MySQL master configuration see: http://chinawu.blog.51cto.com/10692884/1739327
The master-slave normal state is the state value on the Slave: Slave_io_running:yes and Slave_sql_running:yes, when a no, indicates that MySQL master and slave has been destroyed, but, OPS personnel may not be able to enter the status value on MySQL slave at any time. So it takes a footstep to detect whether the relationship is normal within a specified time.
General content of Footsteps:
#!/bin/bash
#Check Mysql_slave Status
#MySQL version:5.1.73
#2016-01-29
Mysql_port= ' Netstat-an|grep "LISTEN" |grep "3306" |awk-f "' {print $4} ' |awk-f ': ' {print $} ' #注意: After renting a print $, it does not necessarily apply to the Have host, according to the actual situation Pring value
mysql_ip= ' ifconfig eth0 |grep ' inet addr ' |awk-f ': ' {print $} ' |awk-f ' ' {print '} '
mysql_status=$ (/usr/local/mysql/bin/mysql-s/tmp/mysql.socket-uroot-pfgjh123.-E "show slave Status\g" |grep-i "Runni Ng "|head-n2)
Io_env= ' echo $MySQL _status | grep slave_io_running |awk ' {print $} '
Sql_env= ' echo $MySQL _status |grep slave_sql_running |awk ' {print $} '
today= ' date + '%y-%m-%d%h:%m:%s '
If ["$MySQL _port" = = "3306"]
Then
echo "###### $ToDay ######" >>/data/check_mysql_slave_ok.log
echo "MySQL Server is running!" >>/data/check_mysql_slave_ok.log
Else
Mail-s "warn! Server: $MySQL _ip MySQL is down "[email protected]
Fi
If ["$IO _env" = "yes"-a "$SQL _env" = "yes"]
Then
echo "###### $ToDay ######" >>/data/check_mysql_slave_ok.log
echo "Slave MySQL Server Slave_io and Slave_sql is running!" >>/data/check_mysql_slave_ok.log
Else
echo "###### $ToDay ######" >>/data/check_mysql_slave_warn.log
echo "Slave is not running!" >>/data/check_mysql_slave_warn.log
echo "Slave is not running!" | Mail-s "warn! $MySQL _ip MySQL Slave is not running "[email protected]
Fi
Then put it in the auto-execute task list, CRONTAB-E
*/10 * * * * root/bin/sh/root/shell/check_mysql_slave_status.sh
Every 10 minutes to run the detection step (time customization, crontab five parameters please study)
Zabbix add trigger to detect MySQL master-slave, Alarm
[email protected] scripts]# cat mysql-replication.sh
#!/bin/bash
Mysql-uzabbix-e ' show slave status\g ' |grep-e ' slave_io_running| Slave_sql_running "|awk ' {print $} ' |grep-c Yes
[Email protected] scripts]#
[Email protected] etc]# tail-15 zabbix_agentd.conf
Userparameter=mysql.replication,/home/zabbix/scripts/mysql-replication.sh
Userparameter=mysql.status[*],/home/zabbix/scripts/chk_mysql.sh $
Step monitoring MySQL Master and slave is normal