mysql主从同步监控脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql主从同步监控脚本相关的知识,希望对你有一定的参考价值。
mysql主从同步监控脚本,利用mysql从库中的IO和SQL进程以及延迟时间来监控主从同步是否正常,详细shell脚本如下:
#!/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/null if [ $? -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.log else echo "ip $ip the master mysql service is normal" >/mail/mysql_master.log && mail -s "wangning tile" [email protected] </mail/mysql_master.log fi } ################### 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.log else echo "the master and slave replication is failed" >/mail/mysql_slave.log && mail -s "wangning tile" [email protected] </mail/mysql_slave.log fi } ################################ judge error code ################################## judge_error_code(){ for ((i=0;i<=${#status[*]};i++)) do if [ ${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" fi done } main(){ while true do define_variable judge_master IO_SQL_delay judge_error_code sleep 180 done } main
本文出自 “飞奔的骆驼” 博客,请务必保留此出处http://wn2100.blog.51cto.com/9915310/1948112
以上是关于mysql主从同步监控脚本的主要内容,如果未能解决你的问题,请参考以下文章