rhrl as4.4 httpd安装mod_bandwidth模块
最近经常有站点流量负载超高导致服务器经常挂掉,就想到用此模块来限制单个站点流量和并发,避免伤及无辜站点,prima就用此模块,现在plesk似乎还没有此功能的限制,只能手工安装mod_bandwidth来做限制了。
官方地址http://www.ivn.cl/apache/ 我们下载最新的版本 Status : Stable
Current Version : v0.8 http://www.ivn.cl/apache/files/source/mod_bw-0.8.tgz
在为apache加装此模块的时候需要用到httpd-devel的开发包。
[root@plesklin5 ~]# wget http://www.ivn.cl/apache/files/source/mod_bw-0.8.tgz
[root@plesklin5 ~]# tar -zxf mod_bw-0.8.tgz
[root@plesklin5 ~]# cd mod_bw
[root@plesklin5 mod_bw]# apxs2 -i -a -c mod_bw.c
[root@plesklin5 mod_bw]#rpm-qa |grep http-deval
发现无此安装包,上传http-deval的rpm包所依赖的安装包
apr-0.9.4-24.5.i386.rpm
apr-devel-0.9.4-24.5.i386.rpm
apr-util-0.9.4-21.i386.rpm
apr-util-devel-0.9.4-21.i386.rpm
httpd-devel-2.0.52-25.ent.i386.rpm
pcre-4.5-3.2.RHEL4.i386.rpm
pcre-devel-4.5-3.2.RHEL4.i386.rpm
都装完之后然后在
[root@plesklin5 mod_bw]# apxs -i -a -c mod_bw.c
即可
chmod 755 /usr/lib/httpd/modules/mod_bw.so
ldconfig -n /usr/lib/httpd/modules
[activating module `bw’ in /etc/httpd/conf/httpd.conf]
LoadModule bw_module /usr/lib/httpd/modules/mod_bw.so
[root@plesklin5 mod_bw]# /etc/init.d/httpd restart
Stopping httpd: [OK ]
Starting httpd: [ OK ]
重新启动就生效了,具体的配置信息我们可以看mod_bw.txt文件。
首先前面要先加入
BandwidthModule On
ForceBandWidthModule On
不然什么设置都是无效的…..
限制后缀为.avi 的速度 文件,问大小大于等于 500K的时候速度最高为10K
LargeFileLimit .avi 500 10240
限制单个IP的速度
BandWidth localhost 0 #不限制本机的IP速度
BandWidth 222.191.251.123 1024 #限制这个IP地址为10K
BandWidth “u:^Mozilla/5(.*)” 10240 # 限制浏览器Mozilla的最大速度为 10K ,
BandWidth “u:wget” 102400 #限制wget的速度
BandWidth all 102400 #限制所有的带宽为 100k
MaxConnection all 60 #限制所有的连接为 60
ErrorDocument 510 /error/maxconnexceeded.html
BandWidthError 510 #设置超出规则的错误信息
4.- Examples
4.1 - Misc examples
Limit every user to a max of 10Kb/s on a vhost :
<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername www.frsky.net
</Virtualhost>
Limit al internal users (lan) to 1000 kb/s with a minimum of 50kb/s , and
files greater than 500kb to 50kb/s.
<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000
LargeFileLimit * 500 50000
Servername www.frsky.net
</Virtualhost>
Limit avi and mpg extensions to 20kb/s.
<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 20000
LargeFileLimit .mpg 1 20000
Servername www.frsky.net
</Virtualhost>
Using it the "right" way, with output filter by mime type (for text)
to 5kb/s:
<Virtualhost *>
BandwidthModule On
AddOutputFilterByType MOD_BW text/html text/plain
Bandwidth all 5000
Servername www.frsky.net
</Virtualhost>
If you need help on doing more complex setup, you could post it in sf.net
forums.
现在对plesk站点下的站进行资源控制,touch /var/www/vhosts/xxxx.com/conf/vhost.conf
然后 插入如下:
BandwidthModule On ForceBandWidthModule On BandWidth all 512000 MinBandwidth all 50000 MaxConnection all 600 LargeFileLimit * 1024 50000 BandWidthError 510 ErrorDocument 510 http://frsky.net/error.html
就对这个站点进行了限制。
/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=xxxx.com
/etc/init.d/httpd graceful 重新加载下就生效了。
然后测试下下载,放一个大的文件。
wget http://www.xxxxx.com/frsky
0% [ ] 378,280 48.87K/s ETA 4:28:51
ll frsky
-rw-r–r– 1 zxxxxxcom psacln 808656248 Mar 30 2007 frsky