Skip to content

代理组 — mihomo

代理组是代理 / 其他组的命名集合,对外表现为单一命名出站。mihomo 提供 四种组类型:select(手动)、url-test(基于延迟自动)、fallback (按顺序基于健康)与 load-balance(分配流量)。

通用字段

所有组类型共享同一份 GroupCommonOption 基类。结构体标签 group:"..." 是 mihomo 自有的 —— YAML 键与该标签一致。

字段类型默认值允许值描述
namestring(required)<string>唯一的组名。会被规则与其他组引用。
typestring(required)select | url-test | fallback | load-balance组类型。`relay` 已移除 —— 请在代理条目上使用 `dialer-proxy`。
proxies[]string[][<proxy or group name>]显式成员列表。基于 provider 的成员构成请使用 `use:`。
use[]string[][<proxy-provider name>]从命名 proxy-provider 拉取成员。
urlstring(required for url-test/fallback)<URL>健康检查 URL —— 定期对该 URL 发 GET 以测量成员延迟。典型:`http://www.gstatic.com/generate_204`。
intervalint300<seconds>两次健康检查之间的秒数。
timeoutint5000<milliseconds>健康检查超时(毫秒)。
max-failed-timesint5<int>成员被视为不可用前允许的连续失败次数。
empty-fallbackstring(unset)<proxy name>当组解析后没有可用成员时(例如成员都被 `filter` 滤掉)回落到的代理。
lazybooltruetrue | false为 true 时仅在组被实际使用时运行健康检查。可省带宽。
disable-udpboolfalsetrue | false该组拒绝 UDP 流量。在并非所有成员都支持 UDP 时有用。
filterstring(unset)<regex> | <regex>`<regex>...应用于成员名的正则过滤器。多个正则用反引号分隔。
exclude-filterstring(unset)<regex>正则过滤器 —— 名字命中的成员被排除。
exclude-typestring(unset)<proxy type>排除指定类型的成员(如 `direct,ss`)。
expected-statusstring*<HTTP status range>可接受的健康检查状态码。`2xx` 或 `200-204,301`。
include-allboolfalsetrue | false自动包含所有代理与 provider —— 省去手动列出。
include-all-proxiesboolfalsetrue | false自动包含所有代理条目(不含 provider)。
include-all-providersboolfalsetrue | false自动包含所有 proxy-provider(不含直连代理)。
hiddenboolfalsetrue | false在面板 UI 中隐藏该组。
iconstring(unset)<URL>兼容面板会显示的图标 URL。

源码: adapter/outboundgroup/parser.go:25-46 · 锚定版本 v1.19.27 (5184081)

type: select

手动选择。该组把当前选项暴露给 Clash API(面板可让用户切换)。 无健康检查 —— 被选成员即被直接使用。

yaml
proxy-groups:
  - name: Manual
    type: select
    proxies: [Proxy-A, Proxy-B, Proxy-C, DIRECT]

type: url-test

通过周期性 URL 延迟探测自动挑选最快成员。探测每 interval 秒运行; 活动成员仅在新成员快出超过旧式 tolerance 时切换 (在 adapter/outboundgroup/urltest.go:198-205parseURLTestOption 中解析)。

yaml
proxy-groups:
  - name: Auto
    type: url-test
    url: http://www.gstatic.com/generate_204
    interval: 300
    timeout: 5000
    tolerance: 50
    proxies: [Proxy-JP, Proxy-US, Proxy-HK, Proxy-SG]

额外字段:

  • tolerance(整数,毫秒)—— 切换阈值。默认 0(始终切到绝对最快, 可能抖动)。

type: fallback

使用首个仍响应的成员。按声明顺序进行健康检查;第一个存活的 承 担全部流量。适合「主 + 备」模式。

yaml
proxy-groups:
  - name: HA
    type: fallback
    url: http://www.gstatic.com/generate_204
    interval: 60
    timeout: 3000
    max-failed-times: 3
    proxies: [Primary, Backup, DIRECT]

type: load-balance

把流量分散到各成员。strategy 字段选择算法:

策略行为
round-robin按顺序轮转。
consistent-hashing对目的域名哈希 —— 同一域名总走同一成员。适合 CDN 粘性路由。
sticky-sessions同一客户端的首次连接挑选成员,后续连接复用。
yaml
proxy-groups:
  - name: Distributed
    type: load-balance
    url: http://www.gstatic.com/generate_204
    interval: 300
    strategy: consistent-hashing
    proxies: [Proxy-1, Proxy-2, Proxy-3]

type: relay —— 已移除

曾是链式代理组。已移除;替代方案是按代理设置 dialer-proxy: 字段(示例见 Direct)。仍写 type: relay 的 配置会在启动时报明确错误 (adapter/outboundgroup/parser.go:187-188)。

成员集合工具

代理多时,手工在每个组里列出会很痛苦。四个 include-all* 标志加上 filter / exclude-filter 解决这个问题:

yaml
proxy-groups:
  - name: All-JP
    type: url-test
    url: http://www.gstatic.com/generate_204
    interval: 300
    include-all: true
    filter: 'JP|Japan|🇯🇵'
    exclude-type: 'direct,reject'

四个标志按层级展开:

  • include-all: true 等价于同时设置 include-all-proxiesinclude-all-providers: true
  • include-all-proxies 覆盖 proxies: 中的条目。
  • include-all-providers 覆盖经 proxy-providers: 引入的条目。
  • 直接的 use: 显式引用命名 provider。

filter 接受反引号分隔的正则 —— 每个之间是 OR 关系。例如 filter: 'JP\Japan`🇯🇵'` 匹配名字含三种字符串之一的代理。

示例

典型多层级部署:

yaml
proxy-providers:
  vendor1:
    type: http
    url: https://example.com/sub
    interval: 86400
    path: ./providers/vendor1.yaml

proxy-groups:
  - name: 🚀 Proxy
    type: select
    proxies: [♻️ Auto, 🔯 Fallback, 🔮 LoadBalance, DIRECT]

  - name: ♻️ Auto
    type: url-test
    url: http://www.gstatic.com/generate_204
    interval: 300
    tolerance: 50
    use: [vendor1]
    filter: '香港|新加坡|HK|SG'

  - name: 🔯 Fallback
    type: fallback
    url: http://www.gstatic.com/generate_204
    interval: 60
    use: [vendor1]
    filter: '日本|JP'

  - name: 🔮 LoadBalance
    type: load-balance
    url: http://www.gstatic.com/generate_204
    interval: 300
    strategy: consistent-hashing
    use: [vendor1]

  - name: 🎬 Stream
    type: select
    include-all: true
    filter: '美|US|🇺🇸'

rules:
  - DOMAIN-SUFFIX,netflix.com,🎬 Stream
  - MATCH,🚀 Proxy

跨内核说明

sing-box 等价 —— selector / urltest 出站

sing-box 把同样的想法实现为 出站类型,而非独立的「组」概念:

json
{
  "outbounds": [
    { "type": "selector",
      "tag": "manual",
      "outbounds": ["proxy-jp", "proxy-us", "direct"],
      "default": "proxy-jp",
      "interrupt_exist_connections": false },
    { "type": "urltest",
      "tag": "auto",
      "outbounds": ["proxy-jp", "proxy-us"],
      "url": "https://www.gstatic.com/generate_204",
      "interval": "3m",
      "tolerance": 50 }
  ]
}

Selector:

字段类型默认值允许值描述
outbounds[]string(required)[<outbound tag>]成员出站。
defaultstring(first in outbounds)<outbound tag>启动时的初始选择。
interrupt_exist_connectionsboolfalsetrue | false选择切换时,关闭仍在使用旧成员的连接。

源码: option/group.go:5-9 · 锚定版本 v1.13.11 (553cfa1)

URLTest:

字段类型默认值允许值描述
outbounds[]string(required)[<outbound tag>]成员出站。
urlstringhttps://www.gstatic.com/generate_204<URL>健康检查 URL。
intervalbadoption.Duration3m<duration>重新测试成员的频率。
toleranceuint1650<milliseconds>新成员快超过该毫秒数时才切换。可防止延迟相近时的抖动。
idle_timeoutbadoption.Duration30m<duration>空闲超过该时长后停止健康检查 —— 下次需要时恢复。
interrupt_exist_connectionsboolfalsetrue | false切换时关闭仍在使用旧成员的连接。

源码: option/group.go:11-18 · 锚定版本 v1.13.11 (553cfa1)

sing-box 没有 mihomo fallbackload-balance 组的精确等价。最 接近的做法是用 urltest 配很小的 tolerance 模拟 fallback 行为, 或者级联 selector。

Xray 等价 —— 负载均衡器

Xray 的 balancers 文档在 Routing 页面。策略 取值:randomroundRobinleastPingleastLoad。Xray 没有 "selector"(手动选择)等价物 —— 负载均衡器按策略自动路由。

由 Argsment 出品的 Core Tutorial