溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

shell腳本:nagios監(jiān)控mysql同步

發(fā)布時(shí)間:2020-07-14 03:54:02 來源:網(wǎng)絡(luò) 閱讀:886 作者:sndapk 欄目:移動開發(fā)
#!/bin/bash
#For nagios.
#sndapk(20140106)
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
IFS=' 
'
export PATH IFS
MYSQLPORT="3306"
MYSQLIP="127.0.0.1"
MYSQLUSER="slavemonitor"
MYSQLPW="123456"
MYSQL="/usr/local/mysql-5.0.92/bin/mysql"
netstat -ntl | grep -q "$MYSQLPORT"
if [ $? -ne 0 ];then
    echo "NO MYSQLD PROCESS!"
    exit 2
fi
STATUS=$($MYSQL -h$MYSQLIP -u$MYSQLUSER -p$MYSQLPW -e "show slave status\G" | egrep -i 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master')
IO_status=`echo $STATUS | awk '/IO/{print $2}'`
SQL_status=`echo $STATUS | awk '/SQL/{print $4}'`
SEC_status=`echo $STATUS | awk '/Seconds/{print $6}'`
if [ "$IO_status" == "Yes" ];then
    if [ "$SQL_status" == "Yes" ];then
        if [ "$SEC_status" -eq 0 ];then
            echo "Mysql copy OK!"
            exit 0
        else
            echo "Seconds_behind_master:$SEC_status"
            exit 1
        fi
    else
        echo "Slave_SQL thread is not running!"
        exit 2
    fi
else
    echo "Slave_IO thread is not running!"
    exit 2
fi

注:

1、腳本中監(jiān)控用的mysql用戶(slavemonitor)僅需賦予SUPER權(quán)限。




向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI