`
suxing
  • 浏览: 202173 次
  • 性别: Icon_minigender_1
  • 来自: 遵义
社区版块
存档分类
最新评论

ubuntu下为web下载限速

阅读更多

使用iptables方法:

sudo iptables -R OUTPUT 1 -p tcp --sport 80 -m limit --limit 1000/s --limit-burst 100 -j ACCEPT

sudo iptables -A OUTPUT -p tcp --sport 80 -j DROP

对比的限速和不限速下的cup、内存占用,发现限速下cup占用下降,但内存占用增加了,看来apache将iptables丢弃的包缓存了起来,用iptables来为web限速不是最佳选择。

 

使用Apache mod_bw 模块:

1、下载mod_bw http://apache.ivn.cl/ 

2、确定安装了apxs或apxs2,

     如果没有执行安装 apt-get install apache2-prefork-dev

3、解开mod_bw包,执行 sudo apxs2 -i -a -c mod_bw.c

     报错如下:

 

apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file..

apxs:Error: At least one `LoadModule' directive already has to exist..

4、解决错误
     sudo nano /etc/apache2/httpd.conf
     增加一行:
     LoadModule bw_module       /usr/lib/apache2/modules/mod_bw.so
5、sudo nano /etc/apache2/sites-enabled/000-default
     在<VirtualHost *>部分增加以下内容:
        BandWidthModule On
        ForceBandWidthModule On
        BandWidth all 1000000
        LargeFileLimit .flv 1 60000
     具体配置方法mod_bw包里有帮助文档。
使用mod_bw,内存占用没有变化,CPU占用下降,应是web限速的首选。

另外,在对flv限速后竟然导致无法访问flv文件,后来在<VirtualHost *>里增加
AddType flv-application/octet-stream .flv
解决问题。以上内容也可改为
AddType video/x-flv .flv

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics