apache限速mod_bw

使用mod_bandwidth可以实现并发Ip数和带宽的限制,带宽流量控制模块

安装

tar zxvf mod_bw-0.7.tgz
cd mod_bw
apxs -c -i mod_bw.c


配置

1 全局开启

vim /etc/httpd/conf.modules.d/mod_bw.conf

  1. Load bw_mod modules/mod_bw.so
  2. BandWidthModule On  
  3. ForceBandWidthModule On    
  4. BandWidth all 102400  #限制为100K  
  5. MaxConnection all 100 #限制为100个连接数

2 目录限速

LoadModule bw_module modules/mod_bw.so
  
<virtualHost *:80>
     ServerName vhost1.cszhi.com
     DocumentRoot  /var/www/vhost1
     BandwidthModule On
     ForceBandWidthModule On
     Bandwidth all 1024000
     MinBandwidth all 50000     #每个客户端最高速度可达50KB
     LargeFileLimit * 500 50000
     MaxConnection all 6
</virtualHost>

安装中可能遇到的问题

1 提示如下错误:

/mnt/vdd/mod_bw.c: In function 'get_bw_rate':
/mnt/vdd/mod_bw.c:567:59: error: 'conn_rec' has no member named 'remote_addr'

             if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {

这个错误是由于apache2.2 到2.4 api有所改变,详细如下:

http://httpd.apache.org/docs/2.4/developer/new_api_2_4.html

vim mod_bw.c

把所有的remote_ipremote_addr分别替换成client_ipclient_addr

:%s/remote_ip/client_ip/

:%s/remote_addr/client_addr/

重新执行     apxs -i -c -a mod_bw.c 

2 httpd服务重启后发生错误

[root@vps httpd]# /etc/init.d/httpd restart
Stopping httpd:                      [FAILED]
Starting httpd: httpd: Syntax error on line 203 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_bw.so into server: /etc/httpd/modules/mod_bw.so: undefined symbol: apr_atomic_cas
                               [FAILED]

修改mod_bw.c

#ifdef APR_MAJOR_VERSION  //添加这行
#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
#endif //添加这行

3 apxs没有安装

安装httpd-devel

配置参考

http://www.361way.com/apache-limit-speed/2138.html


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值