How to Install Monit on Ubuntu 24.04, 22.04 or 20.04

Monit is a powerful and versatile monitoring tool that helps you manage and monitor Unix systems. It can oversee system processes, files, directories, and devices, providing automated maintenance and repair. Monit can monitor system load, CPU usage, memory usage, and network connections. Additionally, it can check the status of server applications such as Apache, MySQL, and more. Monit not only alerts you when issues arise but can also take corrective actions, such as restarting failed services or executing scripts, ensuring system reliability and performance.

To install Monit on Ubuntu 24.04, 22.04, or 20.04 using the command-line terminal, you can utilize the default Ubuntu repository. This method ensures you get a stable and up-to-date version of Monit, ready to help you efficiently monitor and manage your system.

Update Ubuntu Before Monit Installation

Before proceeding with the tutorial, ensuring your system is up-to-date with all existing packages is good:

sudo apt update

Proceed to upgrade any outdated packages using the following command:

sudo apt upgrade

Proceed With Monit Installation

Monit is available on Ubuntu’s default repository, making the installation quick and straightforward.

First, use the following command to install the application:

sudo apt install monit

Once installed, you must enable and start the service, which you can do using the following command.

sudo systemctl enable monit --now

Lastly, confirm Monit is operational without any errors using the following.

systemctl status monit

Configure Monit Web User Interface

With Monit operational, please modify the configuration file located at “/etc/monit/monitrc.” For this task, utilize a text editor of your choice. This tutorial recommends using Nano for its user-friendly interface, which typically comes pre-installed on Ubuntu systems.

To open the configuration file, execute the following command:

sudo nano /etc/monit/monitrc

Now, find the lines in the configuration file:

# set httpd port 2812 and
# allow admin:monit

Next, modify the username and password with your own; you can keep admin, but I would change this. Optionally, you can adjust the default port of 2812 with another less-known port for users in sensitive environments.

set httpd port 2812 and
allow joshmonit:strongpassword

To accommodate users in local environments, please uncomment the “allow localhost” line to ensure non-local clients are excluded.

use address localhost  # only accept connection from localhost (drop if y><p if you use M/Monit)
allow localhost        # allow localhost to connect to the server

If you are accessing from an external location, refrain from uncommenting the above lines. Securely save the configuration file by pressing CTRL+O and exit by pressing CTRL+X.

Upon completion, proactively test the service to verify that the configuration file is free of errors:

sudo monit -t

Example output:

Control file syntax OK

Now restart the service so the configuration file changes take effect.

sudo systemctl restart monit

Configure Monit UFW Rules

Your system likely has UFW pre-installed and possibly activated. To facilitate communication with Monit, you must establish allow rules for TCP port 2812 or any alternate port you designated in your Monit configuration.

Begin by confirming the installation of UFW, and install it if absent:

sudo apt install ufw -y

Next, enable UFW:

sudo ufw enable

Depending on your installation and requirements, some examples are below using a singular or a cluster network.

Additional network IP server instance:

sudo ufw allow proto tcp from <ip address> to any port 2812

Cluster network with many instances:

sudo ufw allow proto tcp from <ip address>/24 to any port 2812

Note that the second UFW rule is a subnet rule; before allowing it, ensure the internal network is secure and trustworthy.

Access Monit Web User Interface

Now that you have installed Monit and configured the back end, you can access the Monit service using the server’s IP address.

http://192.0.150.220:2812

Users can use localhost to connect locally.

http://localhost:2812

Log in with the username and password set in the configuration file. Once in, you will arrive at the main dashboard with your overall view.

Once on the dashboard, you can click on your system to show more detailed stats.

Also, for users who may encounter issues and need to adjust some settings, you can see the overview of your Monit settings using the web interface.

The tutorial showed the basic setup; you can monitor extensively with different options. I would advise checking out the Monit Documentation Manual on the official website.

Additional Commands For Monit

Update Monit

Given you have installed Monit using Ubuntu’s default repository, the process is the same using the command line terminal:

sudo apt update && sudo apt upgrade

For desktop users with automatic updates enabled, I recommend occasionally running the terminal update commands to ensure your system is correctly updated.

Remove Monit

Users that no longer require Monit on their Ubuntu system use the following command to remove the application entirely:

sudo apt remove monit

The above command will purge the data that was created with it.

Conclusion

With Monit successfully installed on your Ubuntu system, you can now configure it to monitor various aspects of your system. Edit the configuration file located at /etc/monit/monitrc to specify what you want Monit to monitor. To access the Monit web interface, enable the HTTP server in the configuration file and set the appropriate access permissions. Restart the Monit service to apply the changes, and you can access the web interface via http://localhost:2812. Regularly update and fine-tune your configuration to ensure optimal system performance and reliability. For additional help, refer to Monit’s documentation and community resources.

Leave a Comment