码迷,mamicode.com
首页 > 数据库 > 详细

shell监控mysql主从同步

时间:2017-09-03 23:47:48      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:mysql主从复制的shell监控监本

#!/bin/sh

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-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}‘`

 

function checkMysqlStatus(){

    if [ "$MYSQLPORT" =="3306" ]

    then

        /usr/local/mysql/bin/mysql  --connect_timeout=5 -e "showdatabases;" &>/dev/null 2>&1

        if [ $? -ne 0 ]

        then

            echo "Server: $MYSQLIP mysqlis down, please try to restart mysql by manual!" > /var/log/mysqlerr

        else

            echo "mysql isrunning..."

        fi

    else

        echo "WARN!Server: $MYSQLIP mysqlis down."

    fi

}

 

checkMysqlStatus

 

if [ "$IO_env" ="Yes" -a "$SQL_env" = "Yes" ]

then

 echo "MySQL Slave is running!"

else

 echo "####### $DATA #########">>/data/mysql_slave_status.log

 echo "MySQL Slave is not running!" >>    /data//mysql_slave_status.log

 echo "MySQL Slave is not running!"

fi

 

本文出自 “11300506” 博客,请务必保留此出处http://11310506.blog.51cto.com/11300506/1962340

shell监控mysql主从同步

标签:mysql主从复制的shell监控监本

原文地址:http://11310506.blog.51cto.com/11300506/1962340

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