Installing and Configuring Monit
Monit is a useful program which automatically monitors and manages server programs to make sure that they do not just stay online consistently; it also checks that the file size, checksum, or even permissions are always correct. Additionally monit comes with a basic web interface from where you can set up all of the processes.
In this tutorial we will teach you how to setup and configuration Monit.
The easiest way to install monit is through apt-get.
sudo apt-get install monit
After monit is done downloading, you may add programs and processes to the configuration file.
sudo nano /etc/monit/monitrc
You can start up Monit using a command that keeps it running in the background.
Entering monit status will present monit’s details.
The Monit daemon 5.3.2 uptime: 1h 15m System 'myhost.mydomain.tld' status Running monitoring status Monitored load average [0.03] [0.14] [0.20] cpu 2.5%us 4.9%sy 0.0%wa memory usage 26500 kB [10.4%] swap usage 0 kB [0.0%] data collected Thu, 30 Aug 2012 18:35:00
Monit is simple to use out of the box. By default, it is set up to check that services are running every 2 minutes before storing its log file in ‘/var/log/monit.log’.
The settings could be changed at the beginning of the configuration file in the set daemon and set logfile lines respectively.
Monit usually comes with its own web server running on port 2812.
To configure the web interface, search and uncomment the section which begins with ‘set httpd port 2812’. After the section is uncommented, type in your server’s ip or domain name as the address; permit anybody to connect and then create a Monit user and password.
set httpd port 2812 use address 126.96.36.1999 # only accept connection from localhost allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
After that is configured, monit will reload and reread the configuration file. The web interface is going to be available to you: monit reload. Now you should be able to access the monit web interface by entering ‘example.com:2812’.
Login using your chosen username and password.
Configuring Programs Self-Monitoring
After the web services are set up, you may start putting the programs that you would like monitored and protected into the ‘/etc/monit/monitrc’ configuration file.
In order to make sure that programs stay online, you may use the ‘/etc/init.d’ commands to stop or start a program.
Here you can see some example configurations:
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”
check process nginx with pidfile /var/run/nginx.pid start program = “/etc/init.d/nginx start” stop program = “/etc/init.d/nginx stop”
After you have configured every program that you wish to run, they will be automatically tracked and restarted whenever they turn off.
You can control the programs using both the web interface or the command line.
When you have set up the configuration, check the syntax.
Once resolving every possible syntax error, you can start running all of the monitored program.
monit start all
You should now have everything set up and have Monit ready to go.