发布于
597 字 · 3 分钟

Clash 负载均衡配置指南

AI 摘要

作者
  • avatar
    姓名
    Corner430
    社交账号
题图

Clash 的负载均衡功能可以将流量分散到多个代理节点,避免单节点压力过大,同时降低 IP 风控风险。本文介绍两种实现方式:通过 Parsers 自动注入和手动编辑配置文件。

1 两种负载均衡策略

  • 散列(consistent-hashing):对同一二级域名使用相同节点,避免频繁切换 IP 触发风控
  • 轮询(round-robin):每次请求使用不同节点,适合需要切换 IP 的场景

两种策略都支持定时测速(默认 300 秒),超时节点会自动排除。

2 方式一:通过 Parsers 自动注入

在 Clash 的 Settings → Profiles → Parsers 中填入以下内容:

parsers:
  - reg: 'slbable$'
    yaml:
      append-proxy-groups:
        - name: ⚖️ 负载均衡-散列
          type: load-balance
          url: 'http://www.google.com/generate_204'
          interval: 300
          strategy: consistent-hashing
        - name: ⚖️ 负载均衡-轮询
          type: load-balance
          url: 'http://www.google.com/generate_204'
          interval: 300
          strategy: round-robin
      commands:
        - proxy-groups.⚖️ 负载均衡-散列.proxies=[]proxyNames
        - proxy-groups.0.proxies.0+⚖️ 负载均衡-散列
        - proxy-groups.⚖️ 负载均衡-轮询.proxies=[]proxyNames
        - proxy-groups.0.proxies.0+⚖️ 负载均衡-轮询

配置说明:

  • reg: 'slbable$':当订阅 URL 以 slbable 结尾时触发
  • interval: 300:每 300 秒测速一次,超时节点不参与负载均衡

使用步骤:

  1. 通过 V2Ray 导出订阅链接
  2. 使用 subconverter简易版转换工具进行订阅转换
  3. 在浏览器中打开转换后的链接,保存为 .yaml 文件
  4. 在 Clash 的 Settings → URL 中填入 file\文件路径#slbable 触发订阅刷新

3 方式二:手动编辑配置文件

这种方式适用于所有平台,直接编辑 .yaml 配置文件。

3.1 添加策略组引用

找到 proxy-groups 的第一个策略组,在其 proxies 列表中添加:

# 在第一个代理策略组的 proxies 中添加
- ⚖️ 负载均衡-轮询
- ⚖️ 负载均衡-散列

3.2 添加负载均衡策略组

在最后一个策略组后面添加:

# 添加负载均衡策略组
- name: ⚖️ 负载均衡-散列
  type: load-balance
  url: http://www.google.com/generate_204
  interval: 300
  strategy: consistent-hashing
  proxies:
    - 节点1
    - 节点2
    - 节点3
- name: ⚖️ 负载均衡-轮询
  type: load-balance
  url: http://www.google.com/generate_204
  interval: 300
  strategy: round-robin
  proxies:
    - 节点1
    - 节点2
    - 节点3

节点1节点2节点3 替换为实际的代理节点名称。

3.3 导入生效

将编辑好的配置文件导入到目标设备的 Clash 客户端即可。

版权声明

除非另有说明,本文内容采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处。