感谢支持
我们一直在努力

Bandwidthd完整实战笔记

一、网络配置

网上很多Bandwidthd的实例,大多都是只有Bandwidthd的安装配置。对于刚刚做网络管理的朋友来说,基本用处不大。要用Bandwidthd做流量监控,首先得了解你自己的网络拓扑,选择一个合适的组网方式。

Bandwidthd完整实战笔记(PostgreSQL)_2  http://www.linuxidc.com/Linux/2013-11/92988.htm

例如我所管理的网络拓扑如下:

网络上接入设备较多,整个局域网上网是通过路由器做NAT上网的。那么如果采用Bandwidth进行监控,有以下2种方式组网。

方式一,在路由器和防火墙(或者是你的路由器和内网中间)加一个服务器(服务器需要3块网卡)

 

方式二,如果你的核心交换机支持端口镜像,那么可以将Bandwidthd做为旁路进行分析

 

在这里,我选择了第2种方案,比较服务器做为网关,不是很稳定。万一服务器死了,整个网络就瘫痪了。

如果,选择方式二,你的核心交换机就需要支持端口镜像。

下面简单介绍一下我的设备清单:

路由器:H3C SR6604

防火墙:H3C SecBlade FW防火墙

核心交换机:H3C7506、H3C7503、华为S6506、华为5700

 

具体操作:

将H3C7506连接SR6604路由器的光口镜像到H3C7506连接Bandwidthd服务器的口上。

例如,在光口上做镜像,将流量从G8/0/1镜像到G8/0/12口上

interface GigabitEthernet8/0/1
port access vlan 3990
speed 1000
duplex full
mirroring-group 1 mirroring-port both

#

 

interface GigabitEthernet8/0/12
description mirror
speed 1000
duplex full
mirroring-group 1 monitor-port

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-11/92934p2.htm

相关阅读

CentOS 6.4环境下编译安装Bandwidthd和PostgreSQL心得笔记   http://www.linuxidc.com/Linux/2013-11/92932.htm

CentOS 6.3环境下实战Linux开源流量监控软件Bandwidthd  http://www.linuxidc.com/Linux/2013-03/81472.htm

Ubuntu下编译安装Bandwidthd和postgresql,将数据存入pgsql  http://www.linuxidc.com/Linux/2010-09/28440.htm

Ubuntu下安装Bandwidthd-pgsql  http://www.linuxidc.com/Linux/2010-09/28439.htm

二、Bandwidthd服务器安装配置

(1)首先安装CentOS 6.4,从http://mirrors.163.com/ 网易的开源镜像站点,很快就可以下载了。推荐下载http://mirrors.163.com/centos/6.4/isos/x86_64/CentOS-6.4-x86_64-minimal.iso这个minimal的版本,300M左右。

(2)服务器需要2块网卡

eth0配置为管理地址,eth1网卡不需要配置IP,直接插到交换机的镜像口上。

(3)安装Bandwidthd支持软件包

yum install gcc cpp glibc glibc-devel gcc-c++


 

yum install libpcap libpcap-devel libpng libpng-devel gd gd-devel


 

yum install httpd mod_ssl


service httpd start


chkconfig httpd on

安装wget下载工具

yum install wget

 

(4)下载Bandwidthd代码

官网地址:http://bandwidthd.sourceforge.net/

下载地址:http://nchc.dl.sourceforge.net/project/bandwidthd/bandwidthd/bandwidthd%202.0.1/bandwidthd-2.0.1.tgz

用wget下载:

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

 

tar -zxvf bandwidthd-2.0.1.tgz

 

解压缩完毕后,就准备编译安装了

cd bandwidthd-2.0.1

./configure

[root@localhost bandwidthd-2.0.1]#  ./configure
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking for bison… no
checking for byacc… no
checking for gcc… gcc
checking for C compiler default output… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for executable suffix…
checking for object suffix… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for a BSD compatible install… /usr/bin/install -c
checking for flex… no
checking for lex… no
checking for yywrap in -lfl… no
checking for yywrap in -ll… no
checking how to run the C preprocessor… gcc -E
checking for X… no
checking for /sw/lib… no
checking for /sw/include… no
checking for /usr/pkg/lib… no
checking for /usr/pkg/include… no
checking for connect in -lsocket… no
checking for gethostbyname in -lnsl… yes
checking for inet_aton in -lresolv… yes
checking for pow in -lm… yes
checking for libiconv_open in -liconv… no
checking for png_read_info in -lpng… yes
checking for gdImageCreate in -lgd… yes
checking for pcap_open_live in -lpcap… yes
checking for /usr/local/pgsql/lib… no
checking for /usr/local/pgsql/include… no
checking for PQconnectdb in -lpq… no
checking for dirent.h that defines DIR… yes
checking for opendir in -ldir… no
checking for gd.h… yes
checking for gdfonts.h… yes
checking for pcap.h… yes
checking for arpa/inet.h… yes
checking for errno.h… yes
checking for netdb.h… yes
checking for netinet/in.h… yes
checking for stddef.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for sys/socket.h… yes
checking for sys/time.h… yes
checking for sys/wait.h… yes
checking for syslog.h… yes
checking for unistd.h… yes
checking for arpa/nameser.h… yes
checking for resolv.h… yes
checking for gcc option to accept ANSI C… none needed
checking for an ANSI C-conforming const… yes
checking for inline… inline
checking for ANSI C header files… yes
checking for stdlib.h… (cached) yes
checking for string.h… (cached) yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for unistd.h… (cached) yes
checking for pid_t… yes
checking for size_t… yes
checking whether struct tm is in sys/time.h or time.h… time.h
checking for struct tcphdr.source… yes
checking for struct tcphdr.th_sport… no
checking for struct tcphdr.dest… yes
checking for struct tcphdr.th_dport… no
checking for stdlib.h… (cached) yes
checking for working malloc… yes
checking for ANSI C header files… (cached) yes
checking whether time.h and sys/time.h may both be included… yes
checking for sys/time.h… (cached) yes
checking for unistd.h… (cached) yes
checking for alarm… yes
checking for working mktime… no
checking return type of signal handlers… void
checking whether lstat dereferences a symlink specified with a trailing slash… yes
checking whether stat accepts an empty string… no
checking for alarm… (cached) yes
checking for gethostbyaddr… yes
checking for inet_ntoa… yes
checking for memset… yes
checking for strdup… yes
checking for strftime… yes
checking for pcap_findalldevs… yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h

由于最小系统的CentOS不带make,因此需要自己安装一个make
yum install make

 

安装完毕后,就可以make了

make

 

make install

检查哈有没有安装成功了

ls /usr/local/bandwidthd/

 

将Bandwidthd分析出的网页统计页面链接到httpd 程序下

在CentOS 6.4下,httpd 网页根目录默认是/var/www/html

在web 主目录下做bandwidthd软连接

ln -s /usr/local/bandwidthd/htdocs /var/www/html/bandwidthd

 

配置Bandwidthd的配置文件

vi /usr/local/bandwidthd/etc/bandwidthd.conf

加入你要监控的网段

subnet 10.0.0.0 255.255.0.0
subnet 10.1.0.0 255.255.0.0
subnet 10.2.0.0 255.255.0.0
subnet 10.3.0.0 255.255.0.0
subnet 10.4.0.0 255.255.0.0
subnet 10.5.0.0 255.255.0.0
subnet 192.168.0.0/16
subnet 172.16.25.0/24
subnet 172.16.10.0/24
subnet 172.16.11.0/24
subnet 172.16.12.0/24
subnet 172.16.13.0/24
subnet 172.16.14.0/24
subnet 172.16.15.0/24
subnet 172.16.16.0/24
subnet 172.16.17.0/24
subnet 172.16.18.0/24
subnet 172.16.19.0/24
subnet 172.16.20.0/24
subnet 172.16.31.0/24
subnet 172.16.32.0/24
subnet 172.16.33.0/24
subnet 172.16.34.0/24
subnet 172.16.35.0/24
subnet 172.16.36.0/24

 

启动bandwidthd、httpd
[root@localhost ~]#cd /usr/local/bandwidthd
[root@localname bandwidthd]#./bandwidthd
[root@localhost bandwidthd]# service httpd restart

 

稍微等几分钟(5分钟吧),就可以看到流量页面了。

三、小结

通过交换机、服务器、Bandwidthd的有机配合,可以对全网进行监控。后面我将为大家介绍将Bandwidthd的流量监控信息存储到数据库中,例如MySQL

 

四、完善

最后在安装以下软件包

yum install ntp
ntpdate ntp.fudan.edu.cn
yum install setuptool ntsysv system-config-firewall

把服务器自动对对时间,安装一些方便管理的工具,把httpd 设置为自动启动,然后再把防火墙彻底关闭

 

让bandwidthd可以自动启动

vi /etc/rc.local

加入/usr/local/bandwidthd/bandwidthd

 

修改配置bandwidthd

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.  Traffic that
# matches none of these subnets will be ignored.
# Syntax is either IP Subnet Mask or CIDR
#subnet 10.0.0.0 255.0.0.0
#subnet 192.168.0.0/16
#subnet 172.16.0.0/12

subnet 10.0.0.0 255.255.0.0
subnet 10.1.0.0 255.255.0.0
subnet 10.2.0.0 255.255.0.0
subnet 10.3.0.0 255.255.0.0
subnet 10.4.0.0 255.255.0.0
subnet 10.5.0.0 255.255.0.0
subnet 192.168.0.0/16
subnet 172.16.25.0/24
subnet 172.16.10.0/24
subnet 172.16.11.0/24
subnet 172.16.12.0/24
subnet 172.16.13.0/24
subnet 172.16.14.0/24
subnet 172.16.15.0/24
subnet 172.16.16.0/24
subnet 172.16.17.0/24
subnet 172.16.18.0/24
subnet 172.16.19.0/24
subnet 172.16.20.0/24
subnet 172.16.31.0/24
subnet 172.16.32.0/24
subnet 172.16.33.0/24
subnet 172.16.34.0/24
subnet 172.16.35.0/24
subnet 172.16.36.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 “eth1”

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

# Graph cutoff is how many k must be transfered by an
# ip before we bother to graph it
graph_cutoff 1024

#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

#Read back the cdf file on startup
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
filter “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

reboot 重启服务器后,用 ps -aux 查看进程

可以看到bandwidthd和httpd 已经自动启动了。

 

至此!全部成功了。

赞(0) 打赏
转载请注明出处:服务器评测 » Bandwidthd完整实战笔记
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏