Monit is an open-source utility designed to monitor and manage processes, files, directories, devices, and system resources on Unix-like systems (Linux, macOS, etc.). It can automatically restart failed services or processes and send alerts to system administrators when something goes wrong. Monit is lightweight, easy to configure, and particularly useful for ensuring the reliability of critical services.
To install Monit on a Debian-based system, you can use the following commands:
sudo apt-get update
sudo apt-get install monit
For Red Hat-based systems, use:
sudo yum install monit
After installation, you can configure Monit by editing the configuration file located at /etc/monit/monitrc
. Here is an example configuration snippet:
set daemon 60 # check services at 1-minute intervals
set logfile /var/log/monit.log
set mailserver mail.example.com
set alert admin@example.com
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout
To start Monit, use the following command:
sudo service monit start
You can also enable Monit to start on boot:
sudo systemctl enable monit
By default, the Monit web interface is disabled. To enable it, add the following lines to your Monit configuration file:
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'
After updating the configuration, restart Monit:
sudo service monit restart
You can then access the web interface by navigating to http://localhost:2812
in your web browser.
Monit is a powerful and flexible tool for monitoring and managing system resources and services. Its ease of use and robust feature set make it an essential utility for system administrators looking to ensure the reliability and performance of their systems.