首页 > 代码库 > mysql主从同步监控脚本
mysql主从同步监控脚本
mysql主从同步监控脚本,利用mysql从库中的IO和SQL进程以及延迟时间来监控主从同步是否正常,详细shell脚本如下:
#!/bin/bash #author wangning #date 2017-7-17 #qq 1198143315 #Email 1198143315@qq.com ################################## 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" 1198143315@qq.com </mail/mysql_master.log else echo "ip $ip the master mysql service is normal" >/mail/mysql_master.log && mail -s "wangning tile" 1198143315@qq.com </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" 1198143315@qq.com </mail/mysql_slave.log else echo "the master and slave replication is failed" >/mail/mysql_slave.log && mail -s "wangning tile" 1198143315@qq.com </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主从同步监控脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。