In this tutorial, we want to teach you to Install and Configure Monit Service Manager on Ubuntu 22.04.
Monit is an open-source monitoring tool for Linux operating systems. This utility allows to:
- manage and monitor processes, programs, files, directories, and file systems, and log changes in file size, directories content, and checksums.
- get information about the status of each process that is monitored, and about the resources that the operating system allocates for these processes;
- stop resource-intensive processes, restart the services that stop responding, and start the stopped services.
Steps To Install Monit Manager on Ubuntu 22.04
To complete this guide, you must 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 22.04.
Install Monit o Ubuntu 22.04
The Monit packages are available in the default Ubuntu 22.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
Manage Monit Service
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 Wed 2023-03-01 12:09:16 UTC; 10s ago Docs: man:systemd-sysv-generator(8) Process: 2648 ExecStart=/etc/init.d/monit start (code=exited, status=0/SUCCE SS) Tasks: 1 (limit: 4575) Memory: 2.1M CPU: 53ms CGroup: /system.slice/monit.service └─2654 /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.31.0 Built with ssl, with ipv6, with compression, with pam and with large files Copyright (C) 2001-2022 Tildeslash Ltd. All Rights Reserved.
Configure Monit Service Manager on Ubuntu 22.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
There 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 22.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
Monit 5.31.0 uptime: 0m System 'ubuntu.jammy' status OK monitoring status Monitored monitoring mode active on reboot start load average [0.00] [0.02] [0.07] cpu 0.0%usr 0.0%sys 0.0%nice 0.0%iowait 0.0%hardirq 0.0%softirq 0.0%steal 0.0%guest 0.0%guestnice memory usage 427.4 MB [10.9%] swap usage 0 B [0.0%] uptime 23m boot time Wed, 01 Mar 2023 12:00:03 filedescriptors 1024 [0.0% of 9223372036854775807 limit] data collected Wed, 01 Mar 2023 12:23:16
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:
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 22.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.
/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
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 22.04:
sudo monit reload
That’s it, you are done.
At this point, you have learned to Install and Configure Monit Service Manager on Ubuntu 22.04. Also, you have learned to add services to be monitored on Monit.
Hope you enjoy it. You may be like these articles:
Install and Configure Odoo 16 on Ubuntu 22.04