从软件上 V2Ray 不区分服务器版和客户端版,也就是说在服务器和客户端运行的 V2Ray 是同一个软件,区别只是配置文件的不同。
部署
应用场景
问题:外网无法访问部署在内网的 MySQL,导致 SpringBoot 项目启动时连不上数据库,接口无法调试,开发效率低。
解决:参考以下方式部署 v2ray,然后配置 JVM 参数 -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=18998
部署方案一
在服务器部署 V2Ray 客户端。配置文件如下(更多配置见官网 v2fly):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| { "inbounds": [ { "listen": "0.0.0.0", "port": 8997, "protocol": "socks", "settings": { "auth": "noauth", "accounts": [ { "user": "zhaolq", "pass": "123456789" } ], "udp": true } } ], "outbounds": [ { "protocol": "freedom" } ] }
|
执行 chmod ./v2ray +x
、 ./v2ray run
启动 V2Ray 客户端,可以使用 SwitchyOmega 插件测试 socks 代理是否生效。
注意:
Navicat 不支持 socks 代理,但可以使用 HTTP 隧道。Nginx 配置见 Nginx教程 章节的 常用配置
。具体参考 https://blog.csdn.net/baikunlong/article/details/132596536 。
部署方案二(推荐加密协议)
服务端
在服务器部署 V2Ray 服务端,本地部署客户端。
1 2
| cd /opt/local/ unzip v2ray-linux-64.zip -d ./v2ray-linux-64
|
服务端配置(更多配置见官网 v2fly):
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
| { "log" : { "access": "/opt/local/v2ray-linux-64/log/access.log", "error": "/opt/local/v2ray-linux-64/log/error.log", "loglevel": "warning" }, "inbounds": [ { "port": 8998, "protocol": "vmess", "settings": { "clients": [ { "id": "755bc63b-e26d-47cd-85a1-b6ebbecbbabc" } ] } } ], "outbounds": [ { "protocol": "freedom" } ] }
|
Linux 启动前需授予可执行权限 chmod ./v2ray +x
,然后参考下文 开机自启 。
客户端
客户端配置(更多配置见官网 v2fly):
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
| {
"inbounds": [ { "port": 18998, "listen": "127.0.0.1", "protocol": "socks", "settings": { "udp": true } } ], "outbounds": [ { "protocol": "vmess", "settings": { "vnext": [ { "address": "192.168.0.7", "port": 8998, "users": [ { "id": "755bc63b-e26d-47cd-85a1-b6ebbecbbabc" } ] } ] } }, { "protocol": "freedom", "tag": "direct" } ] }
|
windows启动脚本
1 2 3
| :: 新建文件 v2ray-run.cmd v2ray.exe run pause
|
开机自启
v2ray-linux-64.zip
解压文件中包含 systemd/system/v2ray.service
,需要的选项包括 User、ExecStart 等。
vim /etc/systemd/system/v2ray.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [Unit] Description=V2Ray Service Documentation=https://www.v2fly.org/ After=network.target nss-lookup.target
[Service] User=root Group=root CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE NoNewPrivileges=true ExecStart=/opt/local/v2ray-linux-64/v2ray run -config /opt/local/v2ray-linux-64/config.json Restart=on-failure RestartPreventExitStatus=23
[Install] WantedBy=multi-user.target
|
重新加载配置文件:systemctl daemon-reload