🔗 功能:ACL 类型 “Random”
- 目标:实现一个 ACL 类型,该类型将以给定概率随机匹配。
- 状态:完成
- 版本: 3.2
- 开发者:AmosJeffries
- 更多:Bug 1239
🔗 详细信息
类型为“random”的 ACL 将接受以下三种格式中的一种作为单个值
- A:B - 平均每 B 次不匹配中随机匹配 A 次。A 和 B 不能为零。
- A/B - 总共 B 次请求中平均随机匹配 A 次。A 和 B 不能为零。
- 0.NNNN - 以 0.NNNN 的概率随机匹配任何给定请求。
- 范围在零到一之间,不包括零和一本身。
这三种匹配方式都是成比例的。前两种格式是为了方便配置。它们会被转换为第三种格式所示的小数阈值。
每次测试时,都会生成一个新的随机数并与存储的值进行比较。如果随机数在可能的阈值范围内,ACL 将匹配。
要调试此 ACL,请使用 debug_options 28,3 并关注以“ACL Random”开头的行。
🔗 用例
🔗 上行链路负载均衡
当在 tcp_outgoing_address 或 tcp_outgoing_tos 选择中使用时,此 ACL 允许根据多个链路的相对容量大致分配负载。
这需要在操作系统级别进行一些额外的配置,以确保分配的地址或 TOS 值被路由到合适 essas 上行链路。如果所有流量最终都通过默认路径出去,那么在 Squid 中这样做是没有意义的。
-
示例 1:将两个上行链路的流量大致分配为 50% 每条
acl fiftyPercent random 0.5 # a random 50% go here tcp_outgoing_address 192.0.2.1 fiftyPercent # the rest go here tcp_outgoing_address 192.0.2.2 # NP: operating system required to route packets from 192.0.2.1 and 192.0.2.2 out separate uplinks. -
示例 2:将流量平均分配给三个对等节点,每thirds之一。
acl third random 1/3 acl half random 1/2 # 33% traffic goes here cache_peer_access peerOne allow third cache_peer_access peerOne deny all # 33% traffic goes here cache_peer_access peerTwo allow half cache_peer_access peerTwo deny all # remaining traffic goes here cache_peer_access peerOne allow all -
示例 3:将流量平均分配给两个对等节点,每thirds之一,其余的直接发送。
acl third random 1/3 acl half random 1/2 # 33% traffic goes direct always_direct allow third # 33% traffic goes here (half of what did not go direct already) cache_peer_access peerOne deny half cache_peer_access peerOne allow all # remaining traffic goes here cache_peer_access peerTwo allow all # NP: if both peers are down DIRECT will be used as a backup.
🔗 流量日志抽样
当在 access_log 指令中使用时,此 ACL 允许记录一小部分随机请求。而不是记录所有流量或仅匹配固定条件的流量。
-
示例 1:随机记录 100 个请求中的 1 条日志。
# log 1, skip 99 acl logSmallSample random 1:99 # small log 1 of every 100 requests... access_log /var/log/squid/access-sample.log squid logSmallSample # old style complete log access_log /var/log/squid/access.log squid
类别:功能
导航:站点搜索,站点页面,类别,🔼 向上