關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • Centos 安裝及設定 MRTG

    Posted on December 22nd, 2011 Sam Tang No comments

    MRTG 是一套十分出名的網路流量監察工具,它會透過 SNMP 協定取得網路流量資料,並以網頁介面輸出。要安裝 MRTG,需要安裝以下套件:

    mrtg: MRTG 的主程式
    net-snmp: NET-SNMP 內建幾個 SNMP 工具,包括 snmpd 及 snmptrapd daemons 及文檔等。
    net-snmp-utils: 內建一些 NET-SNMP 工具。

    以下是在 Centos 安裝及設定 MRTG 的步驟:

    1. 安裝 MRTG:

    在 Centos 下輸入以下指令安裝所需套件:

    # yum install mrtg net-snmp net-snmp-utils

     
    2. 設定 SNMP:
    開啟 /etc/snmp/snmpd.conf,加入以下下一行:

    rocommunity mrtg

    儲存好 snmpd.conf 後重新啟動,並設定系統自動啟動 snmpd:

    # chkconfig snmpd on
    # /etc/rc.d/init.d/snmpd restart

     

    3. 設定 MRTG

    安裝 MRTG 後,要用 cfgmaker 工具建立 /etc/mrtg/mrtg.cfg 檔案,方法如下:

    # cfgmaker –global ‘WorkDir: /var/www/mrtg’ –output /etc/mrtg/mrtg.cfg mrtg@localhost

     
    下面的指令會建立 /etc/mrtg/mrtg.cnf 檔案,/var/www/mrtg 為 MRTG 在網頁伺服器的工作目錄,會儲存輸出的 html 及 png 圖像檔案。而 public@localhost 的 public 是在 snmpd.conf 設定的 community name,而 localhost 則是要監察的主機。

    然後要執行 indexmaker 建立顯示流量的網頁檔案:

    # indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

     
    4. 用 Crontab 自動更新流量狀態

    在 crontab 加入以下一行,MRTG 便會每 5 分鐘更新一次:

    */5 * * * * /usr/bin/mrtg /etc/mrtg/mrtg.cfg

    要查看 MRTG 報表,就可以用以下網址,其中 localhost 要換成主機的 hostname:

    http://localhost/mrtg/


    Comments are closed.