haproxy均衡负载v2ray

安装: yum install haproxy

关闭防火墙和selinux[]:
https://www.cnblogs.com/caicaizi/p/9564754.html

# 允许某个端口通过防火墙
firewall-cmd --permanent --zone=public --add-port=8881/tcp
firewall-cmd --reload

https://tylersguides.com/guides/installing-haproxy-from-source-on-centos-7/

参考链接:

高可用的py检测:

nginx转发socks5:
https://sulangsss.github.io/2017/10/18/Nginx/forward-socts5/

systemctl list-unit-files|grep firewalld.service #查看防火墙状态
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

查看防火墙状态
firewall-cmd --state

停止firewall
systemctl stop firewalld.service

禁止firewall开机启动
systemctl disable firewalld.service 

haproxy配置:
/etc/haproxy/haproxy.conf

  • 启动:systemctl start haproxy
  • 重启:systemctl restart haproxy
  • 查看状态: systemctl status haproxy
global
    daemon
    maxconn 256
    user        haproxy
    group       haproxy
    chroot      /var/lib/haproxy

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend v2ray-in
    bind 0.0.0.0:10888
    mode socks
    default_backend servers

backend servers
    server server1 192.168.1.102:10808
    server server2 192.168.1.180:10808
    mode socks
    balance roundrobin

listen  admin_stats
        bind 0.0.0.0:8887
        mode http
        log 127.0.0.1 local0 err
        stats refresh 30s
        stats uri /haproxy
        stats realm welcome login\ Haproxy
        stats auth admin:admin
        stats hide-version
        stats admin if TRUE

成功的配置:

global

defaults
    log global
    mode tcp
    balance source

    option redispatch      #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
    option abortonclose
    timeout connect 3s
    timeout client 1m
    timeout server 1m

listen status
    bind 0.0.0.0:2008
    mode http
    log global
    stats refresh 2s
    stats uri /
    stats auth admin:123456

frontend main
    bind 0.0.0.0:15555
    default_backend v2ray-server

backend v2ray-server
    mode tcp
    balance roundrobin
    server anaf007 192.168.1.102:10808 check inter 1000 rise 3 fall 2 weight 2
    server ip23 192.168.1.154:10808 check inter 1000 rise 3 fall 2 weight 1

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 anaf@163.com
目录