#!/bin/bash
slave='slave1'
#formatDate1=`date "+%Y-%m-%d %H:%M:%S"`
user='root'
password='password'
host='127.0.0.1'
port='9310'
doCount=10
catalog='/home/script/leadLog.txt'
while [ $doCount -ge 1 ]
do
sleep 0.5s
let doCount--
formatDate=`date "+%Y-%m-%d %H:%M:%S"`
#SLAVE_IO_S&SLAVE_SQL_S is YES
thread_status=`mysql -P"$port" -h"$host" -u"$user" -p"$password" -e 'show slave status\G'|grep -i yes|wc -l`
status=(`mysql -P"$port" -h"$host" -u"$user" -p"$password" -e 'show slave status\G'| egrep -i "Master_Log_File|Relay_Master_Log_File|Read_master_log_Pos|Exec_Master_log_pos|Seconds_Behind_Master" |awk -F':' '{print $2}'`)
echo "${formatDate}-${slave}-INFO : SLAVE_IO_S&SLAVE_SQL_S:${thread_status},status:Master_Log_File:${status[0]},Relay_Master_Log_File:${status[1]},Read_master_log_Pos:${status[2]},Exec_Master_log_pos:${status[3]},Seconds_Behind_Master:${status[4]}" >> $catalog
if [[ "$thread_status" != 2 ]]; then
echo "${formatDate}-${slave}-ERROR : SLAVE_IO_S & SLAVE_SQL_S 参数异常请检查!" >> $catalog
fi
if [[ "${status[4]}" -gt "1" ]];then
echo "${formatDate}-${slave}-ERROR :Seconds_Behind_Master=${status[4]},延迟过高,请注意!" >> $catalog
fi
if [[ ${status[0]} == ${status[2]} ]] && [[ ${status[1]} == ${status[3]} ]]; then
echo "${formatDate}-${slave}-INFO : 监听主从参数正常!"
else
echo "${formatDate}-${slave}-ERROR : 从库同步主控LOG日志点位落后,请注意!" >> $catalog
fi
done
MySql 从库根据show slave status返回参数判断延时shell脚本
最新推荐文章于 2024-09-14 19:55:29 发布
该bash脚本用于监控MySQL主从复制的状态,包括SLAVE_IO及SLAVE_SQL线程、主从延迟和日志位置。如果发现SLAVE_IO_S&SLAVE_SQL_S参数异常或Seconds_Behind_Master超过1秒,会将错误信息记录到日志文件中。同时,它还会检查从库是否与主库的日志位置同步。
摘要由CSDN通过智能技术生成