Install Monit
The first, you need to enable EPEL (Extra Packages for Enterprise Linux) to install monit package. Login as root and type the following command:
[root@lifelinux ~]# vi /etc/yum.repos.d/epel.repo
Add or uncomment the following content at end of the file
[epel]
name=Extra Packages for Enterprise Linux 5 – $basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
Save and close the file. And type the following command
[root@lifelinux ~]# yum clean all
To install monit, type the following command
[root@lifelinux ~]# yum install monit
Turn on monit when system start up
[root@lifelinux ~]# chkconfig –levels 235 monit on
Configure Monit
The configuration file of monit in Centos or RedHat is /etc/monit.conf. Type the following command to edit
[root@lifelinux ~]# vi /etc/monit.conf
Sampe configuration file
set daemon 60
set logfile /var/log/monit.log
set mailserver localhost
set mail-format { from: [email protected]
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
}
set alert [email protected]
include /etc/monit.d/*
Now to monitor Apache, create a file /etc/monit.d/httpd, enter
[root@lifelinux ~]# vi /etc/monit.d/httpd
Add following content
check process httpd with pidfile /var/run/httpd.pid
group apache
start program = «/etc/init.d/httpd start»
stop program = «/etc/init.d/httpd stop»
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout
MySQL server restart configuration directives
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
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
SSH server configuration directives
check process sshd with pidfile /var/run/sshd.pid
start program «/etc/init.d/sshd start»
stop program «/etc/init.d/sshd stop»
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
Type the following command to start monit
[root@lifelinux ~]# /etc/init.d/monit start
You can verify that monit is started from /var/log/monit.log log file:
[root@lifelinux ~]# tail -f /var/log/monit.log
Sample ouputs
[ICT May 12 14:51:18] info : ‘system_server2.domain.com’ Monit started