Java321技术网

标题: Centos6定时监测mysql进程终止后自动启动mysql [打印本页]

作者: luozhangyou    时间: 2017-12-24 01:44
标题: Centos6定时监测mysql进程终止后自动启动mysql
运行 yum install crontabs安装

编写脚本 /root/mybatch/listenmysql.sh

  1. pgrep mysqld &> /dev/null
  2. if [ $? -gt 0 ]
  3. then
  4. echo "`date` mysql is stop" >> /var/log/mysql_listen.log
  5. su - root service mysqld start
  6. else
  7. echo "`date` mysql running" >> /var/log/mysql_listen.log
  8. fi
复制代码

chmod 777 /root/mybatch/listenmysql.sh


crontab -e

在下面加入


*/5 * * * * /root/mybatch/listenmysql.sh

不行就用下面的

*/5 * * * * root /root/mybatch/listenmysql.sh




之后执行 service crond restart


这样 会每5分钟检测一次mysql状态,如果停止了 会自动重启。

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


最近再设置一个开机启动


chkconfig --level 2345 crond on




可能会遇到的问题

syntax error near unexpected token `fi'

http://www.java321.com/thread-1582-1-1.html







欢迎光临 Java321技术网 (https://www.java321.com/) Powered by Discuz! X3.3