Maison  >  Article  >  base de données  >  利用shell+短信实现简单MySQL双向同步监控

利用shell+短信实现简单MySQL双向同步监控

WBOY
WBOYoriginal
2016-06-07 17:26:33920parcourir

原理、脚本都很简单,就是截取同步状态的Slave_IO_Running和Slave_SQL_Running两个值是否都为Yes。如果其中不是,就发短信报警。

原理、脚本都很简单,就是截取同步状态的Slave_IO_Running和Slave_SQL_Running两个值是否都为Yes。如果其中不是,,就发短信报警。

[root@mysqlb script]# cat Check_Mysql_Slave_Replication.sh
#!/bin/sh

. /etc/profile

db_user=reed
db_paasswd=reed
LogPath=/root/script/Check_Mysql_Slave_Replication_Log
[ ! -d $LogPath ] && mkdir -p $LogPath

cd $LogPath

Slave_IO_Running=$(/usr/local/mysql/bin/mysql -u$db_user -p$db_paasswd -e"show slave status \G"|grep 'Slave_IO_Running'|cut -d':' -f 2|cut -d' ' -f 2)
Slave_SQL_Running=$(//usr/local/mysql/bin/mysql -u$db_user -p$db_paasswd -e"show slave status \G"|grep 'Slave_SQL_Running'|cut -d':' -f 2|cut -d' ' -f 2)

FUNC()
{
echo "[INFO]$(date +'%F %T') begin to monitor mysql replication..."
if [ "$Slave_IO_Running" == "Yes" ] && [ "$Slave_SQL_Running" == "Yes" ];then
echo "[INFO]$(date +'%F %T') mysql replication is ok!"
else
echo "[ERROR]$(date +'%F %T') fuck!mysql24 replication is failed..."
#调用自己写的发短信脚本
/root/script/info_takeok.sh "fuck!mysql24 replication is failed"
fi
}
FUNC >>Check_Mysql_Slave_Replication$(date +'%F').log

最后写到crontab里面,一分钟检测一次。

linux

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:MySQL查询不使用索引汇总Article suivant: MySQL管理之用户权限