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

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

WBOY
WBOYOriginal
2016-06-07 17:26:33920Durchsuche

原理、脚本都很简单,就是截取同步状态的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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:MySQL查询不使用索引汇总Nächster Artikel: MySQL管理之用户权限