Freebsd下MRTG安装和配置全过程

系统 Linux
Freebsd下MRTG安装和配置全过程:MRTG是一个监控网络链路流量负载的工具软件,通过snmp协议得到设备的流量信息,并将流量负载以包含PNG格式的图形的HTML 文档方式显示给用户,本文讲述的是Freebsd下MRTG安装和配置全过程

  Freebsdmrtg安装和配置全过程

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

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

  1.   pub# cd /usr/ports/net-mgmt/net-snmp/  
  2.  
  3.   pub# make install clean  
  4.  
  5.   pub# rehash  
  6.  

  测试一下

  1.   pub# snmpd  
  2.  
  3.   pub# ps waux |grep snmpd  
  4.  
  5.   root 614 0.0 0.8 5612 4308 ?? S 12:45AM 0:00.23 snmpd  
  6.  

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

  接下来 就是PORTS 安装MRTG

  1.   pub# cd /usr/ports/net-mgmt/mrtg/  
  2.  
  3.   pub# make install && make clean  
  4.  
  5.   pub#rehash  
  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!

  Home: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/

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

  做完上面以后

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

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

  1.   pub# mkdir mrtg  
  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.owshine

  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

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

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

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

  pub# ee snmpd.conf

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

  #

  # EXAMPLE.conf:

  # An example configuration file for configuring the ucd-snmp snmpd ag

  #

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

  #

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

  ............................................

  找一下

  1.   # sec.name source community  
  2.  
  3.   com2sec local localhost COMMUNITY  
  4.  
  5.   com2sec mynetwork NETWORK/24 COMMUNITY  
  6.  
  7.   rocommunity owshine  
  8.  

  在这个地方添加 rocommunity owshine

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

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

  修改完配制记得重起SNMPD

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

  pub# cd /usr/local/etc/mrtg

  pub# cfgmaker owshine@192.168.1.28 > mrtg.owshine

  --base: Get Device Info on owshine@192.168.1.28:

  --base: Vendor Id:

  --base: Populating confcache

  --snpo: confcache owshine@192.168.1.28: Descr vr0 --> 1

  --snpo: confcache owshine@192.168.1.28: Descr lo0 --> 2

  --snpo: confcache owshine@192.168.1.28: Type 6 --> 1

  --snpo: confcache owshine@192.168.1.28: Type 24 --> 2

  --snpo: confcache owshine@192.168.1.28: Ip 127.0.0.1 --> 2

  --snpo: confcache owshine@192.168.1.28: Ip 192.168.1.28 --> 1

  --snpo: confcache owshine@192.168.1.28: Eth 00-05-5d-a1-b6-7d --> 1

  --snpo: confcache owshine@192.168.1.28: Eth --> 2

  --base: Get Interface Info

  --base: Walking ifIndex

  --base: Walking ifType

  --base: Walking ifAdminStatus

  --base: Walking ifOperStatus

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

  在这个地方有几点要注意, 一个是owshine@后面的 192.168.1.28 在很多时候尽量用IP地址来代替,当然假如是放在

  公网上面的机器是动态IP 就不得不使用域名,那也是没办法的事

  情,总之目的就是要获得要抓的网卡上面的流量,得要给MRTG

  知道是哪块网卡才行 ,所以一定要给它正确的地址 。

  还有一个就是前面owshine@中的owshine ,这个就是在前面

  snmpd.conf 建立的访问者拉 ,假如这个访问者不存在或者是

  写错 就会出现

  1.   pub# cfgmaker com2sec@192.168.1.28 > mrtg.owshine  
  2.  

  --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

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

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

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

  pub# cat mrtg.owshine

  # Created by

  # /usr/local/bin/cfgmaker owshine@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

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

  # System: pub.porwork.com.cn

  # Descrīption: FreeBSD pub.porwork.com.cn 4.11-STABLE FreeBSD 4.11-STABLE #5: Tue Apr i386

  # Contact: Me

  # Location: Right here, right now.

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

  ### Interface 1 >> Descr: 'vr0' | Name: '' | Ip: '192.168.1.28' | Eth: '00-05-5d-a1-b6-7d' ###

  Target[192.168.1.28_1]: 1:owshine@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]:

  Traffic Analysis for 1 -- pub.porwork.com.cn

  System: pub.porwork.com.cn in Right here, right now.

  Maintainer: Admin

  Descrīption: vr0

  ifType: ethernetCsmacd (6)

  ifName: owshine 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:owshine@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

  # Descrīption: 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

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

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

  显示出来

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

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

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

  4. 生成WEB 页面 index.html

  1.   indexmaker --title 'owshine net' -output /pub/site/mrtg/index.html mrtg.owshine  
  2.  

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

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

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

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

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

  5.运行 MRTG

  1.   pub# mrtg /usr/local/etc/mrtg/mrtg.owshine  
  2.  
  3.   Rateup WARNING: /usr/local/bin/rateup could not read the primary log file for 192.168.1.28_1  
  4.  
  5.   Rateup WARNING: /usr/local/bin/rateup The backup log file for 192.168.1.28_1 was invalid as well  
  6.  
  7.   Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file  
  8.  
  9.   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  
  10.  
  11.   pub# mrtg /usr/local/etc/mrtg/mrtg.owshine  
  12.  
  13.   Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file  
  14.  
  15.   pub# mrtg /usr/local/etc/mrtg/mrtg.owshine  
  16.  
  17.   pub# mrtg /usr/local/etc/mrtg/mrtg.owshine  
  18.  
  19.   pub# ls  
  20.  

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

  到这一步 应该是一个MRTG 该可以正常使用了http://www.owshine.com/mrtg

  就看到了令人惊奇的一面

  结尾:

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

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

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

  1.   # mrtg crontab  
  2.  
  3.   */5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.owshine  
  4.  

【编辑推荐】

MRTG安装配置

MRTG—网络监控工具

将MRTG做成系统服务

责任编辑:zhaolei 来源: CSDN
相关推荐

2011-03-31 10:26:51

安装MRTG

2011-02-22 10:46:02

Samba配置

2009-12-08 17:56:16

WCF配置

2011-04-01 09:18:03

FreeBSD安装MRTG

2011-01-21 17:51:52

2011-09-06 15:38:20

QT安装

2009-06-10 16:55:42

cygwin netb安装

2010-03-10 13:24:45

Zend Debugg

2011-03-11 10:39:02

YUM安装LAMP

2010-06-01 09:51:11

2010-05-13 16:15:21

MySQL5 mast

2010-03-30 10:11:53

CentOS源

2010-03-26 14:48:03

Ylmf OS 2.0

2010-11-19 09:30:29

2011-04-01 10:19:13

MrtgCISCO安装

2010-05-28 18:57:15

Mrtg配置

2009-06-09 16:17:45

SQL Server

2011-04-18 15:56:10

软件测试

2009-04-13 12:37:18

2009-12-02 13:02:20

Visual Stud
点赞
收藏

51CTO技术栈公众号