mysql服务器守护程序_MySQL主从服务器的守护进程监视

[root@localhost scripts]# mysql -u root -p123qq.com3307 -S /data/3307/mysql.sock -e "show slave status\G"|grep -E "Running|Seconds_Behind_Master|Last_SQL_Errno"|awk ‘{print $NF}‘

2 Yes3 Yes4 0

5 0

2)把错误号定义在数组里面

3)while ture

根据思路调试出如下脚本

1 [root@localhost scripts]# cat check_mysql_slave.sh2 #/bin/bash3 #Date:4 #Author:5 #Mail: 917667797@qq.com6 #Function: This scripts function is check mysql slave isok7 #Version: 1.1

8 qq="917667796@qq.com"

9 cmd="mysql -u root -p123qq.com3307 -S /data/3307/mysql.sock -e"

10 ip=`ifconfig eth2|sed -n ‘s#^.*ddr:\(.*\) Bc.*$#\1#gp‘`11 skip=`$cmd "stop slave;set global sql_slave_skip_counter=1;start slave;"`12 error_numb=(1158 1159 1008 1007 1062)13 while true

14 do

15 status=(`$cmd "show slave status\G"|grep -E "Running|Seconds_Behind_Master|Last_SQL_Errno"|awk ‘{print $NF}‘`)16

17 if [ "${status[0]}" == "Yes" -a "${status[1]}" == "Yes" -a "${status[2]}" == "0"]18 then19 echo "mysql slave is ok"

20 else

21 for ((n=0;n

23 if [ "${status[3]}" == "${error_numb[n]}"];then24 ${skip}25 else

26 $cmd "stop slave;start slave;"

27 fi28 done29 echo "mysql salve is not ok"

30 echo "${ip} mysql is not ok"|mail -s "mysql slave error at `date +%F%T`"$qq31 fi32 sleep 3

33 done

测试结果如下

[root@localhost scripts]# sh check_mysql_slave.sh

mysql salve is not ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

mysql slave is ok

MySQL主从服务器的守护进程监视

标签:counter   echo   error   set   [1]   gre   blog   根据   data

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:http://www.cnblogs.com/it-hack/p/7518539.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值