MRTG (Multi Router Traffic Grapher)

Router 流量分析架設法(2.9.22版)

Copyright 2002 OLS3, 本講義僅供教育人員參考, 任何引用, 請先取得作者的同意.

Email: ols3@www.tnc.edu.tw

網站: http://teacher.mdjh.tnc.edu.tw/~ols3/ 臥龍小三的首頁

 

流量分析的用途:

架設前的注意事項:

架設步驟:

  1. 取得 MRTG 的軟體:目前(2002/09)最新版本 2.9.22

    ftp://ftp.tnc.edu.tw/pub/Sysop/MRTG/mrtg-2.9.22.tar.gz

    MRTG 作者的站台:

    http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html



  2. 解壓, 並進入解壓後的目錄中:

    tar xvzf mrtg-2.9.22.tar.gz

    cd mrtg-2.9.22

  3. 執行設定程式:

    ./configure

  4. 執行編譯及相關設定Perl路徑的動作:

    make

    make intall

    它會將 mrtg 安裝在 /usr/local/mrtg-2

    請將 mrtg 的一些基本圖檔 copy 至 /var/www/html/mrtg 中
    cp images/* /var/www/html/mrtg

  5. 製作 mrtg.cfg

    cd /usr/local/mrtg-2/bin

    cfgmaker public@163.26.197.254 > mrtg.cfg

    其中 @ 之後的 IP 即是貴校 router 的 IP, 記得將 163.26.197.254 換成貴校的.

    > mrtg.cfg 是說將輸出內容存成 mrtg.cfg 這個檔案.



  6. 修改 mrtg.cfg 設定檔:

    在 mrtg.cfg 的上方, 加入 WorkDir 這個關鍵字:

    vi mrtg.cfg

    加上 以下內容樣本, 使圖型向右增長, 且有中文訊息支援:

    ### Global Config Options
    # for UNIX

    WorkDir: /var/www/html/mrtg

    # or for NT
    # WorkDir: c:\mrtgdata

    ### Global Defaults
    # to get bits instead of bytes and graphs growing to the right

    Options[_]: growright, bits

    language: big5

  7. 開始執行 mrtg :

    ./mrtg mrtg.cfg

    第一次執行時, 可能會有很多 Warning 的訊息, 可以不必理會它, 無妨!

    此時, 您會在 /var/www/html/mrtg 中, 發現 mrtg 已幫您產生了許多流量分析的顯示圖表. 其中 163.26.197.254_1.html 是主要的顯示檔.

    163.26.197.254 是 router 的 IP, 1 是介面 port 號, 兩者合起來形成一個 label.

  8. 讓 mrtg 每五鐘執行一次:

    為了讓 mrtg 可以持續而完整的取得受測介面的資料, 通常我們會將 mrtg 設定成每五分鐘就執行一次, 這就要仰仗 cron daemon 了.

    a. 設定 root 的 crontab:

    crontab -u root -e

    它會帶您進入 vi 模式(您看! 把 vi 練好真的很重要吧?!)

    b. 填入以下內容:

    */5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/bin/mrtg.cfg

    然後存檔離開.

  9. 在 /var/www/html/mrtg 中產生 index.html 檔:

    cd /var/www/html/mrtg

    ln -s 163.26.197.254_1.html index.html

    往後只要用覽瀏器觀看 http://貴校網址/mrtg 就可以看到流量分析了.
    當然其它介面的流量分析檔(例如 163.26.197.254_2.html) 也有參考價值, 請自行在貴校網頁中加上連結位置吧.

 

 

疑難問題:

在架設過程中, 您可能會遇到以下情況:


loading for gcc... gcc

checking whether the c compiler (gcc) works... yes

checking whether the c compiler (gcc) is a cross-compiler... no

checking whether we are using GNN c... yes

checking whether gcc accepts -g...yes

checking how to run the preprocessor...gcc-E

checking make sets ${MAKE}... yes

checking per... /usr/bin/perl

checking gdImageGif in -Igd ... no

checking gdImagePng in -Igd ... no

**The GD libraryis required for rateup to compile....................



下 make 之後, 出現:

make:***NO targets. stop.



這表示您的 Server 中尚未安裝 GD Library. GD Library 在 RedHat 光碟片中便有, 請先用 rpm 指令安裝 GD, 之後再來架設 mrtg.

OLS3