博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL主从服务器的守护进程监视
阅读量:4512 次
发布时间:2019-06-08

本文共 1794 字,大约阅读时间需要 5 分钟。

检测myslq从库状态,跳过固定的错误号,每隔30秒检测一次,如果符合条件自动跳过或者是重启从库

1)取出mysql从库的关键字

 

1 [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 05 0

 

 

 

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

3)while ture

根据思路调试出如下脚本

1 [root@localhost scripts]# cat check_mysql_slave.sh  2 #/bin/bash 3 #Date:     4 #Author:    5 #Mail:     917667797@qq.com 6 #Function: This scripts  function is check mysql slave is ok 7 #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 true14 do15 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        else21            for ((n=0;n<${#error_numb[*]};n++))22            do23               if [ "${status[3]}" == "${error_numb[n]}" ];then24               ${skip}25               else26                $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 333 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

 

转载于:https://www.cnblogs.com/it-hack/p/7518539.html

你可能感兴趣的文章
从零开始搭建系统1.5——Redis安装及配置
查看>>
multipart/form-data和application/x-www-form-urlencoded的区别
查看>>
python管理Windows服务
查看>>
python自动化测试报告(excel篇)
查看>>
Dynamic CRM 中修改实体中主字段的长度
查看>>
更新ruby
查看>>
[Angular] Create a custom validator for template driven forms in Angular
查看>>
[React] Make Controlled React Components with Control Props
查看>>
[Python] Indexing An Array With Another Array with numpy
查看>>
css写的手机网站页面如何使网页左右固定不动?
查看>>
解析 Linux 中的 VFS 文件系统机制
查看>>
互联网网海无边,我精力有限
查看>>
P1531 I Hate It
查看>>
ecshop调用指定商品分类下的商品
查看>>
springmvc+json 前后台数据交互
查看>>
NPOI 模板 下载
查看>>
js 常用代码
查看>>
module.js:550 throw err; ^ Error: Cannot find module 'portfinder' at Function
查看>>
tar打包压缩命令
查看>>
objc反汇编分析,block函数块为何物?
查看>>