This guide shows how to set up M/Monit. If you are interested in Monit instead, checkout How to install and configure monit in Rocky Linux 8.
Monit is a small popular Open Source utility for managing and monitoring Unix systems. M/Monit builds on Monit’s capabilities and provides monitoring and management of all your Monit enabled hosts via a modern, clean and well designed user interface which also works on mobile devices.
M/Monit can monitor and manage distributed computer systems, conduct automatic maintenance and repair and execute meaningful causal actions in error situations.
Features
- Quick & Easy SetupEasy install and setup – turn key. Up and running in seconds
- UptimeYour computer systems will have a higher uptime as M/Monit can handle error conditions automatically, often without the need for human intervention.
- DesignM/Monit has a clean, simple and responsive User Interface which scales well, if you manage 2 hosts or 1000+ hosts.
- ChartsCreate beautiful charts for multiple hosts and compare key indicators from various machines and services
In this guide we will learn how to install and set up M/Monit in Linux to be used as a central place to monitor servers and services.
Step 1: Download the latest version
Mmonit distributes the installation package as a tar.gz for the various os architectures. Get the latest package for your linux distribution architecture from the download site here.
I am using an x64 linux, these are the commands to switch to the /opt directory and download the file. You might have to run these command as root to avoid permission denied.
cd /opt
curl -LO https://mmonit.com/dist/mmonit-3.7.11-linux-x64.tar.gz
We can then extract and remove the tar file
tar -xzvf mmonit-3.7.11-linux-x64.tar.gz
rm -rf mmonit-3.7.11-linux-x64.tar.gz
Step 2: Create a systemd to manage the service
After extracting, the executable file is located at this path /opt/mmonit-3.7.11/bin/mmonit
. To ensure that the service runs beyond our login session, let us use the systemd service manager to manage the service.
Create the systemd service file. I am using vim to open the service file:
sudo vim /etc/systemd/system/mmonit.service
Then add this content:
[Unit]
Description=M/Monit server
[Service]
Type=simple
WorkingDirectory=/opt/mmonit-3.7.11
PIDFile=/var/run/mmonit.pid
ExecStart=/opt/mmonit-3.7.11/bin/mmonit -i -p /var/run
[Install]
WantedBy=multi-user.target
Finally, reload systemd daemons for the service to be recognized:
sudo systemctl daemon-reload
Step 3: Starting and enabling the service
Now start service using this command:
sudo systemctl start mmonit
Confirm that the service is running as expected using this command:
$ sudo systemctl status mmonit
● mmonit.service - M/Monit server
Loaded: loaded (/etc/systemd/system/mmonit.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2022-03-29 05:12:22 UTC; 10s ago
Main PID: 221347 (mmonit)
Tasks: 5 (limit: 23465)
Memory: 1.6M
CGroup: /system.slice/mmonit.service
└─221347 /opt/mmonit-3.7.11/bin/mmonit -i -p /var/run
Mar 29 05:12:22 monitoring systemd[1]: Started M/Monit server.
Mar 29 05:12:22 monitoring mmonit[221347]: mmonit 3.7.11 started
The Active: active (running) indicates that the service is up and running.
Enable the service on boot:
sudo systemctl enable mmonit
Step 4: Open port 8080 in firewall
Mmonit runs as a http service exposed on port 8080. If you have firewalld installed and enabled, use these commands to enable the port:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
Step 5: Accessing the service
We can now access the service. Open your browser and head to http://[server_ip]:8080
. You should be welcomed by M/Monit login page.
Login with Username admin
and password swordfish
. You will be redirected to the dashboard, it doesn’t contain anything but we are going to add servers and services to monitor in the next section.
Step 6: Configuring Nginx to proxy request
We can configure a domain to easily access out mmonit server. Ensure that the domain’s dns entry has been added to point to the mmonit server ip address.
Then install Nginx
# In Rocky Linux / RHEL based linux
sudo dnf install -y nginx
# In debian based linux
sudo apt install -y nginx
Add nginx config file
sudo vim /etc/nginx/conf.d/mmonit.conf
Then add this content
server {
listen 80;
server_tokens off;
server_name monit.citizix.com;
if ($host !~* ^(monit.citizix.com)$) {
return 444;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass http://127.0.0.1:8190;
}
}
Start and enable nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Now visit the page at http://monit.citizix.com to access the service