概述
因为业务需求,需要在IBM HTTP Server实现下载限速功能。
需求分析
因为IHS是基于Apache HTTPD构建,其自身并不实现下载的限速功能,因此,需要采用第三方组件来实现该功能,在这个限速功能使用的是名称为Bandwidth Mod。
该组件主页:
http://bwmod.sourceforge.net/#
安装依赖
需要预先安装httpd-devel
安装步骤
执行命令 /opt/IBM/HTTPServer/bin/apxs -ic mod_bw.c来编译。
编辑/opt/IBM/HTTPServer/conf/httpd.conf,增加以下条目实现限速功能:
LoadModule bw_module modules/mod_bw.so BandWidthModule On ForceBandWidthModule On BandWidth all 1024000 #每个客户端限速1M LargeFileLimit * 10240 102400 #如果文件大于10M,限速100K/s |
测试
在/opt/IBM/HTTPServer/htdocs目录下放入大于10M的文件,然后再浏览器窗口访问该文件的url会发现下载速度被限制在100K/s以下。
附录:
安装问题:
1.出现如下错误,
./mod_bw/mod_bw.c: In function 'get_bw_rate': ./mod_bw/mod_bw.c:484:59: error: 'conn_rec' has no member named 'remote_addr' if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) { ^ ./mod_bw/mod_bw.c: In function 'get_maxconn': ./mod_bw/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)) { ^ ./mod_bw/mod_bw.c: In function 'get_sid': ./mod_bw/mod_bw.c:612:59: error: 'conn_rec' has no member named 'remote_addr' if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) { ^ |
需要修改mod_bw.c将其中的remote_addr替换为client_addr,remote_ip替换为client_ip
2. 出现如下错误
../bin/apachectl -k start httpd: Syntax error on line 869 of /opt/IBM/HTTPServer/conf/httpd.conf: Cannot load modules/mod_bw.so into server: /opt/IBM/HTTPServer/modules/mod_bw.so: undefined symbol: apr_atomic_set |
需要修改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 //新增 |