| 又一篇教学档 我的原创,分享给大家,觉得好的就顶一下啦,以便更多的人共同探索,发现问题,解决问题,总结问题.谢谢
在流量统计软件中有MRTG,NTOP,BANDWIDTHD等多种, MRTG 只是显示某一网络接口的总量, NTOP详细得来也很占系统资源. 但不知道大家用过bandwidthd没有,我就很喜欢它,因为它精简,直观.很容易配置. 好处:在任何一台电脑可以通过web界面用浏览器查看经过网关的各个ip流量,而且是分协议,分颜色显示, 已经有直观的图象曲线. 在日常维护中, 网管人员最头痛的是内部网经常有人在大量传送文件而导致本来可怜的带宽变得更加狼狈 .如果在网关上装上'bandwidthd' ,就可以追踪的是各个的 IP 的流量,而且可以用图象曲线显示各个ip 的相应不同协议显示,还能分时段查看 例如包含HTTP, TCP, UDP, ICMP, VPN 以及 P2P 协议的各自流量,以ip为统计对象. 默认的颜色,TCP为绿色;HTTP为蓝色;FTP为浅蓝;P2P为粉红;UDP为棕褐色; ICMP为红色 . 打了补丁还可以 增加你想检测端口. 例子: http://bandwidthd.sourceforge.net/demo/ 安装 bandwidthd 很简单. 1.条件:要先安装有以下库: 如果没有请到相关网址下载: libpcap 相关网址 http://www.tcpdump.org/ libpng相关网址(http://www.libpng.org/ gd相关网址 http://www.boutell.com/gd/ 系统须有支持 System V IPC (基本上Linux都有) RedHat 9.0 自带的rpm包也可以,要装有下面的包: gd-1.8.4-4 gd-devel-1.8.4-4 libpng-1.2.2-16 libpng-devel-1.2.2-16 libpcap-0.7.2-1 分别执行 rpm -ivh 软件包 进安装即可. 2.下载: bandwidthd原始网址如下: http://bandwidthd.sourceforge.net/ 里面有下载地址的连接,目前最新的版本是 bandwidthd 2.0.1 下载bandwidthd-1.2.1b.tgz 放在/home/中(这个目录是我的习惯而已).
3. 安装
3.1 tar -xvzf bandwidthd-2.0.1.tgz 显示: [root@mail bandwidthd]# tar zxvf bandwidthd-2.0.1.tgz bandwidthd-1.2.1b/ bandwidthd-1.2.1b/etc/ bandwidthd-1.2.1b/etc/bandwidthd.conf bandwidthd-1.2.1b/CHANGELOG bandwidthd-1.2.1b/Makefile bandwidthd-1.2.1b/Makefile.BSD bandwidthd-1.2.1b/Makefile.Solaris bandwidthd-1.2.1b/README bandwidthd-1.2.1b/TODO bandwidthd-1.2.1b/bandwidthd-0.4.kdevprj bandwidthd-1.2.1b/bandwidthd.c bandwidthd-1.2.1b/bandwidthd.h bandwidthd-1.2.1b/conf.l bandwidthd-1.2.1b/conf.y bandwidthd-1.2.1b/graph.c bandwidthd-1.2.1b/htdocs/ bandwidthd-1.2.1b/htdocs/index.html bandwidthd-1.2.1b/htdocs/legend.gif bandwidthd-1.2.1b/htdocs/logo.gif bandwidthd-1.2.1b/htdocs/index2.html bandwidthd-1.2.1b/htdocs/index3.html bandwidthd-1.2.1b/htdocs/index4.html bandwidthd-1.2.1b/conf.tab.c bandwidthd-1.2.1b/conf.tab.h bandwidthd-1.2.1b/conf.l.c
3.2 cd bandwidthd-2.0.1
3.3 执行 ./configure && make install 显示: [root@mail bandwidthd-1.2.1b]# make install cc -I/usr/local/include -O3 -Wall -c -o bandwidthd.o bandwidthd.c cc -I/usr/local/include -O3 -Wall -c -o graph.o graph.c bison -d conf.y cc -I/usr/local/include -O3 -Wall -c -o conf.tab.o conf.tab.c lex -s -i -t -I conf.l > conf.l.c cc -O3 -c -o conf.l.o conf.l.c cc -I/usr/local/include -O3 -Wall -c -o tables.o tables.c cc -I/usr/local/include -O3 -Wall bandwidthd.o graph.o conf.tab.o conf.l.o tables.o -o bandwidthd -L/usr/local/lib -lgd -lpng -lpcap if [ ! -d /usr/local/bandwidthd/etc ] ; then mkdir -p /usr/local/bandwidthd/etc ; fi if [ ! -d /usr/local/bandwidthd/htdocs ] ; then mkdir -p /usr/local/bandwidthd/htdocs ; fi cp bandwidthd /usr/local/bandwidthd if [ ! -f /usr/local/bandwidthd/etc/bandwidthd.conf ] ; then cp etc/bandwidthd.conf /usr/local/bandwidthd/etc/ ; fi cp htdocs/legend.gif /usr/local/bandwidthd/htdocs/ cp htdocs/logo.gif /usr/local/bandwidthd/htdocs/ 3.5 至此即已安装完成,它会将 bandwidthd 安装 至 /usr/local/bandwidthd 下 4. 设定,配置bandwidthd.conf bandwidthd 的设定也很简单,一个配置文件搞定, 一般修改一下网段和掩码,其他的用默认值即可,如果你熟悉英文,就看看其他选项.大概如下 编辑: /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 255.255.255.0 #以一网段为例 # Device to listen on dev "eth0" #(这是你要检测的网卡,可以调整为对应的网络连接设备) 把其中 subnet 的设定,以一网段为例: subnet 192.168.1.0 255.255.255.0 ################################################### # 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 存盘之后,便可执行。
5. 运行 ,要先转到安装目录才能执行 cd /usr/local/bandwidthd ./bandwidthd
6. 显示: 在web 主目录下做个软连接,执行 ln -s /usr/local/bandwidthd/htdocs bandwidthd 接着您便可用 http://你的主机/bandwidthd PS:web主目录,如果使用linux9.0默认apache设置,则在/var/www/html下;DocumenRoot在/etc/httpd/conf/httpd.conf下查看 这样就可以在浏览器里面检测你需要的流量了 另外,更多配置方法: 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的开发者,如果觉得有更好的配置和 使用方法,请互相交流. 本bandwidthd进行网络流量检测和分析如果结合tc+iptables进行流量控制,是一个绝妙的组合. 这样你就可以随时检测和控制网内所有机器及端口的流量了.
关于tc+iptables可以参考http://bbs.chinaunix.net/forum/viewtopic.php?t=482589 更多的bandwidthd可以参考: http://free.tnc.edu.tw/modules/news/article.php?storyid=710
|