#repdelay. sh#!/bin/sh#[email protected] #查看复制延迟具体多少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 '} ' |awk-f '. " ' {print $} ' b= ' sed-n '/\<master_log_file\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ': ' {print $} ' |awk-f '. " ' {print $} ' bhtime= ' sed-n '/\<seconds_behind_master\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ': ' {print $ {} ' if [' $b ' = ' $a '];thenc= ' tail-1 ${tmpfile_01} | Grep-v "Log_name" |awk ' {print $} ' d= ' sed-n '/\<read_master_log_pos\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ":" ' {print $} ' e= ' expr $c-$d ' If ["${e}"-eq 0-a "${bhtime}"-eq 0]; Thenecho "*****************************************************************************" Echo-e "\e[1;31m & &&&&&&synchronization has been completed!&&&&&&& \e[0m "echo" * * "Elif [" ${e} "-eq 0-o" ${bhtime} "-eq 0]; Thenecho "*****************************************************************************" 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}];thenf= ' Sed-n"/\<read_master_log_pos\>/p "${tmpfile_02} |sed ' s/^[]*//g ' |a Wk-f ":" ' {print $} ' g= ' awk ' >= ' $b ' {print $} ' ${tmpfile_01} |awk ' Begin{total=0}{total+=$1}end{print total} ' r E= ' expr $g-$f ' echo-e ' \e[1;31m there is multiple log files is not synchronized,the events Is:${re} \e[0m "Fir M-RF ${TMPFILE_01}RM-RF ${tmpfile_02}
Actual combat: MySQL 5.6 Replication latency Monitoring