Monit is a utility for managing and monitoring, processes, files, directories and file systems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.
To install Monit on a Red Hat Enterprise server, the easiest is to use a prepared RPM packet. You'll find precompiled packages on the DAG repositories:
Download the RPM packages suitable for your system:
rpm -ivh monit-4.9-2.el5.rf.i386.rpm
Per default the config files is located under /etc/monit.conf on RHEL.
## Start monit in background (run as daemon) and check the services at 2-minute ## intervals. # set daemon 120 ## Set syslog logging with the 'daemon' facility. If the FACILITY option is ## omited, monit will use 'user' facility by default. You can specify the ## path to the file for monit native logging. # set logfile syslog facility log_daemon ## You can set the alert recipients here, which will receive the alert for ## each service. The event alerts may be restricted using the list. # set alert email@example.com ## It is possible to include the configuration or its parts from other files or ## directories. # include /etc/monit.d/*
If you want to log monit to its own log file change the “set logfile” setting as in the example below:
set logfile /var/log/monit.log
Check monit setting:
Start the servive:
service monit start
Stop the service:
service monit stop
Check the service status:
service monit status
Automatecally start Monit at system start:
chkconfig monit on
Check for messages from the Monit deamon:
grep monit /var/log/messages
Putting configurations for service under /etc/monit.d/<service name>.monit keeps things clean. Alternatively you can configure services directly in the main configuration file (/etc/monit.conf).
Example configuration for Apache stored under /etc/monit.d/httpd.monit.
check process apache with pidfile /var/run/httpd.pid group apache start program = "/sbin/service httpd start" stop program = "/sbin/service httpd stop" if children > 700 then restart # restart Apache before reaching the 768 MaxClients limit if 5 restarts within 5 cycles then timeout
Monit 5.0 onwards supports also “with timeout” statements for program start/stop which resolves problems if it takes long (30s default) to restart a service, i.e. when Apache hangs:
start program = "/sbin/service httpd start" with timeout 90 seconds stop program = "/sbin/service httpd stop"
check process urchind with pidfile /usr/local/urchin/var/urchind.pid group urchin start program = "/sbin/service urchin_daemons start" stop program = "/sbin/service urchin_daemons stop" if 5 restarts within 5 cycles then timeout
# syslog-ng check process syslog-ng with pidfile /opt/syslog-ng/var/run/syslog-ng.pid group services start program = "/sbin/service syslog-ng start" stop program = "/sbin/service syslog-ng stop" if 5 restarts within 5 cycles then timeout