MRTG 快速安裝法 *

MRTG 主要是用來偵測主機上的資料流量,將流量繪製成漂亮的統計圖表。另外,我們也可以自行寫一些 SCRIPT,加掛於 MRTG 上,只要你提供給 MRTG 它兩個數值,它就可以做為流量的依據,幫我們產生統計圖表。

在偵測記憶體負載方面,本人已將緩衝區及快取所佔用的記憶體排除在外,這點可能有別於其它教學文章。因為 Linux 在執行上,並不會自動釋放這兩者所佔用的記憶體,如果併入計算,則在圖表上所看到的記憶體負載,將永遠居高不下。

以下的步驟是使用本人修改過的設定檔來啟用 mrtg,除了原來的網路流量,尚可偵測 CPU 負載、記憶體負載、網站線上人數、FTP 線上人數及 SSH 線上人數及 TELNET 線上人數,適用於 Redhat Linux 7.3。

安裝 ucd-snmp

  • 檢查系統是否已安裝 perl,zlib,gd,libpng,mrtg 這五個模組,沒有的話,請使用 Apt 安裝。
  • 因為系統預設安裝的 ucd-snmp 在執行上有問題,所以請移除 ucd-snmp 及相關套件:
  • apt-get remove ucd-snmp
  • 從本站下載 ucd-snmp 的原始檔至 /tmp,並解壓縮:
  • cd /tmp
    wget http://www.vixual.net/download/source/mrtg/ucd-snmp-4.2.5.tar.gz
    tar -zxvf ucd-snmp-4.2.5.tar.gz
  • 開始安裝 ucd-snmp:
  • cd ucd-snmp-4.2.5
    ./configure --prefix=/usr/local/snmp
    執行過程…
      .
      .
      .
     ************** Configuration Section **************
    
    You are about to be prompted with a series of questions. Answer
    them carefully, as they determine how the snmp agent and related
    applications are to function.
    
    After the configure script finishes, you can browse the newly
    created config.h file for further - less important - parameters to
    modify. Be careful if you re-run configure though, since config.h will
    be overwritten.
    
    -Press return to continue-
    Enter 繼續…
    disabling above prompt for future runs... yes
    checking System Contact Information...
    
    *** System Contact Information:
    
    Describes who should be contacted about the host the agent is
    running on. This information is available in the MIB-II tree. This
    can also be over-ridden using the "syscontact" syntax in the agent's
    configuration files.
    
    System Contact Information (root@):
    輸入 “root@localhost“, 然後按 Enter 繼續…
    setting System Contact Information to... root@localhost
    checking System Location...
    
    *** System Location:
    
    Describes the location of the system. This information is
    available in the MIB-II tree. this can also be over-ridden using the
    "syslocation" syntax in the agent's configuration files.
    
    System Location (Unknown):
    輸入 “RedHat 7.3“, 然後按 Enter 繼續…
    setting System Location to... RedHat 7.3
    checking Location to write logfile...
    
    *** Logfile location:
    
    Enter the default location for the snmpd agent to dump
    information & errors to. If not defined (enter the keyword "none"
    at the prompt below) the agent will use stdout and stderr instead.
    (Note: This value can be over-ridden using command line options.)
    
    Location to write logfile (/var/log/snmpd.log):
    Enter 繼續…
    setting Location to write logfile to... /var/log/snmpd.log
    checking Location to write persistent information...
    
    *** snmpd persistent storage location:
    
    Enter a directory for the snmp library to store persistent
    data in the form of a configuration file.
    
    Location to write persistent information (/var/ucd-snmp):
    Enter 繼續…
    setting Location to write persistent information to... /var/ucd-snmp
      .
      .
      .
  • 繼續編譯檔案:
  • make
    make install
  • 啟動 snmp:
  • /usr/local/snmp/sbin/snmpd
  • 要讓 snmp 在開機時啟動,請修改 /etc/rc.d/rc.local,加入:
  • /usr/local/snmp/sbin/snmpd

    安裝 mrtg

  • 從本站下載 mrtg 的原始檔至 [/var/www/html],並解壓縮:
  • cd /var/www/html
    wget http://www.vixual.net/download/source/mrtg/mrtg-2.9.17-tw.tgz
    tar -xzvf mrtg-2.9.17-tw.tgz
  • 執行一次下列指令,產生流量統計圖 (執行時會產生錯誤訊息,忽略即可):
  • /usr/bin/mrtg /var/www/html/mrtg/net/mrtg.cfg.net
    /usr/bin/mrtg /var/www/html/mrtg/cpu/mrtg.cfg.cpu
    /usr/bin/mrtg /var/www/html/mrtg/ram/mrtg.cfg.ram
    /usr/bin/mrtg /var/www/html/mrtg/www/mrtg.cfg.www
    /usr/bin/mrtg /var/www/html/mrtg/ftp/mrtg.cfg.ftp
    /usr/bin/mrtg /var/www/html/mrtg/ssh/mrtg.cfg.ssh
    /usr/bin/mrtg /var/www/html/mrtg/telnet/mrtg.cfg.telnet
  • 編輯 /etc/crontab,依需求建立下列指令:
  • #mrtg
    */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/net/mrtg.cfg.net > /dev/null 2>&1
    */3 * * * * root /usr/bin/mrtg /var/www/html/mrtg/cpu/mrtg.cfg.cpu > /dev/null 2>&1
    */3 * * * * root /usr/bin/mrtg /var/www/html/mrtg/ram/mrtg.cfg.ram > /dev/null 2>&1
    */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/www/mrtg.cfg.www > /dev/null 2>&1
    */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/ftp/mrtg.cfg.ftp > /dev/null 2>&1
    */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/ssh/mrtg.cfg.ssh > /dev/null 2>&1
    */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/telnet/mrtg.cfg.telnet > /dev/null 2>&1
  • 連上你的網址看流量統計: http://host.example.com/mrtg/index.html
    1. No comments yet.

    1. 02/12. 2011
      Trackback from : MRTG 快速安裝法

    return top

    %d 位部落客按了讚: