利用Nginx/Haproxy实现V2ray+ws+Tls多落地VPS负载均衡

利用Nginx/Haproxy实现V2ray+ws+Tls多落地VPS负载均衡

1:准备工具:国外VPS选购三台分别用三个域名进行解析好其IP地址;准备国内NAT或VDS中转机一台;

2:在国外VPS上分别安装V2ray+ws+tls节点:
这里直接用wulabing onekey安装:

1
wget -N --no-check-certificate -q -O install.sh "https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/master/install.sh" && chmod +x install.sh && bash install.sh

3:安装完成获取配置后对三台国外VPS进行配置修改;原则为UUID、alterID、路径参数皆需一致
配置修改时要注意须停止Nginx和V2ray服务
3.1修改Nginx配置:vi /etc/nginx/conf/conf.d/v2ray.conf
将里面的location路径修改成一致
3.2修改V2ray配置
vi /etc/v2ray/config.json
修改里面的path
以上修改完成后须重新启动V2ray和Nginx
相关启动命令如下:

1
2
systemctl start v2ray
systemctl start nginx

相关停止命令

1
2
systemctl stop nginx
systemctl stop v2ray

2:在国内NAT/VDS上安装nginx 这里用centos7系统:

1
2
3
4
yum -y install nginx
echo "include /etc/nginx/tcpconf.d/*.conf;" >> /etc/nginx/nginx.conf
mkdir -p /etc/nginx/tcpconf.d
vi /etc/nginx/tcpconf.d/proxy.conf

3:写入如下配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
stream {

upstream v2ray {
server 1.1.1.1:443 weight=1;
server 1.1.1.2:443 weight=3;
server 1.1.1.3:443 weight=5;
}

server {
listen 5678;
listen 5678 udp;
proxy_pass v2ray;
}

}

4:开启Nginx同时检查Nginx运行状态

1
systemctl start nginx & systemctl status nginx

5:关闭防火墙

1
2
systemctl stop firewalld
systemctl disable firewalld

6:关闭SELinux

1
2
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

7:配置客户端即可使用

http://ip111.cn/

IP轮询效果查看

拓展:Haproxy负载均衡:

yum -y install haproxy

vi /etc/haproxy/haproxy.cfg

配置文件如下:

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
global
log /dev/log local0
log /dev/log local1 notice
user root
group root
daemon

defaults
log global
mode tcp
timeout connect 5s
timeout client 5s
timeout server 5s
option dontlognull
option redispatch
retries 3

listen status
bind *:1111
mode http
stats refresh 30s
stats uri /status
stats realm Haproxy
stats auth admin:admin
stats hide-version
stats admin if TRUE

frontend shadowsocks-in
mode tcp
bind *:8388
default_backend shadowsocks-out

backend shadowsocks-out
mode tcp
option tcp-check
balance roundrobin
server v1 a.com:443 check
server v2 b.com:443 check
server v3 c.com:443 check

service haproxy start
systemctl status haproxy.service
systemctl start haproxy
systemctl enable haproxy

TG交流群

支付宝收款签约

年付81元G口VPS

SiemensTutorials

VTURAY网络加速

亚马逊测评资源网|

美国住宅动态