1. 程式人生 > >MySQL主從複製從庫狀態監測

MySQL主從複製從庫狀態監測

MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`  
MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`  
STATUS=$(/usr/local/mysql/bin/mysql -uroot -pqkjr_420 -S /tmp/mysql.sock -e "show slave status\G" | grep -i "running")  
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"` function checkMysqlStatus(){ if [ "$MYSQLPORT" == "3306" ] then /usr/local/mysql/bin -uroot -pqkjr_420 --connect_timeout=5 -e "show databases;" &>/dev/null 2>&1 if [ $? -ne
0 ] then echo "Server: $MYSQLIP mysql is down, please try to restart mysql by manual!" > /var/log/mysqld.log mail -s "WARN! server: $MYSQLIP mysql is down." 843706840@qq.com < /var/log/mysqld.log else echo "mysql is running..." fi else
mail -s "WARN!Server: $MYSQLIP mysql is down." 843706840@qq.com fi } checkMysqlStatus if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ] then echo "MySQL Slave is running!" else echo "####### $DATA #########">> /usr/local/mysql/mysql_slave_status.log echo "MySQL Slave is not running!" >> /usr/local/mysql/mysql_slave_status.log echo "MySQL Slave is not running!" | mail -s "WARN! $MYSQLIP MySQL Slave is not running." 843706840@qq.com fi