目录
为什么配置负载均衡?
那么假如我有2台运行着Project V 服务端的机器,分别在世界不同的区域:美国,香港,这些机器连接国内的线路有的速度快,有的速度慢,有的很稳,有的时不时抽风,有时海底光缆断掉,有的莫名其妙被tcp阻断。那么如果用Project V 客户端连接到这些服务器还得经常因为速度、稳定性的原因经常切来切去,未免过于麻烦。所以,需要负载均衡。其实就是和ssr的负载均衡一个意识。
如何配置负载均衡?
下面以一个实际Project V四台机器进行负载均衡为例,进行说明如何编写json和配置客户端。
"outbound": {
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "US.vjsun.com", # 第一台服务器
"port": 443,
"users": [
{
"id": "b3b6da21-0206-496b-a9c5-cf9d3d69c7e8",
"alterId": 64,
"security": "none"
}
]
},
{
"address": "KR.vjsun.com", # 第二台服务器
"port": 443,
"users": [
{
"id": "770593ed-2d6c-4d08-b42e-d9cbc90be24c",
"alterId": 100,
"security": "none"
}
]
},
{
"address": "HK.vjsun.com", # 第三台服务器
"port": 443,
"users": [
{
"id": "4d5328da-0a77-4ee3-b5af-91bbbbd8e75s",
"alterId": 64,
"security": "none"
}
]
},
{
"address": "JP.vjsun.com", # 第四台服务器
"port": 443,
"users": [
{
"id": "fe079348-f0bf-4c74-acc7-39adba442f6d",
"alterId": 100,
"security": "none"
}
]
}
],
"servers": null
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"allowInsecure": true,
"serverName": null
},
"tcpSettings": null,
"kcpSettings": null,
"wsSettings": {
"connectionReuse": true,
"path": "/ray", # websocket连接路径
"headers": null
},
"httpSettings": null
},
"mux": {
"enabled": false
}
},
- 配置多台机器负载均衡的重点是在json文件中的outbound部分。要求所有机器都用相同的协议类型,比如都用vmess,都走tcp,或都走websocket,而且websocket的路径都相同。
- 不同的机器配置在vnext的数组中定义。在上面的例子中这样定义了四台机器, 地址分别是US.vjsun.com, KR.vjsun.com, HK.vjsun.com, JP.vjsun.com.
- 这些机器可以配置不同的端口号,user ID,alter ID和加密类型。下边就是详细的介绍
{
"log": {
"access": "Vaccess.log",
"error": "Verror.log",
"loglevel": "warning"
},
"inbound": {
"domainOverride": ["tls","http"],
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"ip": "127.0.0.1",
"clients": null
},
"streamSettings": null
},
"outbound": {
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "US.vjsun.com",
"port": 443,
"users": [
{
"id": "b3b6da21-0206-496b-a9c5-cf9d3d69c7e8",
"alterId": 64,
"security": "none"
}
]
},
{
"address": "TW.vjsun.com",
"port": 443,
"users": [
{
"id": "770593ed-2d6c-4d08-b42e-d9cbc90be24c",
"alterId": 100,
"security": "none"
}
]
},
{
"address": "HKT.vjsun.com",
"port": 443,
"users": [
{
"id": "4d5328da-0a77-4ee3-b5af-91bbbbd8e75S",
"alterId": 64,
"security": "none"
}
]
},
{
"address": "JP.vjsun.com",
"port": 443,
"users": [
{
"id": "fe079348-f0bf-4c74-acc7-39adba442f6d",
"alterId": 100,
"security": "none"
}
]
}
],
"servers": null
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"allowInsecure": true,
"serverName": null
},
"tcpSettings": null,
"kcpSettings": null,
"wsSettings": {
"connectionReuse": true,
"path": "/ray",
"headers": null
},
"httpSettings": null
},
"mux": {
"enabled": false
}
},
"inboundDetour": null,
"outboundDetour": [
{
"protocol": "freedom",
"settings": {
"response": null
},
"tag": "direct"
},
{
"protocol": "blackhole",
"settings": {
"response": {
"type": "http"
}
},
"tag": "blockout"
}
],
"dns" : {
"servers" : [
"119.29.29.29",
"223.5.5.5",
"1.0.0.1"
]
},
"routing": {
"strategy": "rules",
"settings": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10"
],
"outboundTag": "direct"
},
{
"type": "chinasites",
"outboundTag": "direct"
},
{
"type": "chinaip",
"outboundTag": "direct"
}
]
}
}
}
Windows:
Windows上如果用图形界面的v2rayN工具,那么需要从主界面点击“服务器” > “添加自定义配置服务器”
在电脑上选择配置文件的位置,添加进去后,v2rayN主界面上会显示自定义服务器
Android:
Android手机假如用v2rayNG,添加方法如下: 点击加号,选择“从本地导入自定义配置”
可以直接在v2ray配置文件的routing部分直接编写路由规则,比如去广告,直连网址,代理网址等等规则,都通过v2ray内置的路由来分配。