Bandwidthd完整實戰筆記_1

Bandwidthd完整實戰筆記

本系列文章由ex_net(張建波、樑輝)編寫,轉載請註明出處。


http://blog.csdn.net/zjianbo/article/details/15026111


作者:張建波 郵箱: [email protected] 電話:13577062679 歡迎來電交流!


一、網絡配置

       網上很多Bandwidthd的實例,大多都是隻有Bandwidthd的安裝配置。對於剛剛做網絡管理的朋友來說,基本用處不大。要用Bandwidthd做流量監控,首先得了解你自己的網絡拓撲,選擇一個合適的組網方式。

       例如我所管理的網絡拓撲如下:


網絡上接入設備較多,整個局域網上網是通過路由器做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


二、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 已經自動啓動了。


至此!全部成功了。你可以去喝喝茶,玩會再來看看。。。


發佈了271 篇原創文章 · 獲贊 367 · 訪問量 104萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章