How to Install Monit on Ubuntu 22.10/22.04/20.04

Monit is an open-source utility program that manages and monitors resources and services on Linux systems such as Ubuntu. Some services and resources managed by Monit are CPU usage, memory usage, server uptime, network connections, and server application services. The monitoring manager ensures that all running services are always healthy by restarting services that stop or encounter operating errors. These errors can be caused by many things, such as a power outage or a service crash Monit can help prevent downtime and keep your system running smoothly by monitoring and managing these resources.

In the following tutorial, you will learn how to install Monit on Ubuntu 22.10, 22.04, and 20.04 using the version direct from Ubuntu’s repository and how to configure Monit to be accessible from your browser using the command line terminal.

Important Notice

The following tutorial was done with a Ubuntu 22.04 LTS release, and example images were taken. Still, it was tested on Ubuntu 20.04 and Ubuntu 22.10. In the future, if Ubuntu makes any changes to break the tutorial for one of the distribution versions, please place a comment for me to investigate so I can update the tutorial.

Please also note the different versions of Ubuntu may see a different version of Monit.

Recommended Steps Before Installation

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



sudo apt update

Optionally, you can list the updates for users who require review or are curious.

sudo apt --list upgradable

Proceed to upgrade any outdated packages using the following command.

sudo apt upgrade

Install Monit on Ubuntu Linux

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 -y

Once installed, you will need to 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

Example output:

systemctl status ok on monit on Ubuntu 22.10, Ubuntu 22.04 and Ubuntu 20.04

As mentioned above, Monit is working on the back end. Now proceed to the next section to configure the web interface.

Configure Monit Web User Interface on Ubuntu Linux

Now that Monit is working, you need to edit the configuration file in the following path “/etc/monit/monitrc” using any text editor. The tutorial will use nano as its most user-friendly and will be installed by default on Ubuntu.

Open the configuration file with 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.



Example:

set httpd port 2812 and
allow joshmonit:strongpassword

For users in local environments, you can uncomment the “allow localhost,” which will drop non-local clients.

Example:

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

Do not uncomment the above if you are accessing from outside.

Save the configuration file with CTRL+O, then exit with CTRL+X.

Once done, test the service to ensure the configuration file has no errors.



sudo monit -t

Example output:

Control file syntax OK

Now restart the service for the configuration file changes to take effect.

sudo systemctl restart monit

Configure Monit UFW Rules on Ubuntu Linux

UFW should default be installed on your system and perhaps even enabled. You will need to create allow rules on the TCP port 2812 or what other port you specified in the configuration.

First, ensure UFW is installed in case it is not present.

sudo apt install ufw -y

Next, enable UFW.

sudo ufw enable

Some examples are below, depending on your installation and requirements if using singular or in 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; ensure the internal network is secure and trustworthy before allowing it.

Access Monit Web User Interface on Ubuntu Linux

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

Example:

http://192.0.150.220:2812

Users can use localhost for connecting locally.



http://localhost:2812

Example output:

login to Monit on Ubuntu 22.10, Ubuntu 22.04 and Ubuntu 20.04

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.

Example:

Example Monit service manager  on Ubuntu 22.10, Ubuntu 22.04 and Ubuntu 20.04

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

Example:

Example system status on Ubuntu 22.10, Ubuntu 22.04 and Ubuntu 20.04

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



Example:

Example Monit runtime information on Ubuntu 22.10, Ubuntu 22.04 and Ubuntu 20.04

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.

Update Monit on Ubuntu Linux

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 would advise running the terminal update commands every so often to ensure your system is correctly updated.

Remove Monit on Ubuntu Linux

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

sudo apt autoremove monit --purge

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




Not what you were looking for? Try searching for additional tutorials.

Leave a Comment