Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2068040
  • 博文数量: 178
  • 博客积分: 2076
  • 博客等级: 大尉
  • 技术积分: 2800
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-10 10:50
文章分类

全部博文(178)

文章存档

2010年(4)

2009年(13)

2008年(161)

我的朋友

分类: LINUX

2008-07-08 16:21:20

环境:
CENTOS5
用bandwidthd在任何一台电脑可以通过web界面用浏览器查看经过网关的各个ip流量,而且是分协议,分颜色显示,已经有直观的图象曲线.
在日常维护中, 网管人员最头痛的是内部网经常有人在大量传送文件而导致本来可怜的带宽变得更加狼狈.如果在网关上装上'bandwidthd' ,就可以追踪的是各个
的 IP 的流量,而且可以用图象曲线显示各个ip的相应不同协议显示,还能分时段查看
例如包含HTTP, TCP, UDP, ICMP, VPN 以及 P2P 协议的各自流量,以ip为统计对象.
 打了补丁还可以增加你想检测端口.
安装
1.YUM安装下面的库包即可。
# yum -y install libpcap*
# yum -y install libpng-devel*
# yum -y install libpng*
# yum -y install libgd*
2.下载:
bandwidthd原始网址如下:
文件: bandwidthd-2.0.1.gz
大小: 137KB
下载: 下载

下面是补丁,也可以不打。如果不打,直接看3。
-------------------------------------------
2.1.也下载一个补丁吧,这个补丁可以增加检测端口的,所以在这里还是先补了再安装.
在相关补丁(patchs)的连接里有这样一个补丁:
... 685&atid=591013
2.2. 安装
把bandwidthd-cp3-1.2.1b.patch放在bandwidthd-2.0.1目录同一级.
2.3 执行补丁: patch -p1 < ../bandwidthd-cp3-1.2.1b.patch
[root@mail bandwidthd-1.2.1b]# patch -p1 < ../bandwidthd-cp3-1.2.1b.patch
-------------------------------
3.安装
#tar -xvzf bandwidthd-2.0.1.gz
3.1
#cd bandwidthd-2.0.1
#./configure && make install
3.2 安装完成,默认安装在/usr/local/bandwidthd 下
4.配置bandwidthd.conf
很简单,一个配置文件搞定, 一般修改一下网段和掩码,其他的用默认值即可,如果你熟悉英文,就看看其他选项.大概如下
#vi /usr/local/bandwidthd/etc/bandwidthd.conf
####################################################
# Bandwidthd.conf
#
# Commented out options are here to provide
# documentation and represent defaults
# Subnets to collect statistics on
#subnet 10.0.0.0 255.0.0.0
#subnet 208.16.191.0 255.255.255.0
subnet 192.168.1.250/24 #以这个网段为例
# Device to listen on
dev "eth0" #(这是你要检测的网卡,可以调整为对应的网络连接设备)
把其中 subnet 的设定,以一网段为例:
subnet 192.168.1.0/24
###################################################
# Options that don't usually get changed
# An interval is 2.5 minutes, this is how many
# intervals to skip before doing a graphing run
#skip_intervals 0 #默间隔认2.5 minutes 刷新
# Graph cutoff is how many k must be transfered by an
# ip before we bother to graph it
#graph_cutoff 1024 #默间1M 以上的流量才有图形
#Put interface in promiscuous mode to score to traffic
#that may not be routing through the host machine.
#promiscuous true #让网卡在混杂模式中记录
#Log data to cdf file htdocs/log.cdf 在bandwidthd中生成log2.cdf log.cdf格式数据记录
output_cdf true
#Read back the cdf file on startup 在启动bandwidth时重新读取cdf的数据
recover_cdf true
#Libpcap format filter string used to control what bandwidthd see's
#Please always include "ip" in the string to avoid strange problems
#以ip为过滤对象
filter "ip"
#Draw Graphs
graph true
#以下是我打了补丁bandwidthd-cp3-1.2.1b.patch才有的,
# List of controled protocols
# format: item "item_name" rgb_color protocol ports 这是记录的格式:端口名字,RGB颜色,端口号
# obs.: The yellow (0xffff00) color is predefined to the "TOTAL" item 黄色预设为TOTAL的颜色
item "TCP" 0x00ff00 tcp all
item "HTTP" 0x0000ff tcp 80 443
item "FTP" 0xc0c0ff tcp 20 21
item "2P" 0xff00ff tcp 1044 1045 1214 4661 4661 4665 5190 5500 5501 5502 5503 6346 6347 6666 6667 7788 8888 8889 28864 288
65
item "UDP" 0x800000 udp all
item "ICMP" 0xff0000 icmp all
item "SMTP" 0xFF8C00 tcp 25
item "OP3" 0x00FFFF tcp 110
其中SMTP和POP3是为了更详细的数据流而增加上去的.你也可以增加你想检测的端口,这就是为何我推荐打这个补丁再安装的原因.
存盘之后,便可执行。
5. 运行 ,要先转到安装目录才能执行
#cd /usr/local/bandwidthd
#./bandwidthd
6. 显示:
在web 主目录下做个软连接,或者修改/etc/httpd/conf/httpd.con里的主目录路径为 /usr/local/bandwidthd/htdocs。
用 http://你的主机/就可以在浏览器里面检测你需要的流量了
备注:
另外,更多配置方法:
1. 把设定档中的 dev 增加更多的dev,或设成 any 可以监控更多设备
2. 如果认为TOP20太少了,
就在还没MAKE时候先改graph.c
graph.c中查找
for (Counter=0; Counter < 21 && Counter < NumIps; Counter++)
把21改成101
就变成TOP100
然后查找TOP20改为字符串TOP100
然后存盘,再make install 即可.
本bandwidthd进行网络流量检测和分析如果结合tc+iptables进行流量控制,是一个绝妙的组合. 这样你就可以随时检测和控制网内所有机器及端口的流量了.
关于tc+iptables可以参考
更多的bandwidthd可以参考:
 
阅读(364) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~