实时检测mysql主从状态,并做邮件告警 需求分析: 当我们做完主从后,主从成功的话,Slave_IO_Running和Slave_SQL_Running两个进程的状态就为yes,但是在做主从同步时也不排除,会发生一些意外的情况,所以我们需要写个脚本来实时检测Slave_IO_Running和Slave_SQL_Running的状态,一旦mysql主从状态出现了状况,就通过邮件发送告警,然后再做维护。 脚本思路: 定时检测mysql主从状态,说白的了就是通过脚本让系统去自我检测主...
网络版本#!/bin/bashmysql_cmd="mysql -u root -pxxxxxxxxx"errorno=(1158 1159 1008 1007 1062)while truedoarray=($($mysql_cmd -e "show slave status\G"|egrep ‘_Running|Behind_Master|Last_SQL_Errno‘|awk ‘{ print $NF }‘))if [ "${array[0]}"=="Yes" -a "${array[1]}"=="Yes" -a "${array[2]}"=="0" ]thenecho "MySQL is slave is ok"elsefor ((i=0;i<${#errorno[*]};i++))doif [ "${array[3]}"="${errorno[$i]}" ];th...
常用脚本备份自动配置msmtp,使用mail发邮件#!/bin/bashSRC=/usr/local/srccd$SRC#installmsmtpclient#ifyourwantsupportTLS/SS..常用脚本备份 最近因实际需求,香港服务器租用,对脚本做了以下更改,添加了DNS的监控。与上一个有些区别的就是,香港服务器租用,经一发邮件出来。而不是有一个错就发会邮件出来。线上机器运行 本文出自 “潜入技术的海洋” 博客,请务必保留此出处,免备案空间
要求:每30秒实现检测一次。如果同步出现如下错误号(1158,1159,1008,1007,1062),则跳过错误。
#!/bin/sh#monitor mysql master to salve connection#by zkg 2019-08-22
. /etc/init.d/functions
#Define variablesMYSQLUSER=rootMYSQLPASSWD=DbAppSOCKET=/data/mysql/tmp/mysql.sockMYSQLCMD="mysql -u$MYSQLUSER -p$MYSQLPASSWD -S $SOCKET"
#Define arrayarray_status=($($MYSQLCMD -e "show slave status;"|grep -E "_Runnin...
网络版本#!/bin/bashmysql_cmd="mysql -u root -pxxxxxxxxx"errorno=(1158 1159 1008 1007 1062)while truedoarray=($($mysql_cmd -e "show slave status\G"|egrep _Running|Behind_Master|Last_SQL_Errno|awk { print $NF }))if [ "${array[0]}"=="Yes" -a "${array[1]}"=="Yes" -a "${array[2]}"=="0" ]thenecho "MySQL is slave is ok"elsefor ((i=0;i<${#errorno[*]};i++))doif [ "${array[3]}"="${errorno[$i]}" ];then$mysql...