mysql数据库宕机通知
生产环境中,mysql数据库做了高可用配置,两台mysql做了主主复制,mycat做故障转移。正常情况下应用连接mycat,mycat读写mysql1,mysql1崩溃后,读写操作转移到mysql2,该过程对应用是完全透明的,如果想要让管理员知道mysql崩溃了,就需要发送邮件通知了,直接上脚本
1.关闭本机的sendmail服务或者postfix服务
#执行下面的命令,各位大侠都对号入座吧
#sendmial
service sendmail stop
chkconfig sendmail off
#postfix
service postfix stop
chkconfig postfix off
#再狠一点就直接卸载吧…
yum remove sendmail
yum remove postfix
2、然后修改/etc/mail.rc,在文件末尾增加以下内容,指定外部的smtp服务器地址、帐号密码等
$ vi /etc/mail.rc
set from=123456@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=123456
set smtp-auth-password=runoob
set smtp-auth=login
3.linux定时任务执行shell脚本
*/1 * * * * /usr/software/check.sh > /var/log.log
check.sh 脚本内容如下
#!/bin/bash
mysql -uroot -p123456 -e "select version();" &>/dev/null
if [ $? -eq 0 ];then
echo "mysql running!!!"
else
current_time=$(date "+%Y-%m-%d %H:%M:%S")
current_day=$(date "+%Y%m%d")
str="您好,11mysql服务器于"${current_time}"宕机,请您及时查看"
file="/usr/"${current_day}".txt"
if [ ! -f "$file" ]; then
touch ${file}
echo ${str} | mail -s " 11服务器mysql宕机通知" 123456@qq.com
else
echo "邮件已经发送"
fi
fi