免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1047 | 回复: 0
打印 上一主题 下一主题

squid限制带宽 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-04 17:51 |只看该作者 |倒序浏览

關於設定 SQUID 的頻寬及流量限制,可利用 squid.conf 中的 delay_pools 區段來完成
delay pools 裡的 bucket 像是一個容器,而這個容器就是 squid 要控制頻寬用的,當容器到達所設定的容量時,這個容器的擁有者也無法超過我們所設定的頻寬限制,所有的 bucket 則稱為 unified bucket
Class 分為三種:
(1)Class 1:包含一個 unified bucket,而這個 bucket 是給這個 class 裡所定義的 host 使用
(2)Class 2:包含一個 unified bucket 和 255 個 buckets,每一個 bucket 分配給 8 bit 網路的使用者(255 hosts)使用 (IPv4 class C)
(3)Class 3:包含255個 buckets,每一個 bucket 分配給 16 bit 網路的使用者(65535 hosts)使用 (IPv4 class

(1)Class 1:contains a single unified bucket which is used for all requests from hosts subject to the pool
(2)Class 2:contains one unified bucket and 255 buckets, one for each host on an 8-bit network (IPv4 class C)
(3)Class 3:contains 255 buckets for the subnets in a 16-bit network, and individual buckets for every host on these networks (IPv4 class

推測:若 ACL 只有定義單一個 class C 區段,要限制每個 host 的單一連線流速,可使用 Class 2 來完成;但若 ACL 有定義好幾個 class C 區段,使用 Class 3 可再對各個 class C 區段做個別的總流速限制
delay_parameters 語法:
class 1 delay pool:
delay_parameters pool total
class 2 delay pool:
delay_parameters pool total per-host
class 3 delay pool:
delay_parameters pool total network per-host
每個 delay_parameters 的數值是由 restore(bytes/sec)/max(bytes) 組成,restore 是表示以 bytes/sec 的速度下載 object 到 bucket 裡,而 max 則表示 buckets 的 bytes 值
備註1:如果要設定為 unlimit speed 的話,將數值設定為 -1 即可
備註2:SQUID FAQ 中有提到,建議 max 至少要設為 restore 的兩倍 (It is recommended that the maximum is at least twice the restore value)
[設定檔格式說明]
acl all src 0.0.0.0/0.0.0.0
acl lan src 192.168.1.0/255.255.255.0 # 定義 ACL
delay_pools n # 總共有幾個 delay_pools
delay_class n1 1 # 第 n1 個 delay_pool 的種類是 Class 1
delay_class n2 3 # 第 n2 個 delay_pool 的種類是 Class 3
delay_class n3 2 # 第 n3 個 delay_pool 的種類是 Class 2
delay_access n1 allow lan
delay_access n1 deny all # 定義 delay_pool n1 的 access rule
delay_parameters n1 64000/64000 # 定義 delay_pool n1 的速度限制,依 class 的不同有不同的定義方式 (請參照上面的說明)
[範例說明]
1. 限制總流速為 512 Kbps
acl all src 0.0.0.0/0.0.0.0 # might already be defined
delay_pools 1
delay_class 1 1
delay_access 1 allow all
delay_parameters 1 64000/64000 # 512 kbits == 64 kbytes per second
2. 限制單一連線的流速為 128 Kbps
acl only128kusers src 192.168.1.0/255.255.192.0
acl all src 0.0.0.0/0.0.0.0
delay_pools 1
delay_class 1 3
delay_access 1 allow only128kusers
delay_access 1 deny all
delay_parameters 1 64000/64000 -1/-1 16000/64000
3. 對某些特定網站設定不同的流速限制 (自己試著設定的,若有錯誤請自行修改)
acl lan_use src 192.168.1.0/255.255.255.0 # 設定 LAN 使用者的 ACL
acl kkbox dstdomain .kkbox.com.tw # 設定特定網域的 ACL
delay_pools 2 # 設定兩個 delay_pools
delay_class 1 1 # 第一個是 Class 1 的,用來限制總流速
delay_class 2 2 # 第二個是 Class 2 的,用來限制單一連線流速
delay_access 1 allow kkbox
delay_access 1 deny all
delay_access 2 allow lan_use
delay_access 2 deny all
delay_parameters 1 64000/64000 # 不限制特定網域的單一連線流速,但對總流速作限制
delay_parameters 2 64000/64000 10000/50000 # 限制 LAN 的所有使用者單一連線流速,並對總流速作限制

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/14155/showart_209993.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP