關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • FreeBSD 安裝 MRTG 流量分析

    Posted on May 4th, 2008 Sam Tang 2 comments

    MRTG 是一套網路流量分析工具,可以經由網頁介面監看主機的網路流量。MRTG 是透過 SNMP (Simple Network Management Protocol) 收集資料,所以要使用 MRTG 記錄流量數據的主機要先安裝 SNMP,以下是在 FreeBSD 安裝 SNMP 及 MRTG 的方法:

    安裝 SNMP
    首先安裝 SNMP,在 FreeBSD 透過 ports 安裝很方便,在指令模式輸入以下指令:

    # cd /usr/ports/net-mgmt/net-snmp
    # make install clean

    安裝完成後便要設定 SNMP,新增一個文字檔 /usr/local/share/snmp/snmpd.conf,加入以下內容:

    rocommunity mrtg

    以上設定的是 community name,是一個明碼字串,可視作為一個密碼。完成後在 /etc/rc.conf 加入以下一行:

    snmpd_enable=”YES”
    /usr/local/etc/rc.d/snmpd.sh start

    然後使用以上指令手動啟動 SNMP。

    安裝 MRTG
    安裝 MRTG 同樣使用 ports 來安裝:

    # cd /usr/ports/net-mgmt/mrtg
    # make install

    // 安裝後產生 MTRG 設定檔
    # cd /usr/local/etc/mrtg
    # rehash
    # cfgmaker mrtg@hostname >mrtg.cfg

    上面 cfgmaker mrtg@hostname >mrtg.cfg 的一行,mrtg 是在 snmp 設定的 community name,而 hostname 是主機的位置。

    然後開啟 /usr/local/etc/mrtg/mrtg.cfg,設定裡面的 WorkDIR 選項,改為想要儲存 mrtg 網頁的位置,例如 /home/httpd/mrtg。接著便建立 MRTG 的目錄及網頁:

    # mkdir /home/httpd/mrtg
    # indexmaker -title ‘Traffic Monitoring’ -output /home/httpd/mrtg/index.html mrtg.cfg
    # cd /usr/ports/net-mgmt/mrtg/work/mrtg*
    # cd images
    # cp * /home/httpd/mrtg/

    // 以上已經完成設定了,最後執行 MRTG:
    # /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg

    執行以上指令後會出現錯誤訊息,這是因為第一次執行 mrtg 的關係,沒有一些舊圖,只要再執行一次就行了。最後一步就是輸入 crontab -e 設定每 5 分鐘自動執行 mrtg:

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

    設定完成後,便可以用瀏覽器開啟 /home/httpd/mrtg 的相對網址查看。


     

    2 responses to “FreeBSD 安裝 MRTG 流量分析”

    1. 請問一下CentOS的安裝是方法一樣的嗎?

    2. 基本上分別不大,centos 用 yum 來安裝應該也不難,但設定檔的位置就不同了,以前裝過,但現在已不記得了。

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word