且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CentOS6.3环境下实战Linux开源流量监控软件Bandwidthd

更新时间:2022-04-09 03:58:13

bandwidthd在任何一台电脑可以通过web界面用浏览器查看经过网关的各个ip流量,而且是分协议,分颜色显示,已经有直观的图象曲线.

在日常维护中网管人员最头痛的是内部网经常有人在大量传送文件而导致本来可怜的带宽变得更加缓慢.如果在网关上装上bandwidthd ,就可以追踪的是各个的 IP 的流量,而且可以用图象曲线显示各个ip的相应不同协议显示,还能分时段查看
例如:包含FTPHTTPP2PTCPUDPICMP协议的各自流量,IP为统计对象.

CentOS6.3环境下实战Linux开源流量监控软件Bandwidthd

 

1、基本编译组件安装

[root@localhost ~]# yum install gcc cpp glibc glibc-devel gcc-c++

 

2.PCAP/PNG/GD Library(图像处理库)

[root@localhost ~]# yum install libpcap libpcap-devel libpng libpng-devel gd gd-devel

 

3、安装httpd

[root@localhost ~]# yum install httpd mod_ssl

[root@localhost ~]# service httpd start

[root@localhost ~]# chkconfig httpd on

 

4、下载bandwidthd

[root@localhost ~]#

wget http://jaist.dl.sourceforge.net/project/bandwidthd/bandwidthd/bandwidthd%202.0.1/bandwidthd-2.0.1.tgz

 

5、安裝bandwidthd

解压bandwidthd

[root@localhost ~]# tar -zxvf bandwidthd-2.0.1.tgz

编译

[root@localhost ~]#cd bandwidthd-2.0.1

[root@localhost bandwidthd-2.0.1]# ./configure

[root@localhost bandwidthd-2.0.1]# make;make install

 

[root@localhost ~]# ll /usr/local/bandwidthd

总用量 64

-rwxr-xr-x 1 root root 53320 3  19 15:15 bandwidthd   //启动bandwidthd文件

drwxr-xr-x 2 root root  4096 3  19 15:51 etc          //配置文件

drwxr-xr-x 2 root root  4096 3  19 15:25 htdocs       //web访问目录,可以作一个虚拟主机指过来

 

6、修改bandwidthd配置文件

[root@localhost ~]# vim /usr/local/bandwidthd/etc/bandwidthd.conf

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

# Bandwidthd.conf

#

# Commented out options are here to provide

# documentation and represent defaults

 

# Subnets to collect statistics on.  Traffic that

# matches none of these subnets will be ignored.

# Syntax is either IP Subnet Mask or CIDR

subnet 10.1.3.0 255.255.255.0       #设置监控的网段

#subnet 192.168.0.0/24

subnet 172.16.1.0/24

 

# Device to listen on

# Bandwidthd listens on the first device it detects

# by default.  Run "bandwidthd -l" for a list of

# devices.

dev "any"  #(这是你要检测的网卡ethxany(所有),可以调整为对应的网络连接设备)

 

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

# 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 1  #默认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

output_cdf true   #bandwidthd目录中生成log2.cdf  log.cdf格式数据记录

 

#Read back the cdf file on startup

recover_cdf true   #在启动bandwidth时重新读取cdf的数据

 

#Libpcap format filter string used to control what bandwidthd see's

#Please always include "ip" in the string to avoid strange problems

filter "ip"   #ip为过滤对象

 

#Draw Graphs – This default to true to graph the traffic bandwidthd is recording

#Usually set this to false if you only want cdf output or

#you are using the database output option.  Bandwidthd will use very little

#ram and cpu if this is set to false.

graph true    #图形生成

 

#Set META REFRESH seconds (default 150, use 0 to disable).

meta_refresh 150   #网页刷新时间

:wq               #保存

 

7、在web 主目录下做bandwidthd软连接,执行

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# ln -s /usr/local/bandwidthd/htdocs bandwidthd

 

8、启动bandwidthdhttpd

[root@localhost ~]#cd /usr/local/bandwidthd

[root@localname bandwidthd]#./bandwidthd

[root@localhost bandwidthd]# service httpd restart

 

9、设定开机自动启动 bandwidthd

[root@localhost ~]# vim /etc/rc.local

在最后添加内容:

#bandwidthd流量监控

/usr/local/bandwidthd/bandwidthd

 

11、过几分钟,就可以浏览bandwidthd 生成的图形报表

http://IP/bandwidthd

CentOS6.3环境下实战Linux开源流量监控软件Bandwidthd

 




本文转自 yhw85 51CTO博客,原文链接:http://blog.51cto.com/yanghuawu/1160334,如需转载请自行联系原作者