监控mysql_slave脚本
[root@linux-250 shell]# cat check_mysql_slave.sh #!/bin/sh #检测mysql的从机同步情况,若有异常则发出邮件告警 mysql_binfile=/usr/local/mysql/bin/mysql mysql_user=root mysql_pass=123456 datetime=`date +"%Y-%m-%d %H:%M:%S"` mysql_slave_logfile=/data/script/shell/check_mysql_slave.log status=$($mysql_binfile -u$mysql_user -p$mysql_pass -e "show slave status\G"|grep -i "running") Slave_IO_Running=`echo $status | grep Slave_IO_Running | awk ‘ {print $2}‘` Slave_SQL_Running=`echo $status | grep Slave_SQL_Running | awk ‘{print $2}‘` if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ] then echo "Slave is Running!" else echo " $datetime $slave_ip Slave is not running!" >> $mysql_slave_logfile $mysql_binfile -u$mysql_user -p$mysql_pass -e "SLAVE STOP;" $mysql_binfile -u$mysql_user -p$mysql_pass -e "SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;" $mysql_binfile -u$mysql_user -p$mysql_pass -e "SLAVE START;" $mysql_binfile -u$mysql_user -p$mysql_pass -e "EXIT" echo "mysql_slave同步出现错误,请及时登入192.168.1.250数据库从机服务器进行检查" | mutt -s "mysql_slave检测" [email protected] fi
其中发邮件功能需要另行配置
配置方法:MUTI+MSMTP实现
参考资料
http://storysky.blog.51cto.com/628458/293005
http://item.taobao.com/item.htm?spm=a1z10.5.w4002-1279326270.13.lH89fS&id=37122830025
本文出自 “always_yunwei” 博客,请务必保留此出处http://alwaysyunwei.blog.51cto.com/3224143/1357232
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。