Chinaunix首页 | 论坛 | 博客
  • 博客访问: 486672
  • 博文数量: 100
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 995
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-22 15:44
文章分类

全部博文(100)

文章存档

2006年(90)

2005年(10)

我的朋友

分类: BSD

2006-01-11 07:45:52

FreeBsd下MRTG安装和配置全过程

作者:清心(Email: ) 转载请注明出处:

这篇是早早以前写下来的,用GOOGLE搜一下,发现被转贴了很多地方。所以把它依旧再放回来,测试下GOOGLE能否搜索到

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

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

pub# cd /usr/ports/net-mgmt/net-snmp/
pub# make install && make clean

pub# rehash

测试一下

pub# snmpd

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

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

接下来 就是PORTS 安装MRTG

pub# cd /usr/ports/net-mgmt/mrtg/

pub# make install && make clean

pub#rehash

测试一下

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:


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

做完上面以后

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

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

pub# mkdir mrtg

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

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

pub# cp snmpd.conf.example snmpd.conf

这样里面就有了 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

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

找一下

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

在这个地方添加 ocommunity prowork

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

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

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

pub# cd /usr/local/etc/mrtg

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

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

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

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

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

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

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

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

写错 就会出现

pub# cfgmaker > mrtg.prowork
--base: Get Device Info on :
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 ::::::v4only
at /usr/local/bin/cfgmaker line 796
WARNING: Skipping : as no info could be retrieved

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

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

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

pub# cat mrtg.prowork
# Created by
# /usr/local/bin/cfgmaker


### 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
# Description: 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: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]:

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



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

Maintainer: Admin <admin@prowork.com.cn>

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 <me@somewhere.org>

# 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

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

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

显示出来

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

ERROR: Line 8 ( WorkDir: /var/www/html/mrtg) in CFG file (mrtg)?does not make sense
这个一点都不假 ,不相信试试看

4. 生成WEB 页面 index.html

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

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

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

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



就看到了令人惊奇的一面

结尾:

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

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

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


# mrtg crontab

*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.prowork



到这里也就完全结束了。
阅读(1064) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~