首页 > 数据库 > mysql教程 > 实战:mysql5.6复制延迟监控_MySQL

实战:mysql5.6复制延迟监控_MySQL

WBOY
发布: 2016-06-01 13:02:30
原创
742 人浏览过

#repdelay.sh
#!/bin/sh
#ocpyang@126.com
#查看复制延迟具体多少event

#set mysql evn
MYSQL_USER_MASTER=root  
MYSQL_PASS_MASTER='password'  
MYSQL_HOST_MASTER=192.168.2.188

MYSQL_USER_SLAVE=root  
MYSQL_PASS_SLAVE='password'  
MYSQL_HOST_SLAVE=192.168.2.14

tmpfile_01="tmp01.`date +%Y%m%d%H%M%S`.txt"
tmpfile_02="tmp02.`date +%Y%m%d%H%M%S`.txt"
mysql -h${MYSQL_HOST_MASTER} -u${MYSQL_USER_MASTER} -p${MYSQL_PASS_MASTER} -e"SHOW BINARY LOGS;" >${tmpfile_01}
mysql -h${MYSQL_HOST_SLAVE} -u${MYSQL_USER_SLAVE} -p${MYSQL_PASS_SLAVE} -e"SHOW SLAVE STATUS\G;" >${tmpfile_02}

#tail -1 ${tmpfile_01} | grep -v "Log_name"
#cat ${tmpfile_02} | grep -E 'Master_Log_File|Read_Master_Log_Pos|Exec_Master_Log_Pos' | grep -v "Relay_Master_Log_File" |sed 's/^[ ]*//g'
a=`tail -1 ${tmpfile_01} | grep -v "Log_name" |awk '{print $1}'|awk -F "." '{print $2}'`
b=`sed -n "/\<Master_Log_File\>/p" ${tmpfile_02} |sed &#39;s/^[ ]*//g&#39; |awk -F ":" &#39;{print $2}&#39;|awk -F "." &#39;{print $2}&#39;`
bhtime=`sed -n "/\<Seconds_Behind_Master\>/p" ${tmpfile_02} |sed &#39;s/^[ ]*//g&#39; |awk -F ":" &#39;{print $2}&#39;`

if [ "$b" = "$a"  ];then
	c=`tail -1 ${tmpfile_01} | grep -v "Log_name" |awk &#39;{print $2}&#39;`
	d=`sed -n "/\<Read_Master_Log_Pos\>/p" ${tmpfile_02}  |sed &#39;s/^[ ]*//g&#39; |awk -F ":" &#39;{print $2}&#39;`
        e=`expr $c - $d`
	if [ "${e}" -eq 0  -a "${bhtime}" -eq 0  ]; then
		echo "*****************************************************************************"
		echo -e "\e[1;31m  &&&&&&&Synchronization has been completed!&&&&&&& \e[0m"
		echo "*****************************************************************************"
	elif [  "${e}" -eq 0  -o "${bhtime}" -eq 0  ];then
		echo "*****************************************************************************"
		echo -e "\e[1;31m  Has been synchronized to the same log file! Wait a moment \e[0m"
		echo -e "\e[1;31m Not synchronized binlog events is:${e},behind master tims is ${bhtime} \e[0m"
		echo "*****************************************************************************"
	fi

elif  [ ${b} -lt ${a} ];then
	f=`sed -n "/\<Read_Master_Log_Pos\>/p" ${tmpfile_02}  |sed &#39;s/^[ ]*//g&#39; |awk -F ":" &#39;{print $2}&#39;`
	g=`awk &#39;$1 >= "$b"  {print $2}&#39; ${tmpfile_01} |awk &#39;BEGIN{total=0}{total+=$1}END{print total}&#39;`
	re=`expr $g - $f`
        echo -e "\e[1;31m There are multiple log files are not synchronized,the  events is:${re} \e[0m"

fi

rm -rf ${tmpfile_01}

rm -rf ${tmpfile_02}
登录后复制

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板