MRTG 為使用 Perl 程式寫成的,並且使用到 zlib 、 gd 及 png 的函式庫(zlib 用來壓縮圖表、gd 用來繪製圖表),且由於 MRTG 乃使用 SNMP 協定,並且最後是以 HTTP 的網頁型態輸出成圖表,因此,你需要確定 Linux 主機中已經含有下列的套件:
perl (perl-5.0xx 以上)
zlib (zlib-1.1.3-xx 以上)
gd (gd-1.3.xx 以上)
libpng
apache
可以用rpm -qa | grep xxx來檢查
安裝設定snmp:
之前叫做ucd-snmp...在RH9改叫 net-snmp了
代碼: 選擇全部
# rpm -qa|grep snmp
net-snmp-devel-5.0.6-17
net-snmp-5.0.6-17
net-snmp-utils-5.0.6-17
如果沒有安裝,可以在RH9安裝片第二片中找到rpm檔安裝,
安裝完打開/etc/snmp/snmp.conf,修改下列部分紅色內容:
代碼: 選擇全部
# --------------------------------------------------
# Here is a commented out example configuration that allows less
# restrictive access.
# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE. YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.
## sec.name source community
com2sec local localhost netadmin
com2sec mynetwork 192.168.20.0/24 netadmin
# 註﹕請將 192.168.100.0/24 改為您機器目前所在的 network 範圍。
## group.name sec.model sec.name
group MyRWGroup v1 local
group MyROGroup v1 mynetwork
#
#group MyRWGroup any otherv3user
#...
## incl/excl subtree mask
view all included .1 80
## -or just the mib2 tree-
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
## context sec.model sec.level prefix read write notif
access MyROGroup "" any noauth prefix all none none
access MyRWGroup "" any noauth prefix all all all
存檔後,啟動snmpd,/etc/rc.d/init.d/snmpd start
安裝MRTG:
http://www.ee.ethz.ch/~oetiker/webtools/mrtg/
下載source檔,
代碼: 選擇全部
[root @www /root]# cd /usr/local/src
[root @www src]# cp /root/mrtg-2.10.15.tar.gz
[root @www src]# tar -zxvf mrtg-2.10.15.tar.gz
[root @www src]# cd mrtg-2.10.15
[root @www mrtg-2.10.15]# ./configure --prefix=/usr/local/mrtg-2 \
> --with-gd=/usr/include \
> --with-gd-lib=/usr/lib \
> --with-gd-inc=/usr/include \
> --with-png=/usr/include \
> --with-zlib=/usr/include
[root @www mrtg-2.10.15]# make; make install
產生 mrtg.cfg 檔﹕
代碼: 選擇全部
[root @www mrtg-2.10.15]# cd /usr/local/mrtg-2/bin
[root @www bin]# ./cfgmaker --output=/usr/local/apache/htdocs/mrtg/net/mrtg.cfg \
> --global 'Language: big5' \
> --global 'Options[_]: bits,growright' \
> --output /etc/mrtg/mrtg.cfg \
> netadmin@192.168.0.1
#@後面為該機器之IP
[root @www bin]# ./mrtg /usr/local/apache/htdocs/mrtg/net/mrtg.cfg
#連續執行 3 次
若執行 mrtg /etc/mrtg/mrtg.cfg 碰到如下錯誤:
Malformed UTF-8 character (unexpected end of string) at /usr/bin/../lib/mrtg2/locales_mrtg.pm line 614.
那可能是 locale 的關係,可先執行 export LANG=C 再重跑 mrtg 命令。
產生index.html
代碼: 選擇全部
[root@www bin]# ./indexmaker mrtg.cfg \
> --output=/usr/local/apache/htdocs/mrtg/net/index.html \
> --title=主機流量統計表 \
> /usr/local/apache/htdocs/mrtg/net/mrtg.cfg
設定排程,設定五分鐘偵測一次:
代碼: 選擇全部
[root @www bin]# vi /etc/crontab
#1. Runing The MRTG Net Flow Control
*/5 * * * * root /usr/local/mrtg-2/bin/mrtg /usr/local/apache/htdocs/mrtg/net/mrtg.cfg > /dev/null 2>&1
參考資料:
http://linux.vbird.org/linux_security/old/04mrtg.php
http://www.study-area.org/tips/mrtg.htm
http://www.adj.idv.tw/phpBB2/viewtopic.php?t=960