UbuntuUbuntu Based

How To Install Monit on Ubuntu 24.04 LTS

Install Monit on Ubuntu 24.04

In this tutorial, we will show you how to install Monit on Ubuntu 24.04 LTS. Monit is a lightweight, cross-platform monitoring tool that provides a simple and efficient way to manage and monitor processes, files, directories, and filesystems on Unix-like operating systems. It can automatically restart services that have crashed or failed, send alerts via email or SMS, and generate detailed reports on system health and performance.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Monit monitoring tool on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Monit on Ubuntu 24.04 LTS

Step 1. Updating the Package Repository.

Updating your system ensures that all existing packages are up-to-date, which can prevent potential conflicts during the installation process.

sudo apt update
sudo apt upgrade

The apt update command fetches the latest package information from the configured sources while apt upgrade installing available upgrades for all packages currently installed on the system.

Step 2. Installing Monit on Ubuntu 24.04.

Install Monit from the official Ubuntu repository:

sudo apt install monit

Once the installation is complete, verify that Monit was installed correctly by checking its version:

monit -V

This command will display the version of Monit installed on your system.

Step 3. Configuring Monit.

With Monit installed, it’s time to configure it to suit your specific monitoring needs. The main configuration file for Monit is located at /etc/monit/monitrc. Let’s make some basic configurations to get you started.

Open the configuration file using your preferred text editor:

sudo nano /etc/monit/monitrc

First, let’s enable the web interface for easy management. Find the following lines and uncomment them (remove the # at the beginning of each line):

set httpd port 2812 and
    use address localhost
    allow localhost

To secure the web interface, add authentication by including these lines:

 allow admin:your_password

Configure email alerts by adding or modifying the following lines:

set mailserver smtp.gmail.com port 587
    username "your_email@gmail.com" password "your_email_password"
    using tlsv12

set alert your_email@gmail.com

Save the file and exit the text editor, then test your configuration for syntax errors:

sudo monit -t

Now that we have Monit configured, let’s start the service and enable it to run on system boot.

sudo systemctl start monit

Enable Monit to start automatically on system boot:

sudo systemctl enable monit

Step 4. Configure Firewall.

If you’re using a firewall, ensure that port 2812 is open:

sudo ufw allow 2812/tcp

Step 5. Accessing the Monit web interface.

Now open your web browser to access the Monit web interface via the URL http://your-server-ip-2812. You will be prompted to enter a Monit admin username and password (see below):

Install Monit on Ubuntu 24.04 LTS

Step 6. Monitoring Services with Monit.

Monit excels at monitoring and managing services. Let’s set up monitoring for some common services.
Monitoring Apache Web Server.

Monitoring Apache Web Server

Create a configuration file for Apache:

sudo nano /etc/monit/conf.d/apache2

Add the following content:

check process apache2 with pidfile /var/run/apache2/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if cpu usage > 95% for 3 cycles then restart
if memory usage > 200 MB for 5 cycles then restart
if failed host localhost port 80 protocol http then restart

Monitoring MySQL Database

Create a configuration file for MySQL:

sudo nano /etc/monit/conf.d/mysql

Add the following content:

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if cpu usage > 90% for 5 cycles then restart
if memory usage > 500 MB for 5 cycles then restart
if failed host localhost port 3306 then restart

Save the files and reload Monit:

sudo monit reload

Step 7. Troubleshooting Common Issues.

Even with careful setup, you might encounter some issues. Here are solutions to common problems:

    1. Monit fails to start:
      • Check the Monit log file: sudo tail -f /var/log/monit.log
      • Verify the syntax of your configuration files: sudo monit -t
    2. Web interface access problems:
      • Ensure the web interface is enabled in the configuration.
      • Check firewall settings to allow access to port 2812.
    3. Email alert configuration issues:
      • Verify your SMTP server settings.
      • Check your email credentials and ensure they’re correctly entered in the configuration.
    4. Resource monitoring inaccuracies:
      • Adjust the monitoring thresholds based on your system’s typical performance.
      • Increase the number of cycles before an alert is triggered to avoid false positives.

Congratulations! You have successfully installed Monit. Thanks for using this tutorial for installing the Monit monitoring tool on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Monit website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button