使用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..