mysql主从监控

Posted 李兴利

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql主从监控相关的知识,希望对你有一定的参考价值。

	要求:检测myslq从库状态,跳过固定的错误号,每隔30秒检测一次,如果符合条件自动跳过或者是重启从库
	1)取出mysql从库的关键字
	[[email protected] 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}‘
	Yes
	Yes
	0
	0
	2)把错误号定义在数组里面
	3)while ture
	根据思路调试出如下脚本。。。。。
	[[email protected] scripts]# cat check_mysql_slave.sh 
	#/bin/bash
	#Date:     2015-12-14 22:37
	#Author:   create by  李兴利
	#Mail:     [email protected]
	#Function: This scripts  function is check mysql slave is ok
	#Version:  1.1
	qq="[email protected]"
	cmd="mysql -u root -p123qq.com3307 -S /data/3307/mysql.sock -e"
	ip=`ifconfig eth2|sed -n ‘s#^.*ddr:\(.*\) Bc.*$#\1#gp‘`
	skip=`$cmd "stop slave;set global sql_slave_skip_counter=1;start slave;"`
	error_numb=(1158 1159 1008 1007 1062)
	while true
	do
	status=(`$cmd "show slave status\G"|grep -E "Running|Seconds_Behind_Master|Last_SQL_Errno"|awk ‘{print $NF}‘`)
	
	   if [ "${status[0]}"  == "Yes" -a "${status[1]}" == "Yes" -a "${status[2]}" == "0" ]
	       then
	           echo  "mysql slave is ok"
	       else
	           for ((n=0;n<${#error_numb[*]};n++))
	           do
	              if [ "${status[3]}" == "${error_numb[n]}" ];then
	              ${skip}
	              else
	               $cmd "stop slave;start slave;"
	              fi
	           done
	           echo  "mysql salve is not ok"
	           echo "${ip} mysql is not ok"|mail -s "mysql slave error at `date +%F%T`" $qq
	   fi
	sleep 3
	done
	[[email protected] scripts]# 
	测试结果如下
	[[email protected] 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主从监控的主要内容,如果未能解决你的问题,请参考以下文章

zabbix监控Mysql主从状态

zabbix4.4监控mysql主从复制

Zabbix监控mysql主从

zabbix监控mysql主从状态

十七Mysql的主从--主从故障监控分析

脚步监控mysql主从是否正常