Monit is an open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. However, you are the master and monit would only do what you define in the config file for it to do. We will discuss here how to install and configure a basic monit installation in Centos or Redhat Linux.
Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamp changes, checksum changes or size changes. You can also monitor remote hosts; Monit can ping a remote host and can check TCP/IP port connections and server protocols. Monit is controlled via an easy to use control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions and recovery status via customizable alert. For more infop on monit you can visit their official site http://mmonit.com/monit/
Save and close the file. And type the following command
Type the following command to start monit
Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamp changes, checksum changes or size changes. You can also monitor remote hosts; Monit can ping a remote host and can check TCP/IP port connections and server protocols. Monit is controlled via an easy to use control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions and recovery status via customizable alert. For more infop on monit you can visit their official site http://mmonit.com/monit/
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@superman ~]# vi /etc/yum.repos.d/epel.repoAdd 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@superman ~]# yum clean allTo install monit, type the following command
[root@superman ~]# yum install monitTurn on monit when system start up
[root@superman ~]# 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@superman ~]# vi /etc/monit.confSampe configuration file
set daemon 60
set logfile /var/log/monit.log
set mailserver localhost
set mail-format { from: alert@domain.com
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION. }
set alert admin@domain.com include /etc/monit.d/*
Now to monitor Apache, create a file /etc/monit.d/httpd, enter
[root@superman ~]# vi /etc/monit.d/httpdAdd 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 Setup Monit Mail Alerts via SMTP: set mailserver mail.yoursmtp.com, mail.foo.bar port 25
username "superman" password "binpip" using tlsv1, localhost
with timeout 15 seconds
Type the following command to start monit
[root@superman ~]# /etc/init.d/monit startYou can verify that monit is started from /var/log/monit.log log file:
[root@superman ~]# tail -f /var/log/monit.logSample ouputs:
[IST June 17 14:51:18] info : 'system_server2.domain.com' Monit started To understand Monit config file better follow this link : http://mmonit.com/monit/documentation/monit.html Do share your comments below.
I'd like to thank you for the efforts you have put in penning this site. I really hope to view the same high-grade blog posts from you later on as well. In truth, your creative writing abilities has encouraged me to get my own, personal website now ;)
ReplyDeleteMy web page - track website changes