Share your love
Install and Configure Monit Manager on Ubuntu 20.04
This guide intends to teach you to Install and Configure Monit Manager on Ubuntu 20.04.
Monit is an open-source utility for managing and monitoring Unix systems. You can use Monit to monitor daemon processes or other programs running on localhost, such as those started at system boot time from /etc/init/ like sendmail, sshd, apache, and mysql.
Steps To Install and Configure Monit Manager on Ubuntu 20.04
To set up Monit manager, log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Ubuntu 20.04.
Install Monit o Ubuntu 20.04
The Monit packages are available in the default Ubuntu 20.04 repository. First, update your local package index with the command below:
# sudo apt update
# sudo apt upgrade -y
Then, use the following command to install the Monit:
sudo apt install monit -y
Check Monit Status
At this point, your Monit service should be activated on your server. To check the status of Monit, run the command below:
sudo systemctl status monit --no-pager -l
Output
● monit.service - LSB: service and resource monitoring daemon
Loaded: loaded (/etc/init.d/monit; generated)
Active: active (running) since Tue 2023-03-28 19:03:28 CEST; 42s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 1 (limit: 4620)
Memory: 1.5M
CGroup: /system.slice/monit.service
└─1763 /usr/bin/monit -c /etc/monit/monitrc
...
If your service wasn’t started, use the following command:
sudo systemctl start monit
Also, you can check your Monit version:
sudo monit --version
Output
This is Monit version 5.26.0
Built with ssl, with ipv6, with compression, with pam and with large files
Copyright (C) 2001-2019 Tildeslash Ltd. All Rights Reserved.
Configure Monit Service Manager on Ubuntu 20.04
The Monit program can be configured using the /etc/monit/monitrc
file. It is recommended that you do not make your own settings directly in this file. It is better to create a new one for the desired settings.
Enable Monit httpd port
By default, port 2812 is disabled which is used for communicating with Monit. So you need to enable it. To do this, open the Monit config file by using your favorite text editor, here we use the vi editor:
sudo vi /etc/monit/monitrc
Find the line: set httpd port 2812
Then remove the # tag for the following lines. Also, replace the allow and use address value from localhost to 0.0.0.0 if you want to access the Monit web interface remotely as shown below.
You can also change the default password for the admin that is monit.
set httpd port 2812 and
use address 0.0.0.0 # only accept connection from localhost (drop if you use M/M>
allow 0.0.0.0/0 # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
When you are done, save and close the file.
To check the Monit configuration, use the command below:
sudo monit -t
Output
Control file syntax OK
Enable Monit Service Manager
By default, the Monit service is not enabled on Ubuntu 20.04. To enable the Monit service to get started automatically with the system boot, run the command below:
sudo /lib/systemd/systemd-sysv-install enable monit
To apply the changes, restart the service:
sudo systemctl restart monit
Also, you can check that everything is working correctly by using the command below:
sudo monit status
Output
Monit 5.26.0 uptime: 0m
System 'orca.ubuntu'
status OK
monitoring status Monitored
monitoring mode active
on reboot start
load average [0.00] [0.03] [0.01]
cpu 0.0%us 0.0%sy 0.0%wa
memory usage 106.4 MB [2.7%]
swap usage 0 B [0.0%]
uptime 9m
boot time Tue, 28 Mar 2023 18:58:26
data collected Tue, 28 Mar 2023 19:08:14
Configure Firewall for Monit
At this point, you need to allow port 2812 through the UFW firewall. To do this, run the command below:
sudo ufw allow 2812
Reload the firewall to apply the new rules:
sudo ufw reload
Access Monit Service Manager Web Interface
At this point, you can access your Monit web interface by typing your server’s IP address in your web browser followed by 2812:
http://your-server-ip-address:2812
You will see the sign-in screen. Enter the admin user and password you have defined in the Monit config file and click Sign in.
You will see the following screen:
Add Services In Monit on Ubuntu 20.04
At this point, you can create a service file for an application to get monitored or can use the pre-configured ones available in the M/Monit folder.
In the /etc/monit/conf-available/
there are several ready-made files for various common server services such as:
acpid, at, mdadm, mysql, openntpd, pdns-recursor, rsyslog, snmpd,
apache2, cron, memcached, nginx, openssh-server, postfix and smartmontools.
In order for Monit to take over the settings for the desired service, a soft link to the service file must be created and activated in the /etc/monit/conf-enabled/
.
For example, you want to monitor Nginx using its pre-configured file. To do this, you can use the command below:
sudo ln -s /etc/monit/conf-available/nginx /etc/monit/conf-enabled/
Then, reload the Monit service:
sudo monit reload
In your Monit service manager, you should see:
If you want to add another service that is not in the ready-made file, you can add it manually.
For example, If you want to detect all information about your system hardware using sensors, you can install it by using the command below:
sudo apt install lm-sensors -y
Then, you need to create the file for it:
sudo vi /etc/monit/conf-available/sensors
Add the following content to it:
check program sensors with path /usr/bin/sensors
if status != 0 then alert
When you are done, save and close the file.
Next, enable it by using the command below:
sudo ln -s /etc/monit/conf-available/sensors /etc/monit/conf-enabled/
Finally, reload the Monit service on Ubuntu 20.04:
sudo monit reload
That’s it, you are done.
Conclusion
At this point, you have learned to Install and Configure Monit Service Manager on Ubuntu 20.04. Also, you have learned to add services to be monitored on Monit.
Hope you enjoy it. Please subscribe to us on Facebook and Twitter.