MySQL主从复制监控
#!/bin/bash #check MySQL_Slave Status #crontab time 00:10 MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ ‘{print $4}‘` MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ ‘{print $4}‘` STATUS=$(/usr/bin/mysql -S /var/lib/mysql/mysql.sock -e "show slave status\\G" | grep -i "running") STATUS=$(/usr/bin/mysql -uroot -pPASSWD -e "show slave status\\G"|grep "Running" |awk ‘{print $2}‘)) IO_env=`echo $STATUS | grep IO | awk ‘ {print $2}‘` SQL_env=`echo $STATUS | grep SQL | awk ‘{print $2}‘` DATA=`date +"%y-%m-%d %H:%M:%S"` if [ "$MYSQLPORT" == "3306" ] then echo "mysql is running" else mail -s "warn!server: $MYSQLIP mysql is down" [email protected] fi if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ] then echo "Slave is running!" else echo "####### $DATA #########">> /data/data/check_mysql_slave.log echo "Slave is not running!" >> /data/data/check_mysql_slave.log echo "Slave is not running!" | mail -s "warn! $MYSQLIP MySQL Slave is not running" [email protected] fi #设置cron每十分钟运行一次 #*/10 * * * * root /bin/sh /root/mysql_slave.sh
本文出自 “棒棒不是糖” 博客,谢绝转载!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。