Digital Marketing

How to Set up monit to restart Apache and MySQL automatically in Centos

Install monit from EPEL, first install EPEL:

$ sudo rpm -Uvh  http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

$ sudo yum -y install monit

in /etc/monit.conf

# set daemon mode timeout to 1 minute
set daemon 60
# Include all files from /etc/monit.d/
include /etc/monit.d/*

check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
# monitoring apache

check process apache with pidfile /var/run/httpd/httpd.pid
group www
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"

if failed host www.goyun.info port 80 protocol http
then restart

# the following is to check web site with content.

check host www.goyun.info with address www.goyun.info
if failed url http://www.goyun.info and content == "IT.goyun.info"
timeout 30 seconds for 2 cycles then exec "/usr/bin/python /root/restart-do.py"
Finally:

$ sudo  /etc/init.d/monit start

Comments

Popular posts from this blog

MySQL Sandbox with the Sakila sample database