1、安装 haproxy:

yum install -y haproxy

2、编辑 haproxy 配置文件:

vi /etc/haproxy/haproxy.cfg

3、加入以下配置:

global
    maxconn 128
defaults
    mode http
    option httplog
    log global
    timeout connect 10s
    timeout client 60s
    timeout server 60s
frontend http
    bind *:80
    default_backend nodes
backend nodes
    balance roundrobin
    server node1 xx.xx.xx.xx:80 check
    server node2 yy.yy.yy.yy:80 check

4、启动 haproxy:

systemctl start haproxy

5、设置开机自启:

systemctl enable haproxy

6、开启路由转发功能:

vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p

7、设置 nat 转发:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination xx.xx.xx.xx:80
iptables -t nat -A POSTROUTING -j SNAT --to-source yy.yy.yy.yy

8、保存 nat 转发规则:

service iptables save

9、重新加载 nat 转发规则:

service iptables restart
Centos 7 VPS 路由优化:利用好线路,提升网络速度

原文地址: https://www.cveoy.top/t/topic/lom2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录