言成言成啊 | Kit Chen's Blog

Qv2ray路由分流与负载均衡

发布于2023-06-02 03:28:38,更新于2023-08-15 21:04:21,标签:qv2ray  文章会持续修订,转载请注明来源地址:https://meethigher.top/blog

一、背景

6月1号,我的代理ChatGPT API失效了。调用API还是蛮划算的,算了一下,大概1¥≈4w汉字(0.002$=1k tokens)。

我在公司内网部署了ChatGPT,这半个月下来,花费了9块左右,也就是36W个汉字左右。

但是没有美国信用卡,因此最终放弃购买API服务了。为了不影响使用GPT,所以研究了下Qv2ray的分流操作。仅针对ChatGPT使用固定的美国代理。

二、配置路由分流与负载均衡

先参考Git配置代理

默认情况下,Qv2ray并不支持V2ray以外的代理协议,因此在作为SS/SSR/Trojan等客户端使用前,需要在Qv2ray中添加相应插件(注意插件版本号和Qv2ray版本号要对应)

Qv2ray Shadowsocks插件下载:https://github.com/Qv2ray/QvPlugin-SS/releases/

Qv2ray SSR插件下载:https://github.com/Qv2ray/QvPlugin-SSR/releases/

Qv2ray Trojan插件下载:https://github.com/Qv2ray/QvPlugin-Trojan/releases

Qv2ray Trojan-go插件下载:https://github.com/Qv2ray/QvPlugin-Trojan-Go/releases/

Qv2ray NaiveProxy插件下载::https://github.com/Qv2ray/QvPlugin-NaiveProxy/releases/

插件安装路径如图

Qv2ray 使用教程

需求

  1. 针对OpenAI官方,使用美国代理
  2. 针对国外部分网站,使用香港代理
  3. 针对国内部分网站,进行代理负载均衡(使用北京、广东,随机规则)
  4. 其他网站,使用直连

我之所以一直使用Qv2ray,除了操作简单,还有个配置可视化,这是我认为优于Clash的地方。直接上配置结果图

上图的配置文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
{
"browserForwarder": null,
"dns": {
"servers": [
]
},
"fakedns": {
"ipPool": "198.18.0.0/15",
"poolSize": 65535
},
"inbounds": [
{
"allocate": {
"concurrency": null,
"refresh": null,
"strategy": "always"
},
"listen": "0.0.0.0",
"port": 1081,
"protocol": "http",
"settings": {
"allowTransparent": true,
"timeout": 300
},
"sniffing": {
"destOverride": [
"http",
"tls",
"fakedns",
"fakedns+others"
],
"enabled": true,
"metadataOnly": null
},
"streamSettings": {
},
"tag": "全局HTTP"
},
{
"allocate": {
"concurrency": null,
"refresh": null,
"strategy": "always"
},
"listen": "0.0.0.0",
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"ip": "127.0.0.1",
"udp": true
},
"sniffing": {
"destOverride": [
"http",
"tls",
"fakedns",
"fakedns+others"
],
"enabled": true,
"metadataOnly": null
},
"streamSettings": {
},
"tag": "全局Socks"
}
],
"observatory": {
"subjectSelector": [
]
},
"outbounds": [
{
"QV2RAY_OUTBOUND_METADATA": {
"displayName": "Freedom_61548124"
},
"mux": {
},
"protocol": "freedom",
"sendThrough": "0.0.0.0",
"settings": {
"domainStrategy": "AsIs",
"redirect": ""
},
"streamSettings": {
},
"tag": "Direct"
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "zhftfzvjdpzd",
"displayName": "北京",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "hahhsrhabtbg",
"displayName": "广东",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "rbqqzesntetk",
"displayName": "美国01-IEPL-倍率1.0",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "cmjocfkpgvmh",
"displayName": "香港01-IEPL-倍率1.0",
"metaType": 1
}
}
],
"routing": {
"balancers": [
{
"selector": [
"北京",
"广东"
],
"strategy": {
"type": "random"
},
"tag": "Balancer"
}
],
"domainStrategy": "",
"rules": [
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "国内特定网站",
"balancerTag": "Balancer",
"domain": [
"api.bilibili.com",
"api.zhihu.com",
"baidubce.com",
"cnblogs.com",
"csdn.net",
"www.zhihu.com"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
},
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "OpenAI",
"domain": [
"chat.openai.com",
"openai.com"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"outboundTag": "美国01-IEPL-倍率1.0",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
},
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "国外特定网站",
"domain": [
"bing.com",
"camunda.io",
"github.com",
"githubassets.com",
"githubusercontent.com",
"gohugo.org",
"google.com",
"googleapis.com",
"googleusercontent.com",
"jsdelivr.net",
"live.com",
"microsoft.com",
"mvnrepository.com",
"office.com",
"office.net",
"openstreetmap.org",
"rawgit.com",
"xn--gmqz83awjh.cc",
"youtube.com"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"outboundTag": "香港01-IEPL-倍率1.0",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
}
]
}
}

三、自用两种模式

3.1 省流模式

省流,顾名思义,想要省流量,就得少用代理。那么这套代理规则应该是这样的。

优点:省流。

缺点:需频繁配置。未配置的路由,就走直连了。像访问youtube等网站,只配置youtube.com走代理,而静态资源一般来自于cdn服务器,如果cdn没配置走代理,一样打不开。因此,就需要频繁配置。

配置文件,即第二项中的配置

常用需代理的网站

1.) 国内网站

1
2
3
4
5
6
api.bilibili.com
api.zhihu.com
baidubce.com
cnblogs.com
csdn.net
www.zhihu.com

2.) 国外网站

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bing.com
camunda.io
github.com
githubassets.com
githubusercontent.com
gohugo.org
google.com
googleapis.com
googleusercontent.com
jsdelivr.net
live.com
microsoft.com
mvnrepository.com
office.com
office.net
openstreetmap.org
rawgit.com
xn--gmqz83awjh.cc
youtube.com

3.2 通用模式

通用模式,就是为了解决省流模式的弊端,但同时流量也就没那么省了。

优点:不用频繁配置路由。

缺点:比较耗费流量。

通过geosite:cn拦截域名路由,进行直连。

通过geoip:private拦截局域网路由,进行直连。

geosite与geoip搭配使用,会导致geoip失效。因此想要使用geoip,需要单独使用。

注意geosite.dat与geoip.dat文件,需要下载更新

配置文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
{
"browserForwarder": null,
"dns": {
"servers": [
]
},
"fakedns": {
"ipPool": "198.18.0.0/15",
"poolSize": 65535
},
"inbounds": [
{
"allocate": {
"concurrency": null,
"refresh": null,
"strategy": "always"
},
"listen": "0.0.0.0",
"port": 1081,
"protocol": "http",
"settings": {
"allowTransparent": true,
"timeout": 300
},
"sniffing": {
"destOverride": [
"http",
"tls",
"fakedns",
"fakedns+others"
],
"enabled": true,
"metadataOnly": null
},
"streamSettings": {
},
"tag": "全局HTTP"
},
{
"allocate": {
"concurrency": null,
"refresh": null,
"strategy": "always"
},
"listen": "0.0.0.0",
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"ip": "127.0.0.1",
"udp": true
},
"sniffing": {
"destOverride": [
"http",
"tls",
"fakedns",
"fakedns+others"
],
"enabled": true,
"metadataOnly": null
},
"streamSettings": {
},
"tag": "全局Socks"
}
],
"observatory": {
"subjectSelector": [
]
},
"outbounds": [
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "shxqmvymidvv",
"displayName": "香港01-IEPL-倍率1.0",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"displayName": "Freedom_61548124"
},
"mux": {
},
"protocol": "freedom",
"sendThrough": "0.0.0.0",
"settings": {
"domainStrategy": "AsIs",
"redirect": ""
},
"streamSettings": {
},
"tag": "Direct"
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "gnjlaakiinjq",
"displayName": "北京_北京",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "cpmytpafbtua",
"displayName": "广东_广东",
"metaType": 1
}
},
{
"QV2RAY_OUTBOUND_METADATA": {
"connectionId": "xydfsynkqtks",
"displayName": "美国01-IEPL-倍率1.0",
"metaType": 1
}
}
],
"routing": {
"balancers": [
{
"selector": [
"北京_北京",
"广东_广东"
],
"strategy": {
"type": "random"
},
"tag": "Balancer"
}
],
"domainStrategy": "",
"rules": [
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "直连局域网",
"inboundTag": [
"全局Socks",
"全局HTTP"
],
"ip": [
"geoip:cn",
"geoip:private"
],
"network": "udp,tcp",
"outboundTag": "Direct",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
},
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "直连域名",
"domain": [
"geosite:cn",
"meethigher.top",
"snipurl.cc"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"outboundTag": "Direct",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
},
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "OpenAI",
"domain": [
"bing.com",
"chat.openai.com",
"openai.com"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"outboundTag": "美国01-IEPL-倍率1.0",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
},
{
"QV2RAY_RULE_ENABLED": true,
"QV2RAY_RULE_TAG": "国内特定网站",
"balancerTag": "Balancer",
"domain": [
"api.bilibili.com",
"api.zhihu.com",
"cnblogs.com",
"csdn.net",
"www.zhihu.com"
],
"inboundTag": [
"全局HTTP",
"全局Socks"
],
"network": "udp,tcp",
"protocol": [
"tls",
"http",
"bittorrent"
],
"type": "field"
}
]
}
}

四、参考致谢

Loyalsoldier/geoip: 🌚 🌍 🌝 GeoIP 规则文件加强版,同时支持定制 V2Ray dat 格式路由规则文件 geoip.dat 和 MaxMind mmdb 格式文件 Country.mmdb。Enhanced edition of GeoIP files for V2Ray, Xray-core, Trojan-Go, Clash and Leaf, with replaced CN IPv4 CIDR available from ipip.net, appended CIDR lists and more.

Loyalsoldier/v2ray-rules-dat: 🦄 🎃 👻 V2Ray 路由规则文件加强版,可代替 V2Ray 官方 geoip.dat 和 geosite.dat,兼容 Shadowsocks-windows、Xray-core、Trojan-Go 和 leaf。Enhanced edition of V2Ray rules dat files, compatible with Xray-core, Shadowsocks-windows, Trojan-Go and leaf.

v2fly/domain-list-community: Community managed domain list. Generate geosite.dat for V2Ray.

发布:2023-06-02 03:28:38
修改:2023-08-15 21:04:21
链接:https://meethigher.top/blog/2023/qv2ray-dispatcher/
标签:qv2ray 
付款码 打赏 分享
Shift+Ctrl+1 可控制工具栏