Master Linux Monitoring with Monit: Installation, Configuration, and Real‑World Examples
This guide walks you through installing Monit on Ubuntu and CentOS, handling common build issues, configuring the web UI, setting up email alerts, and creating practical monitoring rules for processes, filesystems, files, custom scripts, and remote hosts.
Monit is a lightweight monitoring tool for Linux that can watch system resources, processes, files, directories, and devices, automatically restart failed services, and provide a built‑in web UI with color‑coded status indicators and email notifications.
Installation
On Ubuntu, install Monit with: sudo apt-get install monit On CentOS, use: yum install monit For source installation:
wget http://mmonit.com/monit/dist/monit-5.5.tar.gz
tar zxvf monit-5.5.tar.gz
cd monit-5.5
./configure --prefix=/usr
make
make installIf configure reports missing PAM headers, install the development package: apt-get install libpam0g-dev For SSL library errors, install the SSL development package and, if necessary, point configure to the library directory:
sudo apt-get install libssl-dev
./configure --prefix=/usr --with-ssl-lib-dir=/usr/lib/i386-linux-gnu/After compilation, copy the sample configuration file and set proper permissions:
mv monitrc /etc/monitrc
chown root:root /etc/monitrc
chmod 0700 /etc/monitrcStarting Monit and Web UI
Start the daemon: monit The built‑in HTTP server listens on port 2812. A basic configuration looks like:
set httpd port 2812 and
use address localhost
allow localhost
allow admin:monit
allow @monit
allow @users readonlyTo allow remote access, modify the address and credentials:
set httpd port 2812 and
use address 10.64.74.99
allow 0.0.0.0/0.0.0.0
allow manu:manuNow the UI can be reached at http://10.64.74.99:2812.
Basic Settings
set daemon 60 # check every 60 seconds
set logfile /var/log/monit.logEmail Alerts
set mailserver xxx.xx.xxx.xxx port 25 with timeout 15 seconds
set mail-format {
from: [email protected]
subject: monit alert -- $EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: $HOST
Description: $DESCRIPTION
Your faithful employee,
bean
}
set alert [email protected]Monitoring Examples
1. Process Monitoring
check process apache with pidfile /var/run/httpd.pid
start program = "/etc/init.d/rcWebServer.sh start https"
stop program = "/etc/init.d/rcWebServer.sh stop https"
if changed pid then alertFor processes without a PID file, use matching on the command line:
check process test_abc with MATCHING test_abc
if changed pid then alert2. Filesystem / Device Monitoring
check device VAR_LOG with path /var/log
if space usage > 85% then alert
check filesystem tmpfs with path /var
if space usage > 80% then alert3. File Monitoring
check file monit_target with path /var/log/monit_target
if failed permission 700 then alert
if size > 1000 MB then exec "/usr/local/bin/rotate /var/log/monit_target"4. Program Monitoring (Custom Script)
check program COREDUMP_EXIST with path "/var/log/tool/coredump_exist.sh"
if status != 0 then alert
#!/bin/sh
corefile_num=`ls /home/manu/core/core* 2>/dev/null | wc -l`
if [ $corefile_num -eq 0 ]; then
exit 0
else
exit 1
fi5. Host Monitoring
check host my_brother with address XX.XX.XX.XX
if failed icmp type echo count 3 with timeout 3 seconds then alertFor detailed options, refer to the official Monit documentation at http://mmonit.com/monit/documentation/monit.html#connection_testing .
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
