服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 940|回复: 0

Squid限制带宽

[复制链接]
dirtysea 发表于 2023-4-19 14:12:45 | 显示全部楼层 |阅读模式
squid限制带宽
23 Mar, 2008  CDN

squid限制带宽
关于设定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分配给8bit网络的使用者(255 hosts)使用IPv4 class C).
(3)Class 3:包含255个buckets,每一个bucket分配给16bit网络的使用者(65535 hosts)使用(IPv4 class B).

(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 B)
推测:如果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 tatal per-host
class 3 delay pool;
delay_parameters pool total network per-host
每个delay_parameters的数值是由restore(byte/sec)/max(bytes)组成,restore是表示以bytes/sec的速度下载object到bucket里,而max则表示bucket的bytes值.
备注1:如果要设定为unilit 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 的所有使用者单一带宽,并对总的带宽作以限制
本文来自: E点废墟(www.xok.la) 详细出处参考:http://xok.la/2008/03/squid_limlit_band.html
————————————————
版权声明:本文为CSDN博主「DBA日志小记」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m18580239676/article/details/48367903

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

本版积分规则

QQ|小黑屋|手机版|Archiver|运维之家

GMT+8, 2024-3-29 15:16 , Processed in 0.193524 second(s), 14 queries .

Powered by Dirtysea

© 2008-2020 Dirtysea.com.

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