Monitorix 是輕量級、基於 Web 的系統監控工具,以 Perl 撰寫,透過 rrdtool 產生圖表,支援 CPU、記憶體、磁碟、網路、服務、感測器等上百項指標。無需資料庫、設定簡單,適合中小型伺服器快速部署。本文說明 CentOS 7/8/9 完整安裝、設定與多主機監控步驟。
yum install epel-release)yum install -y rrdtool rrdtool-perl perl-libwww-perl perl-MailTools \
perl-MIME-Lite perl-CGI perl-DBI perl-XML-Simple perl-Config-General \
perl-HTTP-Server-Simple wget
cd /tmp
wget https://www.monitorix.org/monitorix-3.16.0-1.noarch.rpm
rpm -ivh monitorix-3.16.0-1.noarch.rpm
或直接從 EPEL 安裝(版本可能較舊):
yum install -y monitorix
/etc/monitorix.conf關鍵設定項:
/var/lib/monitorix
y
8080
nobody
nobody
2
y
# 或個別啟用:
y
y
y
y
y
y
y
y
y
y
Monitorix 需讀寫 RRD 檔案,SELinux Enforcing 模式下會被阻擋。兩種方案擇一:
方案 A:設定布林值允許(推薦,保持 SELinux 啟用)
setsebool -P httpd_read_user_content 1
setsebool -P httpd_enable_homedirs 1
# 或建立自定義政策模組
方案 B:停用 SELinux(簡單但降低安全性)
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
reboot
systemctl enable --now monitorix
# CentOS 7 相容指令:
chkconfig --level 35 monitorix on
service monitorix start
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
瀏覽器開啟 https://伺服器IP:8080/monitorix/,應看到儀表板與圖表。
在主監控節點修改 /etc/monitorix.conf:
enabled = y
footer_url = y
graphs_per_row = 2
remotehost_list = server1, server2, server3
0 = https://192.168.1.10:8080/monitorix, /, server1
1 = https://192.168.1.11:8080/monitorix, /, server2
2 = https://192.168.1.12:8080/monitorix, /, server3
0 = Web Servers, server1, server2
1 = DB Servers, server3
每台被監控主機皆需安裝 Monitorix 並開放 8080 埠。
| 現象 | 解決方案 |
|---|---|
| 圖表顯示空白/錯誤 | 檢查 /var/log/messages、/var/log/audit/audit.log SELinux 拒絕訊息,執行方案 A 或 B |
| 無法存取 Web 介面 | 確認 systemctl status monitorix、防火牆 8080、netstat -tlnp | grep 8080 |
| Perl 模組缺失 | yum install perl-ModuleName 或 cpan Module::Name |
| RRD 檔案權限錯誤 | chown -R nobody:nobody /var/lib/monitorix |
# /etc/nginx/conf.d/monitorix.conf
server {
listen 443 ssl http2;
server_name monitor.example.com;
ssl_certificate /etc/letsencrypt/live/monitor.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/monitor.example.com/privkey.pem;
location /monitorix/ {
proxy_pass https://127.0.0.1:8080/;
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-Proto $scheme;
}
}
CentOS 安裝 Monitorix 核心流程:安裝 Perl 依賴 → RPM 安裝 Monitorix → 設定 /etc/monitorix.conf → 處理 SELinux → 啟動服務 → 開放防火牆。輕量無資料庫設計,幾分鐘即可獲得專業級系統監控儀表板。多主機模式適合中小規模叢集統一監控視圖。