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 位部落客按了赞: