For those of you who didn’t know, Monit is a opensource process tool for Linux operating system which helps you to monitor system process using web browser and also whenever requires it automatically do the maintenance or repair of particular process in such a way that it can be brought back online. The monitoring can be directly on the command line or on the web. You can assign Monit multiple tasks (not only monitoring), so if a certain service fails the check, Monit can alert or do something about it (try to restart the service for example).
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation Monit on Ubuntu 14.04.
Install Monit on Ubuntu 14.04
Step 1. Installing Monit and Apache server.
sudo apt-get update sudo apt-get install apache2 sudo apt-get install monit
Step 2. Configure Monit.
After the installation is complete, edit the main config file to resemble the example below using your favorite text editor and set your own username and password:
set httpd port 2812 and # # set the listening port to your desire. 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' allow @monit # allow users of group 'monit' to connect (rw) allow @users readonly # allow users of group 'users' to connect readonly
Once you’ve configured it, you need to start the monit service to reload the new configuration settings:
sudo /etc/init.d/monit start
Step 3. Configuring Programs Self-Monitoring.
Once the initial config is completed, we can configure some of the services we want to monitor. To do this, we will create separate files for every service located within the /etc/monit.d/ directory. Following are some useful configuration examples for monit, that can be very helpful to see how a service is running, where it keeps its pidfile and how to start and stop a service etc:
## SSH ## # nano /etc/monit.d/ssh start program “/etc/init.d/sshd start” stop program “/etc/init.d/sshd stop” if failed port 22 protocol ssh then restart
## Webserver ## # nano /etc/monit.d/http check process webserver with pidfile /var/run/httpd/httpd.pid group apache start program = “/etc/init.d/httpd start” stop program = “/etc/init.d/httpd stop” if failed host 0.0.0.0 port 80 then restart
## NTP ## # nano /etc/monit.d/ntp check process ntpd with pidfile /var/run/ntpd.pid start program = “/etc/init.d/ntpd start” stop program = “/etc/init.d/ntpd stop” if failed host 127.0.0.1 port 123 type udp then alert
After adding required services in monit monitoring configuration file, Use the below command to verify syntax of file:
Now restart monit service:
sudo /etc/init.d/monit start
Step 4. Accessing Monit.
Monit will be available on HTTP port 2812 by default. Open your favorite browser and navigate to http://your-domain.com:2812 or http://server-ip:2812 and and then enter the credentials you created in conf above.
Congratulation’s! You have successfully installed Monit. Thanks for using this tutorial for installing Monit on Ubuntu 14.04 system.