首页 > 代码库 > 实战:mysql 5.6复制延迟监控
实战:mysql 5.6复制延迟监控
#repdelay.sh#!/bin/sh#ocpyang@126.com#查看复制延迟具体多少event#set mysql evnMYSQL_USER_MASTER=root MYSQL_PASS_MASTER='password' MYSQL_HOST_MASTER=192.168.2.188MYSQL_USER_SLAVE=root MYSQL_PASS_SLAVE='password' MYSQL_HOST_SLAVE=192.168.2.14tmpfile_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 's/^[ ]*//g' |awk -F ":" '{print $2}'|awk -F "." '{print $2}'`bhtime=`sed -n "/\<Seconds_Behind_Master\>/p" ${tmpfile_02} |sed 's/^[ ]*//g' |awk -F ":" '{print $2}'`if [ "$b" = "$a" ];then c=`tail -1 ${tmpfile_01} | grep -v "Log_name" |awk '{print $2}'` d=`sed -n "/\<Read_Master_Log_Pos\>/p" ${tmpfile_02} |sed 's/^[ ]*//g' |awk -F ":" '{print $2}'` 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 "*****************************************************************************" fielif [ ${b} -lt ${a} ];then f=`sed -n "/\<Read_Master_Log_Pos\>/p" ${tmpfile_02} |sed 's/^[ ]*//g' |awk -F ":" '{print $2}'` g=`awk '$1 >= "$b" {print $2}' ${tmpfile_01} |awk 'BEGIN{total=0}{total+=$1}END{print total}'` re=`expr $g - $f` echo -e "\e[1;31m There are multiple log files are not synchronized,the events is:${re} \e[0m"firm -rf ${tmpfile_01}rm -rf ${tmpfile_02}
实战:mysql 5.6复制延迟监控
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。