apache Bandwidth Module Mod_bw 插件安装设置 限制IP并发数和下载流量控制

目录

1、下载

2、解压

3、编译安装 

1)修改代码

a.注释#if (APR_MAJOR_VERSION < 1)代码:

b.把所有的remote_addr替换成client_addr 

2)编译

​4、配置apache

1) httpd.conf 加上LoadModule bw_module modules/mod_bw.so

2) 网站配置

5、测试


1、下载

 下载地址:http://bwmod.sourceforge.net/

wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz

目前是0.7版本

2、解压

tar -xzf  mod_bw-0.7.tgz

3、编译安装 

1)修改代码

由于apache2.2 到2.4 api有所改变详细地址http://httpd.apache.org/docs/2.4/developer/new_api_2_4.html

a.注释#if (APR_MAJOR_VERSION < 1)代码:

/* Compatibility for ARP < 1 
#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
*/

报错内容:

ERROR:
httpd: Syntax error on line 153 of /www/server/apache/conf/httpd.conf: Cannot load modules/mod_bw.so into server: /www/server/apache/modules/mod_bw.so: undefined symbol: apr_atomic_set

b.把所有的remote_addr替换成client_addr 

报错内容:

mod_bw.c: In function ‘get_bw_rate’:
mod_bw.c:484:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
  484 |             if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
      |                                                           ^~
mod_bw.c: In function ‘get_maxconn’:
mod_bw.c:567:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
  567 |             if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
      |                                                           ^~
mod_bw.c: In function ‘get_sid’:
mod_bw.c:612:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
  612 |             if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
      |                                                           ^~
mod_bw.c: In function ‘update_counters’:

apxs:Error: Command failed with rc=65536

2)编译

cd mod_bw
/www/server/apache/bin/apxs -c -i mod_bw.c


4、配置apache

1) httpd.conf 加上LoadModule bw_module modules/mod_bw.so

2) 网站配置

详细配置可以参考mod_bw.txt

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot "/www"
    ServerName 301ac043.test
    ServerAlias test
    
     BandwidthModule On  
     ForceBandWidthModule On  
     Bandwidth all 2048000
     MinBandwidth all 1024000  
     LargeFileLimit * 500 50000  
     MaxConnection all 10

主要参数说明
1) BandWidth localhost 0                   //对localhost不限速
2) BandWidth 8.8.8.8 102400            //对8.8.8.8限速为100KB
3) MinBandWidth all 10240                //保证每个客户端最高速度可达10KB
4) LargeFileLimit .jpg 100 10240       //jpg文件超过100KB) 限速10KB
5) 自定义510报错
    ErrorDocument 510 /errors/maxconexceeded.html
    BandWidthError 510
6) MaxConnection all 10                 //所有ip最大连接数为10
7) MaxConnection 8.8.8.8 5           //8.8.8.8最大连接数为5

5、测试

将最大连接数设置小点,如: MaxConnection all 1 然后打开开发者工具,不断的按F5刷新页面页面,就会出现canceled

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值