主机类型 | 服务器地址 |
---|---|
监控主机 | 10.3.97.240 |
被监控1 | 10.3.145.1 |
被监控2 | 10.3.145.2 |
监控机:
安装软件 | 版本 |
---|---|
lepus | 3.7 |
mysql | 5.7.25 |
Apache | 2.2.15 |
安装步骤:
yum install gcc python-devel net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml -y
[root@localhost lepus_v3.7]# cd /var/www/html/
[root@localhost html]# ls
php
修改PHP配置/var/www/html/php/application/config/database.php
$db['default']['hostname'] = '127.0.0.1';
$db['default']['port'] = '3306';
$db['default']['username'] = 'root';
$db['default']['password'] = 'Lepus123';
$db['default']['database'] = 'lepus';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
[root@localhost html]# service httpd status
httpd is stopped
[root@localhost html]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
告警的解决:
编辑 /etc/httpd/conf/httpd.conf
添加 ServerName localhost:8089
/*
如果需要修改监听端口,修改httpd.conf文件中的Listen 配置
Listen 8089
[root@localhost conf]# netstat -lnap |grep httpd
tcp 0 0 :::8089 :::* LISTEN 2708/httpd
*/
1. ]# tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local
2. ]# cd /usr/local
3. ]# ln -s ./mysql-5.7.25-linux-glibc2.12-x86_64/ ./mysql
4. ]# useadd mysql
5. ]# mkdir -p /data/mysql
6. ]# chown mysql:mysql -R /data/mysql
7. ]# chown mysql:mysql -R /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64/ mysql
8. 检查/删除已经安装的MySQL
9. ]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize
10. 修改root 密码:Lepus123
执行/usr/local/lepus_v3.7/sql 中的sql
# mysql -uroot -pLepus123 -Dlepus
# mysql -uroot -pLepus123 -Dlepus
# /usr/local/lepus_v3.7/python 下的sh 和py 文件添加执行权限
1. chmod +x *.py *.sh
# 编辑当前目录下的配置文件,指定资料库的连接信息
2. vim etc/config.ini
[monitor_server]
host="127.0.0.1"
port=3306
user="root"
passwd="Lepus123"
dbname="lepus"
3. 执行install.sh安装
[root@localhost local]# lepus start
nohup: appending output to `nohup.out'
lepus server start fail!
# 检查日志
[root@localhost lepus]# less nohup.out
Traceback (most recent call last):
File "lepus.py", line 8, in <module>
import MySQLdb
ImportError: No module named MySQLdb ## 监控MySQL需要安装mysql的python 支持包
安装MySQLpython包:
yum install MySQL-python.x86_64 -y
再次启动成功
# 安装Oracle监控包cx_oracle的时候报错:
running build
running build_ext
building 'cx_Oracle' extension
creating build
creating build/temp.linux-x86_64-2.6
creating build/temp.linux-x86_64-2.6/src
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Iodpi/include -Iodpi/src -I/usr/include/python2.6 -c src/cx_Oracle.c -o build/temp.linux-x86_64-2.6/src/cx_Oracle.o -DBUILD_VERSION=6.0
src/cx_Oracle.c:17:20: error: Python.h: No such file or directory
……
src/cx_Oracle.c: In function ‘initcx_Oracle’:
src/cx_Oracle.c:725: warning: implicit declaration of function ‘Module_Initialize’
error: command 'gcc' failed with exit status 1
#解决:安装python开发包
yum install -y python-devel
#重新编译安装cx_oracle
python setup.py build
python setup.py install
使用浏览器登陆的时候,apache 日志报错:
[Tue Mar 19 16:45:32 2019] [error] [client *.*.*.*] File does not exist: /var/www/html/favicon.ico
[Tue Mar 19 16:46:24 2019] [error] [client *.*.*.*] Directory index forbidden by Options directive: /var/www/html/
#解决:
安装系统以来的额php 软件包,所有的软件包安装见配置的第一步
# 在被监控的MySQL库创建监控用户
grant select,super,process,reload,show databases,replication client on *.* to 'lepus_monitor'@'10.3.97.240' identified by 'MANAGER';
flush privileges;
yum install -y net-snmp*
vim /etc/snmp/snmpd.conf
# 修改监控主机的IP和用户(用户名是lepus 监控中配置的用户名,此处配置的是root)
# 41 行改成如下
com2sec notConfigUser 10.3.97.240 root
# 62 行 将any 改成all
access notConfigGroup "" any noauth exact all none none
# 85 行去掉注释
]# /etc/init.d/snmpd status
# snmp 默认是使用的是161 端口 监控主机需要访问被监控主机的161端口
[root@localhost snmp]# grep 'Simple Net Mgmt Proto' /etc/services
snmp 161/tcp # Simple Net Mgmt Proto
snmp 161/udp # Simple Net Mgmt Proto
[root@localhost snmp]# lsof -i :161
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
snmpd 94420 root 7u IPv4 800342 0t0 UDP *:snmp
[root@localhost snmp]# ps -ef | grep 'snmpd'
snmpwalk -v 1 -c root 10.3.145.1
snmpwalk -v 2c -c root 10.3.145.1
添加MySQL主机监控之后,在nohup日志中报错
ERROR 1366 (HY000) at line 1: Incorrect integer value: '' for column 'mem_shared' at row 1
# 造成该错误的原因是在Linux内核2.6 以上的时候,MemShared 已经被删除,所以,mem_shared获取错误。
# 解决方案:
修改lepus 监控脚本,在脚本合适的位置,添加mem_shared 变量赋值操作。
[root@localhost lepus]# vim check_os.sh
39 mem_shared=`/usr/bin/snmpwalk -v1 -c ${community} ${ip} UCD-SNMP-MIB::memShared.0 |cut -d= -f2 |awk -F ' ' '{print $2}'`
40 if [ -z $mem_shared ];then
41 mem_shared=0
42 fi
MySQL主从监控
lepus 监控主从是从视图中读取数据,要在主从库开启 show_compatibility_56 参数,否则,MySQL主从复制拓扑无法获取
监控慢查询
scp /usr/local/lepus/client/mysql/lepus_slowquery.sh [email protected]:/usr/bin/
# 145.1:
chmod +x lepus_slowquery.sh
vim lepus_slowquery.sh
#config lepus database server
lepus_db_host="10.3.97.240"
lepus_db_port=3306
lepus_db_user="root"
lepus_db_password="Lepus123"
lepus_db_database="lepus"
#config mysql server
mysql_client="/usr/local/mysql/bin/mysql"
mysql_host="127.0.0.1"
mysql_port=2306
mysql_user="root"
mysql_password="8U^@x7Y3"
#config slowqury
slowquery_dir="/data/mysql/"
……
#config server_id
lepus_server_id=sbtest1 #此处的server_id是lepus “配置中心” 中对应的IP的id字段
#原始脚本存在不可见字符,需要替换一下
sed -i "s/\\r/\\n/g" lepus_slowquery.sh
sed -i /^$/d lepus_slowquery.sh
# 测试监控数据是否可以正常回写
sh lepus_slowquery.sh
*/5 * * * * sh /usr/bin/lepus_slowquery.sh > /dev/null 2>&1