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." [email protected] < /var/log/mysqld.log else echo "mysql is running..." fi else mail -s "WARN!Server: $MYSQLIP mysql is down." [email protected] 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." [email protected] fi

http://blog.csdn.net/qq_25067905/article/details/70207740

转载于:https://www.cnblogs.com/seasonzone/p/7459388.html

你可能感兴趣的:(MySQL主从复制从库状态监测)