Zabbix 2.4.7 Mysql 5.7.9
a. 安装时注意删除系统默认mysql和my.cnf
例 2015-12-02T05:21:41.917241Z 1 [Note] A temporary password is generated for root@localhost : r/Cfgl<l+2#r
查找密码 grep "temporary password" mysql-error.log | awk '{print $NF}'
输入密码时要加双引号 mysql -uroot -p"r/Cfgl<l+2#r"
mysql> alter user 'root'@'localhost' identified by 'password';
如果密码简单,会提示 Your password does not satisfy the current policy requirements
Shutting down zabbix_server: [FAILED]
Starting zabbix_server: /opt/zabbix-server/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方法 从其他服务器复制 libmysqlclient.so.18 文件到 /usr/lib64
提示zabbix server is not running the information displayed may not be current 日志提示 connection to database 'zabbix' failed: [2002] Can't connect to local MySQL serve
r through socket '/tmp/mysql.sock'
解决方法 在zabbix_server.conf 和zabbix_proxy.conf中增加一行
DBSocket=/var/lib/mysql/mysql.sock
truncate table history;
truncate table history_uint;
truncate table history_str;
truncate table trends;
导入模板Custom Template NGINX.xml,配置KEY
UserParameter=nginx.status[*],/opt/zabbix-agent/scripts/nginx-status.sh $1
创建脚本nginx_status.sh
#!/bin/bash # DateTime: # Description:zabbix监控nginx性能以及进程状态 HOST="127.0.0.1" PORT="80" # 检测nginx进程是否存在 function ping { /sbin/pidof nginx | wc -l } # 检测nginx性能 function active { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}' } # 执行function $1
在服务端测试
zabbix_get -s 10.1.1.3 -k 'nginx.status[accepts]'
http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.24/bin/extras/catalina-jmx-remote.jar
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="12345" rmiServerPortPlatform="12346"/>
-A INPUT -s 10.1.1.2 -m state --state NEW -m tcp -p tcp --dport 12345:12346 -j ACCEPT
-A INPUT -s 10.1.1.2 -m state --state NEW -m tcp -p tcp --dport 10050:10051 -j ACCEPT
-A INPUT -s 10.1.1.2 -m state --state NEW -m udp -p udp --dport 10050:10051 -j ACCEPT
检测命令
java -jar /root/cmdline-jmxclient-0.10.3.jar - 10.1.1.3:12345 java.lang:type=Memory NonHeapMemoryUsage
删除默认模板Template App MySQL.xml,导入模板,此模板相对默认模板增加了Threads,Active_connection .添加key ,检查mysqladmin命令是否存在
UserParameter=mysql.version,mysql -V
UserParameter=mysql.ping,mysqladmin -uroot -p123456 -P3306 -h'127.0.0.1' ping 2>/dev/null | grep -c alive
创建脚本vim /opt/zabbix-agent/scripts/chk_mysql.sh
#!/bin/bash # ------------------------------------------------------------------------------- # FileName: check_mysql.sh # Revision: 1.0 # Date: 2015/12/11 # Description: # 用户名 MYSQL_USER='root' # 密码 MYSQL_PWD='123456' # 主机地址/IP MYSQL_HOST='127.0.0.1' # 端口 MYSQL_PORT='3306' # 数据连接 MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h"${MYSQL_HOST}" -P${MYSQL_PORT}" # 参数是否正确 if [ $# -ne "1" ];then echo "arg error!" fi # 获取数据 case $1 in Uptime) result=`${MYSQL_CONN} status 2>/dev/null |cut -f2 -d":"|cut -f1 -d"T"` echo $result ;; Com_update) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_update"|cut -d"|" -f3` echo $result ;; Slow_queries) result=`${MYSQL_CONN} status 2>/dev/null |cut -f5 -d":"|cut -f1 -d"O"` echo $result ;; Com_select) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_select"|cut -d"|" -f3` echo $result ;; Com_rollback) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_rollback"|cut -d"|" -f3` echo $result ;; Questions) result=`${MYSQL_CONN} status 2>/dev/null |cut -f4 -d":"|cut -f1 -d"S"` echo $result ;; Com_insert) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_insert"|cut -d"|" -f3` echo $result ;; Com_delete) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_delete"|cut -d"|" -f3` echo $result ;; Com_commit) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_commit"|cut -d"|" -f3` echo $result ;; Bytes_sent) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Bytes_sent" |cut -d"|" -f3` echo $result ;; Bytes_received) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Bytes_received" |cut -d"|" -f3` echo $result ;; Com_begin) result=`${MYSQL_CONN} extended-status 2>/dev/null |grep -w "Com_begin"|cut -d"|" -f3` echo $result ;; Threads) result=`${MYSQL_CONN} status 2>/dev/null | awk '{print $4}'` echo $result ;; Active_connection) result=`${MYSQL_CONN} processlist 2>/dev/null |grep -i Query|wc -l` echo $result ;; *) echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin|Threads|Active_connection)" ;; esac
导入模板 Custom Template Mysql tables.xml , 添加key
UserParameter=mysql.table[*],/opt/zabbix-server/scripts/mysql_tables.sh $1
#!/bin/bash MYSQL_USER='root' MYSQL_PWD='123456' MYSQL_HOST='127.0.0.1' MYSQL_PORT='3306' MYSQL_CONN="/usr/bin/mysql -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}" # MYSQL COMMAND MYSQL_CMD1="use information_schema;" MYSQL_CMD2="select table_schema,table_name,table_rows from tables where table_schema='owl2';" MYSQL_TABLES=`${MYSQL_CONN} -e "use owl2;show tables;" 2>/dev/null |grep t_` # 参数是否正确 if [ $# -ne "1" ];then echo "arg error!" fi # select tables rows if echo $MYSQL_TABLES |grep -q $1 then result=`${MYSQL_CONN} -e "${MYSQL_CMD1}${MYSQL_CMD2}" 2>/dev/null |grep -w $1 |awk '{print $3}'` echo $result fi
UserParameter=redis_stats[*],redis-cli -h 127.0.0.1 -p $1 -a password info|grep $2 | cut -d : -f2
zabbix_get -s 10.1.1.2 -k redis_stats[6379,total_connections_received]
UserParameter=MongoDB.Status[*],/bin/echo "db.serverStatus().$1" | /usr/bin/mongo 127.0.0.1:27017 | grep "$2"|awk -F':' '{print $$2}'|awk -F',' '{print $$1}' UserParameter=MongoDB.networkIn[*],/bin/echo "db.serverStatus().$1" | /usr/bin/mongo | grep "$2"|awk -F'[()"]' '{print $$5}' UserParameter=MongoDB.networkOut[*],/bin/echo "db.serverStatus().$1" | /usr/bin/mongo | grep "$2"|awk -F'"' '{print $$4}'
http://www.ttlsa.com/zabbix/zabbix-lld-monitor-disk-io-stats/
http://blog.chinaunix.net/uid-26446098-id-4964263.html
UserParameter=discovery.disks.iostats,/opt/zabbix-agent/scripts/discover_disk.pl UserParameter=disk.ops.read[*],grep -w "$1" /proc/diskstats| awk '{print $$4}' UserParameter=disk.ops.write[*],grep -w "$1" /proc/diskstats| awk '{print $$8}' UserParameter=disk.rsec[*],grep -w "$1" /proc/diskstats | awk '{print $$6}' UserParameter=disk.wsec[*],grep -w "$1" /proc/diskstats | awk '{print $$10}' UserParameter=disk.io.ms[*],grep -w "$1" /proc/diskstats | awk '{print $$13}'
6.3 添加正则 在管理--一般---最右边下拉 选择正则表达式
名称 Linux disks for autodiscovery
表达式 两种写法
^(xvda|xvdb|xvdc|xvdd|vda|vdb|vdc|vdd|sd[a-z])$
^(hd[a-z]|sd[a-z]|xvd[a-z]|vd[a-z]|dm-[0-9])$
表示式类型 结果为真
区分大小写 不选
测试zabbix_server不能用127.0.0.1
time zabbix_get -s 10.172.194.67 -k 'disk.ops.read[xvdb]'
备注 不同方法获取速度不同, ,在I/O繁忙时,用脚本无法获取到数据