#此脚本为监控MySQL主从IO和SQL的两个YES,NO代表为不同步
#Zabbix一分钟采集一次数据
#触为器为大于1则报警
#!/bin/bash
mysql="/usr/bin/mysql"
user="root"
password="123456"
IO=`$mysql -u$user -p$password -e "show slave status\G" | grep 'Slave_IO_Running:' | awk '{print $2}'`
SQL=`$mysql -u$user -p$password -e "show slave status\G" | grep 'Slave_SQL_Running:' | awk '{print $2}'`
#[ "$IO" == "Yes" -a "$SQL" == "Yes" ] && echo "1" || echo "2"
[ "$IO" == "Yes" -o "$IO" == "Connecting" ] && [ "$SQL" == "Yes" -o "$SQL" == "Connecting" ] && echo "1" || echo "2"
#此脚本为监控MySQL主从同步的中继日志点,不变化代表不同步,
#Zabbix三分钟采集一次数据
#触为器为日志点数字不变化则报警
#!/bin/bash
mysql="/usr/bin/mysql"
user="root"
password="123456"
Relay=`$mysql -u$user -p$password -e "show slave status\G" | grep 'Relay_Log_Pos:' | awk '{print $2}'`
echo $Relay
#此脚本为监控MySQL主从同步延迟时间
#Zabbix一分钟采集一次数据
#触为器为超过3600秒延迟时间则报警
#!/bin/bash
mysql="/usr/bin/mysql"
user="root"
password="123456"
Seconds=`$mysql -u$user -p$password -e "show slave status\G" | grep 'Seconds_Behind_Master:' | awk '{print $2}'`
echo $Seconds
上述三个监控脚本写后,在Slave的机器上相应位置放置三个脚本,
再去Zabbix Web界面添加监控,设置好Item和Key即可