1.修改zabbix_agent.conf
[root@mysql-master-b etc]# cat zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
#被动模式填服务器的IP
Server=192.168.1.111
#主动模式,填服务器的IP
ServerActive=192.168.1.111
#这里设置的name必须和web界面的一样
Hostname=192.168.1.24
#打开以下两项
Include=/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1
2.在/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d目录创建监控文件mysql_status.conf
[root@mysql-master-b zabbix_agentd.conf.d]# cat mysql_status.conf
#UserParameter=mysql.version,mysql -V
#UserParameter=mysql.ping,mysql -urepl -phipiao ping | grep -c alive
UserParameter=mysql.status[*],/usr/local/zabbix-agent/scripts/checkmysqlperformance.sh $1 $2
3.写一个脚本,取监控项的值
cat /usr/local/zabbix-agent/scripts/checkmysqlperformance.sh
#!/bin/sh
MYSQL_SOCK="/var/lib/mysql/mysql.sock"
MYSQL_PWD=`cat /usr/local/zabbix-agent/scripts/mysqlpass.txt`
ARGS=1
HOST="192.168.1.24"
if [ $# -ne "$ARGS" ];then
echo "Please input onearguement:"
fi
case $1 in
mysql_replication)
result=`mysql -urepl -h${HOST} -p${MYSQL_PWD} -e ‘show slave status\G‘ | grep -E "Slave_IO_Running|Slave_SQL_Running"|awk ‘{print $2}‘ | grep -c Yes`
echo $result
;;
mysql_delay)
result=`mysql -urepl -h${HOST} -p${MYSQL_PWD} -e ‘show slave status\G‘ | grep -E "Seconds_Behind_Master" |awk ‘{print $2}‘`
echo $result
esac
4.重启服务
/usr/local/zabbix-agent/sbin/zabbix_agentd /usr/local/zabbix-agent/etc/zabbix_agentd.conf
5.在Web界面设置监控项mysql_replication
本文出自 “jiazheming” 博客,请务必保留此出处http://8888866666.blog.51cto.com/6988153/1765452
原文地址:http://8888866666.blog.51cto.com/6988153/1765452