Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

linux流量限制....

[复制链接]
iamok 发表于 2003-4-7 16:44:52 | 显示全部楼层 |阅读模式

  1. #! /bin/sh
  2. # Simple bandwidth limiter - <[email]j@4u.net[/email]>
  3. # Change this to your link bandwidth
  4. # (for cable modem, DSL links, etc. put the maximal bandwidth you can
  5. # get, not the speed of a local Ethernet link)
  6. REAL_BW='10Mbit'
  7. # Change this to the bandwidth you want to allocate to WEB.
  8. # We're talking about megabits, not megabytes, so 80Kbit is
  9. # 10 Kilobytes/s
  10. WEB_BW='1000Kbit'
  11. # Change this to your physical network device (or 'ppp0')
  12. NIC='eth0'

  13. tc qdisc del dev "$NIC" root 2> /dev/null

  14. tc qdisc add dev "$NIC" root handle 1: cbq \
  15. bandwidth "$REAL_BW" avpkt 1000

  16. tc class add dev "$NIC" parent 1: classid 1:1 cbq bandwidth "$REAL_BW" \
  17. rate "$REAL_BW" maxburst 1 avpkt 1000

  18. tc class add dev "$NIC" parent 1:1 classid 1:10 cbq \
  19. bandwidth "$REAL_BW" rate "$WEB_BW" maxburst 1 avpkt 1000 bounded

  20. tc qdisc add dev "$NIC" parent 1:10 sfq perturb 10

  21. tc filter add dev "$NIC" parent 1: protocol ip handle 1 fw classid 1:10

  22. iptables -t mangle -A OUTPUT -p tcp --sport 80 -j MARK --set-mark 1
复制代码



比天现在就是用这套系统来限制web的流量....加上ip线程的限制....开个http下裁也无妨咯....实际流量会有误差...用http://ethstatus.calle69.net/graphic/index.html


调整...
Crossday 发表于 2003-4-7 16:49:17 | 显示全部楼层
hehe 好东西~下个版本Discuz!核心也会有的流量限制和放DoS功能
回复

使用道具 举报

szboy 发表于 2003-4-7 21:18:24 | 显示全部楼层
哇.
爽.
回复

使用道具 举报

 楼主| iamok 发表于 2003-4-7 23:05:35 | 显示全部楼层
流量限制只是一个下策..不论你怎么限制带宽还是会被占满...所以当务之急是分析web日志..查找源头...比天上周末就被当作download site了....还好平时日志保存比较完善...一查就查到了....


查日志推荐:

WebTrends Analysis Series 7.0

一个600M左右的日志...15分钟就分析完了...
回复

使用道具 举报

 楼主| iamok 发表于 2003-4-10 16:18:15 | 显示全部楼层
htb的语法比cbq的更简单...但是需要给核心打补丁...需要2.4.20级的内核..还有新的tc....

http://luxik.cdi.cz/~devik/qos/htb/

linux的带宽控制能力非常强.





  1. #! /bin/sh
  2. # Simple bandwidth limiter - <[email]j@4u.net[/email]>

  3. # Change this to your link bandwidth
  4. # (for cable modem, DSL links, etc. put the maximal bandwidth you can
  5. # get, not the speed of a local Ethernet link)

  6. # Change this to the bandwidth you want to allocate to FTP.
  7. # We're talking about megabits, not megabytes, so 80Kbit is
  8. # 10 Kilobytes/s
  9. real_bw=512kbit
  10. ftp_bw=50kbit

  11. # Change this to your physical network device (or 'ppp0')
  12. NIC='eth0'

  13. # Change this to the ports you assigned for passive FTP
  14. tc qdisc del dev "$NIC" root

  15. tc qdisc add dev "$NIC" root handle 1: htb

  16. tc class add dev "$NIC" parent 1: classid 1:1 htb rate $real_bw ceil $real_bw burst 1k

  17. tc class add dev "$NIC" parent 1:1 classid 1:10 htb rate $ftp_bw ceil $ftp_bw burst 1k

  18. tc qdisc add dev "$NIC" parent 1:10 sfq perturb 10

  19. tc filter add dev "$NIC" parent 1: protocol ip handle 1 fw flowid 1:10

  20. iptables -t mangle -A OUTPUT -p tcp --sport 80 -j MARK --set-mark 1

  21. #U32="tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32"

  22. #$U32 match ip sport 80 0xffff classid 1:10
复制代码
回复

使用道具 举报

up1m 发表于 2003-11-27 14:07:06 | 显示全部楼层
能否限制每个IP或者单个链接的流量?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-6-1 22:32 , Processed in 0.097511 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表