Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 系統安裝 Monitorix 系統監控工具完整教學

編輯:關於 Linux

Monitorix 是輕量級、基於 Web 的系統監控工具,以 Perl 撰寫,透過 rrdtool 產生圖表,支援 CPU、記憶體、磁碟、網路、服務、感測器等上百項指標。無需資料庫、設定簡單,適合中小型伺服器快速部署。本文說明 CentOS 7/8/9 完整安裝、設定與多主機監控步驟。

前置需求

  • CentOS 7 / 8 / 9 / Rocky / AlmaLinux
  • EPEL 倉庫已啟用(yum install epel-release)
  • HTTP 埠 8080 可存取(防火牆/安全群組放行)

安裝步驟

1. 安裝依賴套件

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

2. 下載並安裝 Monitorix RPM

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

3. 設定主配置檔 /etc/monitorix.conf

關鍵設定項:

/var/lib/monitorix
y
8080
nobody
nobody
2
y
# 或個別啟用:
y
y
y
y
y
y
y
y
y
y

4. SELinux 設定(關鍵)

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

5. 啟動並設定開機自啟

systemctl enable --now monitorix
# CentOS 7 相容指令:
chkconfig --level 35 monitorix on
service monitorix start

6. 防火牆開放 8080 埠

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

7. 驗證存取

瀏覽器開啟 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

進階:Nginx 反向代理 + HTTPS

# /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 → 啟動服務 → 開放防火牆。輕量無資料庫設計,幾分鐘即可獲得專業級系統監控儀表板。多主機模式適合中小規模叢集統一監控視圖。

Copyright © Windows教程網 All Rights Reserved