码迷,mamicode.com
首页 > 其他好文 > 详细

MySQL主从复制从库状态监测

时间:2017-08-31 18:00:15      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:time   null   href   grep   target   tmp   add   article   usr   

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

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

MySQL主从复制从库状态监测

标签:time   null   href   grep   target   tmp   add   article   usr   

原文地址:http://www.cnblogs.com/seasonzone/p/7459388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!