centos 安装 mod_bw httpd apache 限速 限制下载速度
一.安装
wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz
tar -xvf mod_bw-0.7.tgz
cd mod_bw
apxs -i -a -c mod_bw.c
二.如果报下面的错
我在64位centos上,想利用bw_mod限制apache带宽,在安装完成,重启apache后出现undefined symbol: apr_atomic_cas错误
cd mod_bw
解决办法如下: 1.打开mod_bw.c文件 vim mod_bw.c 2. 找到如下代码: #if (APR_MAJOR_VERSION < 1) #define apr_atomic_inc32 apr_atomic_inc #define apr_atomic_dec32 apr_atomic_dec #define apr_atomic_add32 apr_atomic_add #define apr_atomic_cas32 apr_atomic_cas #define apr_atomic_set32 apr_atomic_set #endif 将其注释,即: /* #if (APR_MAJOR_VERSION < 1) #define apr_atomic_inc32 apr_atomic_inc #define apr_atomic_dec32 apr_atomic_dec #define apr_atomic_add32 apr_atomic_add #define apr_atomic_cas32 apr_atomic_cas #define apr_atomic_set32 apr_atomic_set #endif */ 3.重新编译即可。
三.配置
Listen 8008 <Virtualhost *:8008> ServerName 123 DocumentRoot "/root/workspace/server/gameserver/passport" WSGIScriptAlias / /root/workspace/server/gameserver/passport/passport/aly_wsgi.py Order deny,allow Allow from all Alias "/static" "/root/workspace/server/gameserver/passport/passport/static_root" <location "="" static"=""> SetHandler None Alias "/media" "/root/workspace/server/gameserver/passport/passport/media" <location "="" media"=""> SetHandler None ErrorLog /var/log/httpd/passport_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel error CustomLog /var/log/httpd/passport_access.log combined BandwidthModule On ForceBandWidthModule On Bandwidth all 1000000 #所有人限速10M LargeFileLimit .apk 500 20000 #大于500K的apk限速20K LargeFileLimit .zip 500 20000 #大于500K的zip限速20K #MinBandwidth all -1 #不知道为什么,这句加上不能限速 </Virtualhost>
设置Apache的conf文件: BandWidthModule On
BandWidth 211.67.64.0/255.255.255.0 100000 //211.67.64.0的用户带宽限制为
100K
BandWidth all 10000 //其他用户带宽限制为
10K
LargeFileLimit .avi 500 10000 //文件大小超过
500K
的
avi
文件限制为
10K
// 定义错误码和错误页面
ErrorDocument 510 /errors/maxconexceeded.html
BandWidthError 510
mod_bandwidth 的选项简单说明:
..............................
BandWidthDataDir
格式: BandWidthDataDir
默认: "/tmp/apachebw"
上下文: server config
设置 mod_bandwidth 保存运行时数据的目录。需要在该目录下创建 ./master
和 ./link 两个子目录,并设置为权限为 777。
注意:有些系统会定时清理 /tmp 目录,所以在这些系统上最好把
BandWidthDataDir 设置到其他地方。
..............................
BandWidthModule
格式: BandWidthModule
默认: Off
上下文: per server config
允许或者禁止模块。
..............................
BandWidthPulse
格式: BandWidthPulse
默认: 1000
上下文: per server config
改变计算带宽的时间间隔,默认为1000毫秒(1秒)。使用更低的间隔可以获得
更精确的带宽控制,但消耗更多的CPU时间,反之亦然。
注意:这个选项的详细说明请参考 mod_bandwidth 的文档。
..............................
BandWidth
格式: BandWidth
默认: 无
上下文: per directory, .htaccess
限制这个目录下文件下载的速率。
domain 指定来自哪个域的连接受到这个设置的影响。
ip 指定来自哪个ip地址(或者ip段)的连接受到影响。
all 所有连接都受到影响。
示例:
# 来自 dualface.com 的连接不限制下载速度
BandWidth dualface.com 0
# 来自 192.168.0.0/16(或者192.168.0) 网段的连接不限制下载速度
BandWidth 192.168.0.0/16 0
# 其他连接限制下载速度为每秒1024字节
BandWidth all 1024
# 越前面的设置优先权越高
..............................
LargeFileLimit
格式: LargeFileLimit
默认: 无
上下文: per directory, .htaccess
对于超过指定大小的文件,下载时使用的速率。如果速率设置0即不限制速度,
但下载速度仍然要受到BandWidth设置的影响。如果设置成-1,则完全不受影响。
通过设置不同的文件大小和速率,可以设置不同大小范围内文件的下载速度。
示例:
# 文件尺寸大于等于200千字节的文件,下载速率为每秒3072字节
LargeFileLimit 200 3072
LargeFileLimit 1024 2048
..............................
MaxConnection
格式: MaxConnection
默认: 0 (不限制)
上下文: per directory, .htaccess
当超过指定连接数时,拒绝新的连接。
..............................
MinBandWidth
格式: MinBandWidth
默认: all 256
上下文: per directory, .htaccess
设置最小带宽,默认为每秒256字节。根据BandWidth和LargeFileLimit设置的速
率。mod_bandwidth会计算允许的连接数。例如BandWidth为4096字节,而
MinBandWidth为1024字节,则最大并发连接数为4。
注意:这个选项的详细说明请参考 mod_bandwidth 的文档。