Search
Close this search box.

How to Install Monit Monitoring Tool on Ubuntu 22.04

Table of Contents

Monitoring and maintaining the health of your server is crucial for ensuring its optimal performance and reliability. Monit is a powerful and lightweight open-source monitoring tool designed to manage and monitor Unix systems. It helps administrators keep track of system processes, files, directories, and more, providing automated maintenance and repair whenever necessary. In this guide, we will walk you through the step-by-step process of installing and configuring Monit on Ubuntu 22.04, empowering you to efficiently oversee your server’s performance and stability. Whether you’re a seasoned system administrator or a newcomer to server management, this tutorial will equip you with the knowledge to harness Monit’s capabilities on your Ubuntu system.

 

 

To start, make sure you’ve created a VPSie account if you haven’t already. Next, proceed by deploying an Ubuntu 22.04 server configured to meet your specific needs.

 

Once the server is deployed, SSH into the command line interface. Before installing any packages, it’s essential to update your system’s package list to ensure you have access to the latest versions. Open a terminal and run the following command:

sudo apt-get update -y

 

Install Monit

By default, the Monit package is available in the Ubuntu 22.04 default repository. You can install it with this command:

sudo apt install monit

 

After successfully installing Monit, you can start the Monit service and enable it to start automatically at system reboot by executing the following commands:

sudo systemctl start monit
sudo systemctl enable monit

 

Verify the installation by checking the version of Monit:

monit --version

You can also check the status of the Monit using the following command:

systemctl status monit

Configure Monit

The main configuration file for Monit is located at /etc/monit/monitrc. Open this file in your favorite text editor:

sudo nano /etc/monit/monitrc

 

 

Uncomment the following line to enable the Monit web interface:

set httpd port 2812 and
use address localhost  # only accept connection from localhost
allow localhost        # allow localhost to connect to the server and

 

 

To access the web interface remotely, replace localhost with the IP address or hostname of your server and specify an IP or subnet allowed to connect:

set httpd port 2812 and
use address 0.0.0.0  # accept connection from any address
allow 0.0.0.0/0      # allow any IP to connect to the server

Save and close the file the restart the Monit service to apply the changes:

systemctl restart monit

 

By default, Monit listens on port 2812. You can verify this by running the following command:

ss -antpl | grep monit

 

Check your system status using the command below:

monit status

Add Monitoring Services

To add monitoring for specific services in Monit, you typically create configuration files tailored to each service you wish to monitor. However, Monit also offers predefined templates for certain processes and services, located in the /etc/monit/conf-available/ directory. For example, there’s a default Nginx template provided.

 

To link the Monit configuration for Nginx from the available configurations to the enabled ones, use the following command:

sudo ln -s /etc/monit/conf-available/nginx /etc/monit/conf-enabled/

 

After linking the configuration, restart the Monit service to apply the changes:

sudo systemctl restart monit

 

These commands enable the Nginx monitoring configuration in Monit and ensure that the changes take effect immediately by restarting the Monit service.

 

Adding Redis Monitoring service to Monit:

 

If Redis is not already installed on your system, install it using the following command:

sudo apt update
sudo apt install redis-server

 

By default, Redis should start automatically as a service after installation. You can check its status with:

sudo systemctl status redis-server

 

Now, let’s create a Monit configuration file for Redis:

 

Open the Monit configuration file for editing:

sudo nano /etc/monit/monitrc

 

Add the following configuration block to monitor Redis:

check process redis-server with pidfile /var/run/redis/redis-server.pid
  start program = "/etc/init.d/redis-server start"
  stop program  = "/etc/init.d/redis-server stop"
  if failed host 127.0.0.1 port 6379 then restart

 

Adjust the pidfile, start program, stop program, and if failed conditions as necessary based on your Redis installation and configuration.

 

Save and close the file Ctrl+X, then Y, then Enter.

 

Enable the Monit service to start on boot:

sudo systemctl enable monit

 

Check the syntax of your Monit configuration to ensure it’s valid:

sudo monit -t

 

If the syntax is correct, reload the Monit service to apply the new configuration:

sudo monit reload

 

Check the status of Monit to ensure Redis monitoring is active:

sudo monit status

 

You should see Redis listed as monitored under Monit’s status output.

Test Monit’s monitoring capabilities by intentionally stopping Redis (sudo systemctl stop redis-server) and then checking if Monit automatically restarts it (sudo monit status).

 

Access Monit Web UI

You can now access Monit Web Interface through your browser at http://<your_server_ip>:2812. Log in with the credentials you configured in the Monit configuration file.




In conclusion, Monit offers robust monitoring capabilities out-of-the-box for a variety of services like Apache, MySQL, and Nginx. However, for services like Redis that aren’t included by default, adding monitoring is straightforward with a few configuration steps. By customizing Monit’s configuration, users can ensure proactive monitoring and management of additional services tailored to their specific system needs.

Make a Comment
{{ reviewsTotal }}{{ options.labels.singularReviewCountLabel }}
{{ reviewsTotal }}{{ options.labels.pluralReviewCountLabel }}
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.