加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

mysql 主从备份监控slave状态nagios脚本

发布时间:2020-12-15 07:11:33 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/bashcmd='mysql -uslave -ppasswd -P3306 -h 192.168.0.72 -Be'status=`$cmd 'show slave statusG'`Seconds_Behind_Master=`echo "$status"|a

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/bin/bash
cmd='mysql -uslave -ppasswd -P3306 -h 192.168.0.72 -Be'
status=`$cmd 'show slave statusG'`
Seconds_Behind_Master=`echo "$status"|awk '/Seconds_Behind_Master/{FS=":";print $2}'`
Read_Master_Log_Pos=`echo "$status"|awk '/Read_Master_Log_Pos/{FS=":";print $2}'`
Exec_Master_Log_Pos=`echo "$status"|awk '/Exec_Master_Log_Pos/{FS=":";print $2}'`
Last_IO_Errno=`echo "$status"|awk '/Last_IO_Errno/{FS=":";print $2}'`
Last_SQL_Errno=`echo "$status"|awk '/Last_SQL_Errno/{FS=":";print $2}'`
Slave_IO_Running=`echo "$status"|awk '/Slave_IO_Running/{FS=":";print $2}'`
Slave_SQL_Running=`echo "$status"|awk '/Slave_SQL_Running/{FS=":";print $2}'`
 
#nagios status:
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
 
if [ "$Slave_IO_Running" != "Yes" -o "$Slave_SQL_Running" != "Yes" ];then
        echo "Slave_IO or Slave_SQL process exited! Last_IO_Errno:$Last_IO_Errno Last_SQL_Errno:$Last_SQL_Errno"
        exit $STATE_CRITICAL
fi
 
later=$[$Read_Master_Log_Pos - $Exec_Master_Log_Pos]
 
if [ $later -ge 100 ];then
        echo "Read_Master_Log_Pos:$Read_Master_Log_Pos Exec_Master_Log_Pos:$Exec_Master_Log_Pos"
        exit $STATE_WARNING
fi
 
if [ $Seconds_Behind_Master -ge 30 ];then
        echo "Warning: Seconds_Behind_Master:$Seconds_Behind_Master"
        exit $STATE_WARNING
fi
echo "Slave OK-Read_Master_Log_Pos:$Read_Master_Log_Pos Exec_Master_Log_Pos:$Exec_Master_Log_Pos Seconds_Behind_Master:$Seconds_Behind_Master"
exit $STATE_OK

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读