Bandwidthd完整实战笔记(Postgresql)_2
本系列文章由ex_net(张建波、梁辉)编写,转载请注明出处。
http://www.jb51.cc/article/p-kfppskmd-bkr.html
作者:张建波 邮箱:281451020@qq.com电话:13577062679 欢迎来电交流!
前言
做过网管的朋友,相信都会有这么一个感觉,经常听到同事、领导的抱怨,网速慢!可是,单位又愿意投资购买流控、行为管理这些设备。毕竟,流控、行为管理这些设备都在10多万1台。一提钱,领导就会说,想想办法,,,,!哎。无语!
网速慢,真是个纠结的办法,在学校网路中心待的几年中,也逐步摸索出了一些经验。慢慢的整理出来与大伙交流。上一篇已经简单介绍了在CentOS下,安装Bandwidthd的方法,经过几天的实践,发现效果不好。分析的原因是,交换机镜像口把流量给Bandwidthd时,只有单边流量,因此造成了数据不准确。因此,在上次的办法上,进行了改进。
一、系统方案介绍
说明:
(1)服务器选用有3块网卡的服务器,例如我用的服务器HP380G6,它有4块网卡,刚刚好。
(2)将eth1 和eth2组合成“透明网桥”,这样的话,就算服务器坏了,你也可以很快的把线路修复好,而且不需要修改路由器或交换机的配置。
二、服务器系统安装步骤简要说明
(1)安装Ubuntu 13系统(至于安装那个版本,全看你的服务器了,经过试验HP380G6只有安装Ubuntu13才行,安装12.04的版本,Raid比较麻烦,阵列识别不是太好)
(2)系统安装完毕后安装网桥组件
sudo apt-get install bridge-utils
(3)配置网桥
ifconfig em2 0.0.0.0 ifconfig em3 0.0.0.0 brctl addbr bg1 brctl addif bg1 em2 brctl addif bg1 em3 ifconfig bg1 up
bg1就是配置的网桥的名称
(4)测试网桥
将服务器接入网络试试,看看内网能否正常上网。理论上,只要网卡不要插错了。99.999999%是可以正常了,毕竟相当简单了
apt-get install postgresql #安装数据库 apt-get install apache2 #安装apache apt-get install PHP5 #安装PHP语言支持 apt-get install PHP5-pgsql #支持PHP语言连接postgresql数据库 apt-get install PHP5-gd #支持PHP语言从数据库中读取图片
如果对数据库安装还不清晰,可以参考:
(6)安装Bandwitdhd
先创建Bandwidthd数据库和账号
CREATE USER bandwidthdpgsql; ALTER USER bandwidthdpgsql PASSWORD '123456'; create database bandwidthdpgsql;再安装Bandwidthd软件包
apt-get install bandwidthd-pgsql
详细的Bandwidthd安装说明,可以参考:
(7)修改vi /etc/bandwidthd/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 192.168.192.0/24 #subnet 0.0.0.0/0 subnet 10.0.0.0 255.0.0.0 subnet 192.168.0.0 255.255.0.0 subnet 172.16.0.0 255.255.0.0 # Device to listen on # Bandwidthd listens on the first device it detects # by default. Run "bandwidthd -l" for a list of # devices. dev "bg1" ################################################### # Options for postgresql database logging. # Standard postgres connect string,just like PHP,see postgres docs for # details #pgsql_connect_string "user = someuser dbname = mydb host = localhost" pgsql_connect_string "user = bandwidthdpgsql password = 123456 dbname = bandwidthdpgsql host = localhost" # Arbitrary sensor name,I recommend the sensors fully qualified domain # name #sensor_id "sensor1.localhost.localdomain" sensor_id "BW" # Tells Bandwidthd to keep no data and preform no graphing locally graph false # If this is set to true Bandwidthd will try to recover the daily log # into the database. If you set this true on purpose only do it once. # Bandwidthd does not track the fact that it has already transferred # certain records into the database. recover_cdf false ################################################### # Options that don't usually get changed #Put interface in promiscuous mode to score to traffic #that may not be routing through the host machine. promiscuous true #promiscuous false #Libpcap format filter string used to control what bandwidthd see's #Please always include "ip" in the string to avoid strange problems #filter "ip"
vi /etc/network/interfaces
# This file describes the network interfaces available on your system # and how to activate them. For more information,see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto em1 iface em1 inet static address 192.168.192.6 netmask 255.255.255.0 network 192.168.192.0 broadcast 192.168.192.255 gateway 192.168.192.1 # dns-* options are implemented by the resolvconf package,if installed dns-nameservers 222.172.200.68 auto bg1 iface bg1 inet manual pre-up ifconfig em2 down pre-up ifconfig em3 down pre-up brctl addbr bg1 pre-up brctl addif bg1 em2 pre-up brctl addif bg1 em3 pre-up ifconfig em2 0.0.0.0 pre-up ifconfig em3 0.0.0.0 pre-up ifconfig bg1 up post-down ifconfig em2 down post-down ifconfig em3 down post-down ifconfig bg1 down post-down brctl delif bg1 em2 post-down brctl delif bg1 em3 post-down brctl delbr bg1
加入auto bg1 以后的代码。
至此!整个配置全部完毕了。
reboot
重启计算机。5分钟后,打开浏览器。你就可以看到流量了。
看到没害群之马马上就出现了。上传的流量比下载的还大!
贴几张图,秀秀!
三、参考资料
为了方便大家学习,下面把我看过的一些资料贴在下面,供大家交流学习
Bandwidthd安装
Postgresql安装
http://www.if-not-true-then-false.com/2010/howto-install-postgresql-8-4-database-server-on-centos-fedora-red-hat/
http://www.postgresql.org/ftp/pgadmin3/release/v1.18.1/win32/
http://www.blogjava.net/yuanqixun/articles/350525.html
透明网桥
http://wiki.ubuntu.org.cn/UbuntuHelp:NetworkConnectionBridge
http://www.if-not-true-then-false.com/2010/howto-install-postgresql-8-4-database-server-on-centos-fedora-red-hat/
http://www.postgresql.org/ftp/pgadmin3/release/v1.18.1/win32/
http://www.blogjava.net/yuanqixun/articles/350525.html
透明网桥
http://wiki.ubuntu.org.cn/UbuntuHelp:NetworkConnectionBridge
实验笔记汇总:
原文链接:https://www.f2er.com/postgresql/195982.html