What is Monit?
Monit is one of the autohealing software program which automatically manages and monitors server programs to ensure that all the services are running and also make sure file size, permissions or checksum are always correct. Also, it has its basic web interface. This tutorial covers about how to install and configure monit in the ubuntu system.
Installation of Monit:
Monit is very easy to install through apt-get:
sudo apt-get install monit
Once monit downloads, you can add programs and processes to the below configuration file:
sudo nano /etc/monit/monitrc
Monit can be started up with a command that then keeps it running in the background
The Monit daemon 5.6 uptime: 4h 2m System 'localhost' status Running monitoring status Monitored load average [0.89] [0.95] [1.00] cpu 35.1%us 4.4%sy 0.4%wa memory usage 1292032 kB [63.0%] swap usage 0 kB [0.0%] data collected Sat, 22 Aug 2015 13:12:37
How to Configure Monit?
Monit is very easy to configure. Monit, by default is set up to check that services are running every 2 minutes and it is storing its logs in “/var/log/monit.log”.
The above settings can be modified at the beginning of the configuration file in the
set daemon and
set logfile lines respectively.
set daemon 120
set logfile /var/log/monit.log
How to Configure Monit’s Web Interface?
Monit’s Web interface is running at the port 2812.
Goto to the file /etc/monit/monitrc and uncomment from the line no 118 as belows:
set httpd port 2812 use address localhost # only accept connection from localhost allow localhost # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
Once this is configured, monit should be reloaded and reread the configuration file.
Now, the interface can be reached at server’s IP or domain name as the address in the web browser.
Configuring services in the monit:
We can also configure for the individual server to be healed automatically whenever it is stopped.
check process apache with pidfile /run/apache2.pid start program = "/etc/init.d/apache2 start" with timeout 60 seconds stop program = "/etc/init.d/apache2 stop"
check process mysqld with pidfile /var/run/mysqld/mysqld.pid start program = "/etc/init.d/mysql start" stop program = "/etc/init.d/mysql stop"
Once it is done, validate the syntax using the below command:
If any possible syntax errors, resolve it and then you can start running all of the monitored programs by using the command below.
monit start all