利用Nginx实现流量中转和节点负载均衡

利用Nginx进行流量中转并实现负载均衡-一种解决断流方案

食用工具:NAT机一台;VPS(ABC)3台;视频中采用系统镜像为:centOS7
【注意:搭建之前可以对你的VPS进行域名绑定;特别是动态VPS的必须用域名进行中转】

1:关闭所有VPS的防火墙

1
2
systemctl stop firewalld.service
systemctl disable firewalld.service

2:在NAT机上安装Nginx

1
yum install -y epel-release && yum install -y nginx

3:启动Nginx

1
systemctl start nginx.service

4:新建tcp.d文件夹并在文件夹中创建转发配置文件

1
2
mkdir /etc/nginx/tcp.d/
vi /etc/nginx/tcp.d/zf.conf

5:输入配置信息;示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
stream{
upstream tcpssh {
server IP(域名A):端口;
server IP(域名B):端口;
server IP(域名C):端口;
}
server{
listen NAT/VPS外部端口;
listen NAT/VPS外部端口 udp;
proxy_pass tcpssh;
}
}

6:修改Nginx配置文件

1
2
cd /etc/nginx/
vi nginx.conf

并在配置文件中添加以下内容

1
include /etc/nginx/tcp.d/*.conf;

7:利用用 nginx -t 命令可以检查配置是否成功

8:设置开机启动nginx

1
systemctl enable nginx && systemctl start nginx

9:查看Nginx运行状态

1
ss -ntlp| grep -i nginx

10:若有需要须重启Nginx运行如下命令

1
2
systemctl restart nginx
service nginx restart

11:若要定时重启可添加定时任务
执行 crontab -e命令

1
0 */12 * * * systemctl restart nginx

TG交流群

支付宝收款签约

年付81元G口VPS

SiemensTutorials

VTURAY网络加速

亚马逊测评资源网|

美国住宅动态