当前位置: 主机百科 » VPS优惠 » 正文

Centos7定时监测mysql进程终止后自动启动mysql

最近在一台低配小鸡上跑的一个垃圾站遇到mysql频繁宕掉的情况,根据想法,定时检测mysql进程,一旦进程终止又可以自动重启。

最后在夫妻双双DEBUG博客找到了简单的解决方案。转载记录,以备不时之需及其他需要的网友。

Centos7定时监测mysql进程终止后自动启动mysql

1、编写脚本 /root/listen/listen_mysql.sh

1
pgrep mysqld &> /dev/null if [ $? gt 0 ] then echo “`date` mysql is stop” >> /var/log/mysql_listen.log service mysql start else echo “`date` mysql running” >> /var/log/mysql_listen.log fi

给权限:

1
chmod 777 /root/listen/listen_mysql.sh

2、添加定时任务

1
crontab e

每隔一小时自动执行脚本检测mysql进程:

1
* */1 * * * root /root/listen/listen_mysql.sh

间隔时间可以根据需要自行修改,保存退出重启crond进程:

1
systemctl restart crond.service

这样系统会每个小时自动检测一次mysql状态,如果停止了会自动重启。

监控日志输出在了 /var/log/mysql_listen.log

 

未经允许不得转载:主机百科 » Centos7定时监测mysql进程终止后自动启动mysql

相关文章