feat: 新增负载均衡路由 Action 支持 (balancer/balancer_ip/default_balancer) #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
功能概述
为 v2node 新增三种负载均衡路由 Action,支持将流量分发到多个出站节点,实现高可用和负载均衡。
新增 Action
balancerbalancer_ipdefault_balancer支持的负载均衡策略
randomroundrobinleastpingleastload配置格式
action_value 结构:
{ "tag": "proxy-lb", "outbounds": [ {"tag": "proxy-hk-1", "protocol": "vmess", "settings": {...}, "streamSettings": {...}}, {"tag": "proxy-hk-2", "protocol": "trojan", "settings": {...}, "streamSettings": {...}} ], "strategy": "leastping", "fallbackTag": "direct" }字段说明:
tagoutboundsstrategyrandomfallbackTagAPI 下发示例
balancer(域名匹配):
{ "action": "balancer", "match": ["geosite:netflix", "domain:openai.com"], "action_value": "{\"tag\":\"streaming-lb\",\"outbounds\":[...],\"strategy\":\"leastping\"}" }balancer_ip(IP 匹配):
{ "action": "balancer_ip", "match": ["geoip:us", "1.1.1.1/32"], "action_value": "{\"tag\":\"us-lb\",\"outbounds\":[...],\"strategy\":\"roundrobin\"}" }default_balancer(默认出站):
{ "action": "default_balancer", "match": [], "action_value": "{\"tag\":\"default-lb\",\"outbounds\":[...],\"strategy\":\"random\"}" }变更文件
core/balancer.gocore/custom.gocore/core.gocore/distro/all/all.go技术实现
outbounds数组解析并构建 xray-core OutboundHandlerConfighttps://www.gstatic.com/generate_204注意事项
default_out和default_balancer不应同时配置,会产生冲突(先配置的生效)