FreeBsd下安装和配置MRTG

FreeBsd下安装和配置MRTG:MRTG是什么?MRTG(Multi Router Traffi
首页 新闻资讯 行业资讯 FreeBsd下安装和配置MRTG

  FreeBsdMRTG安装和配置全过程

  由于MRTG 不象APACHE 那么庞大, 精密。所以决定用PORTS 安装。

  首先要安装的是SNMP ,因为MRTG就是通过SNMP 监视流量来制作成可视化图表

复制

  pub# cd /usr/ports/net-mgmt/net-snmp/     pub# make install && make clean     pub# rehash
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  测试一下

复制

  pub# snmpd     pub# ps waux |grep snmpd     root 614 0.0 0.8 5612 4308 ?? S 12:45AM 0:00.23 snmpd
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  这一步好了,假如系统和PORTS TREE 本身没问题 ,这一步也应该没问题

  接下来 就是PORTS 安装MRTG

复制

  pub# cd /usr/ports/net-mgmt/mrtg/     pub# make install && make clean     pub#rehash
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  测试一下

复制

  pub# mrtg     Usage: mrtg     mrtg-2.11.1 is the Multi Router Traffic Grapher.     If you want to know more about this tool, you might want     to read the docs. They came together with mrtg!
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  看到这个就应该是没问题了

  做完上面以后

  最后就是配置工作 使MRTG 能为我们工作 ,这个是最“复杂”的一步 , 其实前面安装也挺复杂的,只是借助了PORTS 才会觉得“简单” 有机会可以全部编译安装试一下 以求深入理解MRTG && snmp

  1. 在WEB 发布目录/pub/site 建立一mrtg 目录,为的是能把生成的图表发布在浏览器里面

复制

  pub# mkdir mrtg
  • 1.

  • 2.

  2. 编辑 snmpd.conf 文件在里面添加访问用户 ,以求能顺利获得snmp上面的流量信息 ,这一步一定要做 ,而且好象在freebsd 和red hat下面它们的信息不太一样 ,也许是版本不一样导致 ,我就是吃了闷亏 ,以为都是一样 ,结果耗费了很长时间

复制

  pub# cd /usr/local/share/snmp/     pub# ls     mib2c-data mib2c.iterate_access.conf     mib2c.access_functions.conf mib2c.mfd.conf     mib2c.array-user.conf mib2c.notify.conf     mib2c.check_values.conf mib2c.old-api.conf     mib2c.check_values_local.conf mib2c.scalar.conf     mib2c.column_defines.conf mibs     mib2c.column_enums.conf mrtg.prowork     mib2c.column_storage.conf snmp_perl.pl     mib2c.conf snmp_perl_trapd.pl     mib2c.create-dataset.conf snmpconf-data     mib2c.genhtml.conf snmpd.conf.example     mib2c.int_watch.conf mib2c.iterate.conf
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  看一下里面有个 snmpd.conf.example , copy 一下

复制

  pub# cp snmpd.conf.example snmpd.conf
  • 1.

  • 2.

  这样里面就有了 snmpd.conf 的配置文件了

复制

  pub# ee snmpd.conf
  • 1.

  • 2.

  #######################################################################

  #

复制

  # EXAMPLE.conf:     # An example configuration file for configuring the ucd-snmp snmpd ag
  • 1.

  • 2.

  • 3.

  • 4.

  #

  #######################################################################

  #

复制

  # This file is intended to only be an example. If, however, you want
  • 1.

  • 2.

  找一下

复制

  # sec.name source community     com2sec local localhost COMMUNITY     com2sec mynetwork NETWORK/24 COMMUNITY     rocommunity prowork
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  在这个地方添加 ocommunity prowork

  添加在这里比较容易记忆 ,方便以后查找 ,它也可以放在其它的地方 ,注意不要在前面加 # ^_^ ,其中的prowork 就是等会我们要使用的访问名字 ,

  这一步和别的朋友写的文档上面有点不太一样 , 注意多点没坏处

  2. 生成 mrtg 配置文件 ,用于初始化,获取 snmp 信息

复制

  pub# cd /usr/local/etc/mrtg     pub# cfgmaker prowork@192.168.1.28 > mrtg.prowork     --base: Get Device Info on prowork@192.168.1.28:     --base: Vendor Id:     --base: Populating confcache     --snpo: confcache prowork@192.168.1.28: Descr vr0 --> 1     --snpo: confcache prowork@192.168.1.28: Descr lo0 --> 2     --snpo: confcache prowork@192.168.1.28: Type 6 --> 1     --snpo: confcache prowork@192.168.1.28: Type 24 --> 2     --snpo: confcache prowork@192.168.1.28: Ip 127.0.0.1 --> 2     --snpo: confcache prowork@192.168.1.28: Ip 192.168.1.28 --> 1     --snpo: confcache prowork@192.168.1.28: Eth 00-05-5d-a1-b6-7d --> 1     --snpo: confcache prowork@192.168.1.28: Eth --> 2     --base: Get Interface Info     --base: Walking ifIndex     --base: Walking ifType     --base: Walking ifAdminStatus     --base: Walking ifOperStatus
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  • 29.

  • 30.

  • 31.

  • 32.

  • 33.

  • 34.

  • 35.

  • 36.

  出现以上信息就证明通过了

  在这个地方有几点要注意, 一个是prowork@后面的 192.168.1.28 在很多时候尽量用IP地址来代替,当然假如是放在公网上面的机器是动态IP 就不得不使用域名,那也是没办法的事情,总之目的就是要获得要抓的网卡上面的流量,得要给MRTG知道是哪块网卡才行 ,所以一定要给它正确的地址 。

  还有一个就是前面prowork@中的prowork ,这个就是在前面snmpd.conf 建立的访问者拉 ,假如这个访问者不存在或者是写错 就会出现

复制

  pub# cfgmaker com2sec@192.168.1.28 > mrtg.prowork     --base: Get Device Info on com2sec@192.168.1.28:     SNMP Error:     no response received     SNMPv1_Session (remote host: "192.168.1.28" [192.168.1.28].161)     community: "com2sec"     request ID: 1181035357     PDU bufsize: 8000 bytes     timeout: 2s     retries: 5     backoff: 1)     at /usr/local/lib/perl5/site_perl/5.005/SNMP_util.pm line 627     SNMPWALK Problem for 1.3.6.1.2.1.1 on com2sec@192.168.1.28::::::v4only     at /usr/local/bin/cfgmaker line 796     WARNING: Skipping com2sec@192.168.1.28: as no info could be retrieved
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  • 29.

  • 30.

  这个上面的信息就是我错误理解snmpd.conf 导致出错的信息

  3 .在正确生成 mrtg.prowork的配置文件后就该修改修改里面的

  内容以求能符合自己的习惯 ,

复制

  pub# cat mrtg.prowork     # Created by     # /usr/local/bin/cfgmaker prowork@192.168.1.28     ### Global Config Options     # for UNIX     #这是设定要存放MRTG的信息发布页面的路径 ,也就是存放能     #打开页面看流量信息页面的那个地方     WorkDir: /pub/site/mrtg/     # or for NT     # WorkDir: c:\mrtgdata     ### Global Defaults     # to get bits instead of bytes and graphs growing to the right     # Options[_]: growright, bits     EnableIPv6: no
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  ######################################################################

复制

  # System: pub.porwork.com.cn     # Description: FreeBSD pub.porwork.com.cn 4.11-STABLE FreeBSD 4.11-STABLE #5: Tue Apr i386     # Contact: Me     # Location: Right here, right now.
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  ######################################################################

 

复制

 ### Interface 1 >> Descr: 'vr0' | Name: '' | Ip: '192.168.1.28' | Eth: '00-05-5d-a1-b6-7d' ###     Target[192.168.1.28_1]: 1:prowork@192.168.1.28:     SetEnv[192.168.1.28_1]: MRTG_INT_IP="192.168.1.28" MRTG_INT_DESCR="vr0"    MaxBytes[192.168.1.28_1]: 1250000     Title[192.168.1.28_1]: Traffic Analysis for 1 -- pub.porwork.com.cn     PageTop[192.168.1.28_1]:     System: pub.porwork.com.cn in Right here, right now.     Maintainer: Admin      Description: vr0     ifType: ethernetCsmacd (6)     ifName: prowork nic     Max Speed: 1250.0 kBytes/s     Ip: 192.168.1.28 (pub.porwork.com.cn)     ### Interface 2 >> Descr: 'lo0' | Name: '' | Ip: '127.0.0.1' | Eth: '' ###     ### The following interface is commented out because:     ### * it is a Software Loopback interface     ### * has a speed of 0 which makes no sense     #     # Target[192.168.1.28_2]: 2:prowork@192.168.1.28:     # SetEnv[192.168.1.28_2]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo0"    # MaxBytes[192.168.1.28_2]: 0     # Title[192.168.1.28_2]: Traffic Analysis for 2 -- pub.porwork.com.cn     # PageTop[192.168.1.28_2]:     Traffic Analysis for 2 -- pub.porwork.com.cn     #     # System: pub.porwork.com.cn in Right here, right now.     # Maintainer: Me      # Description: lo0     # ifType: softwareLoopback (24)     # ifName:     # Max Speed: 0.0 Bytes/s     # Ip: 127.0.0.1 (localhost.porwork.com.cn)     #     Options[_]: growright, bits     Language:gb2312     WithPeak[_]: wmy
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  • 29.

  • 30.

  • 31.

  • 32.

  • 33.

  • 34.

  • 35.

  • 36.

  • 37.

  • 38.

  • 39.

  • 40.

  • 41.

  • 42.

  • 43.

  • 44.

  • 45.

  • 46.

  • 47.

  • 48.

  • 49.

  • 50.

  • 51.

  • 52.

  • 53.

  • 54.

  • 55.

  • 56.

  • 57.

  • 58.

  • 59.

  • 60.

  • 61.

  • 62.

  • 63.

  • 64.

  • 65.

  • 66.

  • 67.

  • 68.

  • 69.

  • 70.

  • 71.

  • 72.

  蓝色为修改的地方 红色为添加的地方,这里面的内容不是很难

  可以修改让它符合自己的习惯因为里面有些 等会会在WEB页面

  显示出来

  注意的是任何指令左侧 都不要有空格出现 否则会提示 :

复制

  ERROR: Line 8 ( WorkDir: /var/www/html/mrtg) in CFG file (mrtg)does not make sense
  • 1.

  • 2.

  这个一点都不假 ,不相信试试看

  4. 生成WEB 页面 index.html

复制

  indexmaker --title 'prowork net' -output /pub/site/mrtg/index.html mrtg.prowork
  • 1.

  • 2.

  --title 为 index.html 的标题 /pub/site/mrtg/为发布页面的

  绝对路径 mrtg.prowork 为配置文件

  这时候应该在 /pub/site/mrtg/里面生成了一个配置页面

  打开看的时候 ,应该是看到有 几个红叉叉的页面 并没有预想

  的那样 ,原因是差了最后一步 :运行MRTG

  5.运行 MRTG

复制

  pub# mrtg /usr/local/etc/mrtg/mrtg.prowork     Rateup WARNING: /usr/local/bin/rateup could not read the primary log file for 192.168.1.28_1     Rateup WARNING: /usr/local/bin/rateup The backup log file for 192.168.1.28_1 was invalid as well     Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file     Rateup WARNING: /usr/local/bin/rateup Can't rename 192.168.1.28_1.log to 192.168.1.28_1.old updating log file     pub# mrtg /usr/local/etc/mrtg/mrtg.prowork     Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file     pub# mrtg /usr/local/etc/mrtg/mrtg.prowork     pub# mrtg /usr/local/etc/mrtg/mrtg.prowork     pub# ls
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  果然不假 ,真如别的朋友上面写的一样会“抱怨”三次

  到这一步 应该是一个MRTG 该可以正常使用了

  就看到了令人惊奇的一面

  结尾:

  排程 ,因为流量是不住变化的所以每隔一段时间就要去探测

  一次 , 时间长了 精确度不够 ,时间短 频繁去探测 ,又会

  加重系统负担 , 别人告诉我 ,一般是 5-10分钟 最佳

复制

  # mrtg crontab     */5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.prowork
  • 1.

  • 2.

  • 3.

  • 4.

  到这里也就完全结束了。

【编辑推荐】

如何在FreeBSD下用MRTG监测网路流量

MRTG的网络流量监测研究与应用(应用篇)

用MRTG监测交换机端口流量(图)

10    2011-03-31 10:26:51    安装 MRTG