轉自:http://www.live-in.org/archives/1221.html
Munin是一個網絡資源監控工具,通過自帶插件可以監控很多系統服務。官網:http://munin-monitoring.org/。Munin需要在web server上運行。這裏系統爲CentOS6.2,監控機IP爲192.168.1.100,被監控機IP爲192.168.1.200。經過比較,不使用複雜的源碼編譯安裝,參考官方wiki上使用yum方式安裝。
一、監控機配置(Munin master)
0、先安裝web server
這裏使用apache。
yum install httpd
apache基本配置略過。Munin也可以運行在一個Java的web server上(Resin from www.caucho.com)。
1、安裝EPEL源
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
vim /etc/yum.repos.d/dag.repo
輸入:
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
2、安裝munin
yum install munin
3、簡單配置munin master
安裝完後在/var/www/html會有munin目錄,/etc下也有munin目錄。
PS:剛安裝完/var/www/html/munin目錄下是沒有index.html,但後面登陸時會自動生成的。
vim /etc/munin/munin.conf
將以下幾行的註釋去掉:
dbdir /var/lib/munin
htmldir /var/www/html/munin
logdir /var/log/munin
rundir /var/run/munin
tmpldir /etc/munin/templates
將以下監控本機的代碼註釋掉:
#[x86-07.phx2.fedoraproject.org]
# address 127.0.0.1
# use_node_name yes
同時添加被監控機地址:
[server01]
address 192.168.1.200
use_node_name yes
use_node_name命令控制munin命名節點的方式,如果後面跟的參數爲yes就是用括號中的值來命名,如果是no則將執行一個DNS查詢。
4、設置登陸用戶和密碼:
htpasswd -c /etc/munin/munin-htpasswd muninadmin
輸入兩遍密碼。這裏建立了一個名爲muninadmin的用戶。
5、安裝完munin服務端後,程序會自動創建一個計劃任務
cat /etc/cron.d/munin
可以看到是每5分鐘獲取一次數據:
*/5 * * * * munin test -x /usr/bin/munin-cron && /usr/bin/munin-cron
需要啓動crond服務:
service crond start
6、重啓httpd
service httpd restart
二、被監控機配置(Munin node)
1、也需要安裝EPEL源
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
vim /etc/yum.repos.d/dag.repo
輸入:
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
2、安裝munin-node
yum install munin-node
3、配置munin node
vim /etc/munin/munin-node.conf
找到:
allow ^127\.0\.0\.1$
這裏是表示允許誰來獲取信息,在下面加上監控機IP:
allow ^192\.168\.1\.100$
4、啓動munin-node
service munin-node start
三、收尾
1、監控機測試客戶端
在監控機使用telnet命令連接到客戶端:
telnet 192.168.1.200 4949
使用list、fetch cpu命令查看能否獲得信息。
2、訪問http://監控機IP/munin
輸入前面設置的用戶名和密碼登陸。如果驗證用戶名和密碼和後,頁面顯示Index of munin說明index.html沒有生成,看日誌是因爲沒有nodes,檢查配置是否有錯,ip是不是寫錯了。
3、其它
監控機會產生四個日誌文件,在/var/log/munin目錄下:
munin-graph.log
munin-html.log
munin-limits.log
munin-update.log
被監控機產生一個日誌文件,同樣在/var/log/munin目錄下:
munin-node.log
被監控機的插件目錄在/etc/munin/plugins目錄。
參考資料:
http://blog.zfcms.com/article/458
http://blog.chinaunix.net/uid-15795819-id-3118511.html
http://salogs.com/2011/09/munin-application-notes-installation/
http://www.debian-administration.org/articles/597
http://munin-monitoring.org/wiki/LinuxInstallation