MySQL master-Slave synchronization monitoring script, using MySQL from the library IO and SQL process and delay time to monitor the master-slave synchronization is normal, detailed shell script is as follows:
#!/bin/bash#author wangning#date 2017-7-17#qq 1198143315#email [email protected]##### ############################# define variable############################ #define_variable () {ip= ' ifconfig|sed -n ' 2p ' |awk -f "[: ]+" ' {print $4} ' code= (1158 1159 1008 1007 1062) status= (' Mysql -uroot -p123456 -s /data/3309/mysql.sock -e "Show slave status\g" |egrep "running| behind_master| Last_errno "|awk ' {print $2} ')}############################ judge master ############ ########################## #judge_master () {Mysql -uroot -p123456 -s /data/3306/mysql.sock -e "Show databases" &>/dev/nullif [ $? -ne 0 ];then echo "ip $ip the master mysql service is downed" > /mail/mysql_master.log && mail -s "Wangning tile" [email protected] </mail/mysql_master.logelse echo "ip $ip the master mysql service is normal" > /mail/mysql_master.log && mail -s "Wangning tile" [email protected] </mail/mysql_master.logfi}################### judge io sql status and delay time ############################### io_sql_delay () {if [ "${ Status[0]} " == " yes " -a " ${status[1 "}" == "Yes" -a ${status[3]} - le 60 ];then echo "the master and slave replication Is normal " >/mail/mysql_slave.log && mail -s " wangning tile " [email protected] </mail/mysql_slave.logelse echo " the master and&Nbsp;slave replication is failed " >/mail/mysql_slave.log && mail -s "Wangning tile" [email protected] </mail/mysql_slave.logfi}#### ############################ judge error code ################################# #judge_ Error_code () {for ((i=0;i<=${#status [*]};i++)) Doif [ ${status[2]} -eq ${code[i]} ];then mysql -uroot -p123456 -S /data/3309/mysql.sock -e "Stop slave;set global sql_slave_skip_counter=1;start slave" Fidone}main () {while Truedodefine_variablejudge_masterio_sql_delayjudge_error_codesleep 180done}main
This article is from the "Galloping Camel" blog, make sure to keep this source http://wn2100.blog.51cto.com/9915310/1948112
MySQL master-Slave synchronization monitoring script