Introduction
Monit is a free open source utility for managing and monitoring, processes, programs, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations, for example, Monit can prevent your services from getting stopped.
It is a small Open Source utility for managing and monitoring Unix systems. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.
![](https://i0.wp.com/hackonology.com/wp-content/uploads/2020/09/Monit.png?resize=1024%2C449&ssl=1)
![](https://i0.wp.com/hackonology.com/wp-content/uploads/2020/09/Monit-1.png?resize=1024%2C420&ssl=1)
Install Monit
For installing Monit you need to add the EPEL repository first:
yum install epel-release
After that you can install Monit easily using:
yum install monit
After the installation process is finished, you can execute the following commands to start Monit service and make it run at startup:
systemctl start monit
systemctl enable monit
You can check your Monit service status with the command below:
systemctl status monit
You can set your preferred Email address to get alerts and reports from Monit with the following command:
set mailserver mail.example.com port 25
set alert youremailaddress@example.com
Initial Configuration
For doing some configuration you need to open your Monit global configuration file with the command below:
nano /etc/monitrc
Enable the web interface
In the Monit global configuration file, scroll down to the following block:
set httpd port 2812 and
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'
By default, Monit only listens on “localhost” and only answers to “localhost” as well, So if you want to be able to connect to your Monit interface from anywhere, you have to comment the following lines:
set httpd port 2812 and
#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'
Make sure to change your username and password to something strong like below:
set httpd port 2812 and
#use address localhost # only accept connection from localhost
#allow localhost # allow localhost to connect to the server and
allow MonitAdmin:5PbTLadz # require user 'MonitAdmin' with password '5PbTLadz'
Now you can visit your Monit web interface at the following address:
http://IP_OR_DOMAIN:2812
You will see a page like below:
![](https://i0.wp.com/hackonology.com/wp-content/uploads/2020/09/monitwebui-1.png?resize=1024%2C513&ssl=1)
Configuring Programs Self-Monitoring
Now it’s time to set some services and processes to be monitored by Monit. You can scroll down the “monitrc” file to see the examples of configurations, but all of them are commented, so leave them be and add your own configurations at the very end of the file. in this section, we are going to configure Monit to prevent your services from being stopped. (Make sure to change the red parts with your own values, the “pid” files locations for each software could be different)
Apache
check process apache with pidfile /run/httpd.pid
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop program = "/etc/init.d/httpd stop"
MySQL
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
Nginx
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
After making changes check the syntax of your configuration file for errors:
monit -t
You should see the following output:
Control file syntax OK
Then restart the Monit service to take effect and start working:
systemctl restart monit
monit start all
You can check out Monit official website for more information and news!
![](https://i0.wp.com/s3.amazonaws.com/docs.paykickstart.com/banner-images/1637981871_FO7130A2D7D85-2-320x100.jpg?resize=320%2C100&ssl=1)
Hope this article helpful for you. Thank You
If You Appreciate What We Do Here On Hackonology, You Should Consider:
Hackonology is the fastest growing and most trusted community site where you can find lots of courses, articles about Technology/Hacking/Cracking. Millions of people visit Hackonology! to search or browse the thousands of published articles available FREELY to all.
Let's be a part of Hacker's Community! Join our Hacking Team
We Are Indian We Are Great