Install Monit Manager on Ubuntu 22.04 with Efficient Steps
This tutorial, brought to you by Orcacore, will guide you through the process to Install Monit Manager on Ubuntu 22.04. Monit is a powerful, open-source utility designed for monitoring Linux operating systems. It allows you to:
- Automatically restart services if they fail.
- Monitor system resources like CPU usage, memory, and disk space.
- Execute custom actions based on specific conditions.
- Alert you to issues via email or other notification methods.
To successfully Install Monit Manager on Ubuntu 22.04, you’ll need a server running Ubuntu 22.04. It’s recommended to log in as a non-root user with sudo privileges and have a basic firewall configured. You can refer to our guide on Initial Server Setup with Ubuntu 22.04 for assistance with this initial setup.
1. Install Monit Service Ubuntu 22.04
Monit packages are readily available in the default Ubuntu 22.04 repositories. Begin by updating your local package index using the following command:
sudo apt update && sudo apt upgrade -y
Next, install Monit using the apt package manager:
sudo apt install monit -y
2. Manage Monit Service Ubuntu 22.04
After installation, the Monit service should be running on your server. To verify its status, execute the following command:
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/SUCCESS)
Tasks: 1 (limit: 4575)
Memory: 2.1M
CPU: 53ms
CGroup: /system.slice/monit.service
└─2654 /usr/bin/monit -c /etc/monit/monitrc
...
If the service is not running, you can start it with:
sudo systemctl start monit
You can also check the installed 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.
3. Configure Monit Service Ubuntu 22.04
The primary configuration file for Monit is /etc/monit/monitrc
. It’s best practice to avoid directly modifying this file. Instead, create separate configuration files for your specific monitoring needs.
Enable Monit httpd port
By default, the HTTP interface, which uses port 2812, is disabled. To enable it, edit the Monit configuration file using your preferred text editor (e.g., vi):
sudo vi /etc/monit/monitrc
Locate the line set httpd port 2812
and remove the #
symbol to uncomment it. If you want to access the Monit web interface remotely, change use address localhost
to use address 0.0.0.0
. You can also modify the default admin username and password (default: admin: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'
Save the file and exit the editor.
To verify the Monit configuration syntax, run:
sudo monit -t
Output:
Control file syntax OK
4. Enable Monit Service Ubuntu 22.04
Monit is not enabled to start automatically on boot by default. To enable this, use the following command:
sudo /lib/systemd/systemd-sysv-install enable monit
To apply the changes, restart the Monit service:
sudo systemctl restart monit
Verify that Monit is running correctly by checking its status:
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
5. Configure Firewall for Monit
Allow access to the Monit web interface through the UFW firewall by opening port 2812:
sudo ufw allow 2812
Reload the firewall to activate the new rule:
sudo ufw reload
6. Access Monit Service Manager Web Interface
You can now access the Monit web interface by navigating to your server’s IP address followed by port 2812 in your web browser:
http://<your-server-ip-address>:2812
Enter the admin username and password you configured in the monitrc
file and click Sign in.
[Monit Sign in Image]
You should see the Monit Service Manager dashboard:
[Monit Service Manager Image]
7. Add Services In Monit on Ubuntu 22.04
Monit can monitor various applications using pre-configured files or custom configurations.
The /etc/monit/conf-available/
directory contains pre-made configuration files for common server services, including:
acpid, at, mdadm, mysql, openntpd, pdns-recursor, rsyslog, snmpd,
apache2, cron, memcached, nginx, openssh-server, postfix and smartmontools.
To enable monitoring for a service, create a symbolic link to its configuration file in the /etc/monit/conf-enabled/
directory.
For example, to monitor Nginx, use the following command:
sudo ln -s /etc/monit/conf-available/nginx /etc/monit/conf-enabled/
Then, reload the Monit service:
sudo monit reload
The Nginx service should now appear in your Monit service manager:
[Add Services Image]
To monitor a service without a pre-configured file, you can create a custom configuration.
For example, to monitor system hardware sensors, first install the lm-sensors
package:
sudo apt install lm-sensors -y
Then, create a configuration file for the sensors:
sudo vi /etc/monit/conf-available/sensors
Add the following content to the file:
check program sensors with path /usr/bin/sensors
if status != 0 then alert
Save and close the file.
Next, enable the configuration:
sudo ln -s /etc/monit/conf-available/sensors /etc/monit/conf-enabled/
Finally, reload the Monit service:
sudo monit reload
That completes the process of adding and configuring services to be monitored by Install Monit Manager on Ubuntu 22.04.
Conclusion
This tutorial demonstrated how to Install Monit Manager on Ubuntu 22.04 and configure it to monitor services. You learned how to install Monit, enable the web interface, configure the firewall, and add services for monitoring.
You may also like these articles:
- Install and Configure Odoo 16 on Ubuntu 22.04
- Install and Configure OpenNMS on Ubuntu 22.04
- ownCloud Setup on Ubuntu 22.04 Jammy Jellyfish
- Seafile Server Setup Ubuntu 22.04
- Run Apache in Docker Container on Ubuntu 22.04
- ManageEngine OpManager on Ubuntu 22.04
- Install Powerline For VIM and Bash on Ubuntu 22.04
- Set up Latest OpenSSL on Ubuntu 22.04
Alternative Solutions for Service Monitoring
While Monit is a robust solution for service monitoring, other alternatives exist that offer different features and approaches. Here are two alternative solutions:
1. Systemd Service Monitoring:
Systemd, the system and service manager in Ubuntu 22.04, provides built-in capabilities for monitoring and managing services. You can configure Systemd to automatically restart services upon failure, monitor resource usage, and log events. This approach eliminates the need for a separate monitoring tool, leveraging the existing Systemd infrastructure. The downside is that you won’t have a dedicated web interface like Monit. You would have to query the service status through command line or logging tools.
To configure a service to restart automatically on failure using Systemd, you can modify the service unit file.
For example, to configure the Nginx service, you would edit the /etc/systemd/system/nginx.service
file (or a file in /etc/systemd/system/nginx.service.d/
for overrides) and add or modify the following lines in the [Service]
section:
[Service]
Restart=on-failure
RestartSec=5s
Restart=on-failure
: Specifies that the service should be restarted if it exits with a non-zero exit code. Other options includeon-success
,always
, etc.RestartSec=5s
: Specifies the delay (in seconds) before attempting to restart the service.
After making these changes, reload the Systemd configuration:
sudo systemctl daemon-reload
Then, restart the Nginx service:
sudo systemctl restart nginx
To check the restart policy and current status, you can use systemctl status nginx
.
This approach is lightweight and efficient, as it utilizes the existing Systemd infrastructure. However, it lacks the centralized web interface and advanced alerting features of Monit.
2. Prometheus and Grafana:
Prometheus is an open-source systems monitoring and alerting toolkit. It collects metrics from your systems and services, stores them as time-series data, and provides a powerful query language (PromQL) for analyzing the data. Grafana is a data visualization tool that can be used to create dashboards based on Prometheus metrics. This combination allows you to build comprehensive monitoring solutions with detailed insights into your system’s performance.
To use Prometheus and Grafana, you would first need to install and configure them. The installation process is outside the scope of this article but involves downloading the binaries, configuring the Prometheus server, and installing Grafana.
Once installed, you would configure Prometheus to scrape metrics from your services. This typically involves installing "exporters" on the systems you want to monitor. For example, to monitor system resources, you could install the node_exporter
. For monitoring Nginx, you can use the nginx-exporter
.
The Prometheus configuration file (prometheus.yml
) would then be updated to include these exporters as targets:
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100'] # Assuming node_exporter is running on localhost:9100
- job_name: 'nginx_exporter'
static_configs:
- targets: ['localhost:9113'] # Assuming nginx_exporter is running on localhost:9113
After configuring Prometheus, you can import pre-built dashboards into Grafana to visualize the metrics collected by Prometheus. These dashboards provide a comprehensive view of your system’s performance, including CPU usage, memory usage, network traffic, and service-specific metrics.
Prometheus and Grafana offer a highly scalable and customizable monitoring solution. They are well-suited for complex environments with numerous services and systems. However, the setup and configuration process can be more involved compared to Monit or Systemd’s built-in capabilities.