A Monitor For MySQL Replication

该脚本通过监视Slave上的IO_ThreadSQL_Thread的运行情况,来判断Relication运行是否正常;在下面的代码上,填上你的数据库用户名、密码并且在“DO SOMETHING….”加上你自己的报警代码就可以了。该脚本在patchLog上的一个脚本上修改得到。

zzx@oiegg:~$ vi replicationMonitor.sh
#!/bin/sh
# replicationMonitor.sh – a mysql replication monitor
dbuser = “”
dbpwd = “”
rf=$(mktemp)
echo “SHOW SLAVE STATUS\G”|\
mysql -u $dbuser -p$dbpwd > $rf 2>&1

repl_IO=$(cat $rf|grep “Slave_IO_Running”|cut -f2 -d’:’)
repl_SQL=$(cat $rf|grep “Slave_SQL_Running”|cut -f2 -d’:’)
if [ “$repl_IO” != ” Yes” -o “$repl_SQL” != ” Yes” ] ; then
DO SOMETHING….
fi
rm $rf 

–EOF–

In:

Leave a Reply

Your email address will not be published. Required fields are marked *