【问题标题】:HAProxy Loadbalancing TCP trafficHAProxy 负载平衡 TCP 流量
【发布时间】:2016-12-25 06:31:32
【问题描述】:

使用 HAProxy,我正在尝试 (TCP) 负载平衡 Rserve(在 TCP 套接字中侦听以调用 R 脚本的服务)在 2 个节点的端口 6311 上运行。

下面是我的配置文件。当我运行 HAProxy 时,它的统计没有任何问题。但是当我连接到平衡节点时,出现错误。配置有什么问题吗?

Handshake failed: expected 32 bytes header, got -1

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    tcp
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    #option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000


listen haproxy_rserve
        bind *:81
        mode tcp
        option tcplog
        timeout client  10800s
        timeout server  10800s
        balance leastconn
        server rserve1 rserveHostName1:6311
        server rserve2 rserveHostName2:6311

listen stats proxyHostName:8080
    mode http
    stats enable
    stats realm Haproxy\ Statistics 
    stats uri /haproxy_stats
    stats hide-version
    stats auth admin:password

也尝试了以下前端-后端平衡方式。结果相同。

frontend haproxy_rserve
    bind *:81
    mode tcp
    option tcplog
    timeout client  10800s
    default_backend rserve

backend rserve
    mode tcp
    option tcplog
    balance leastconn
    timeout server  10800s  
    server rserve1 rserveHostName1:6311
    server rserve2 rserveHostName2:6311 

【问题讨论】:

    标签: tcp load-balancing haproxy rserve


    【解决方案1】:

    在为负载平衡 R 的解决方案苦苦挣扎一周后,下面的(完全免费/开源软件堆栈)解决方案奏效了。

    如果更多人提到这个,我会发布一个关于安装到配置的详细博客。

    能够使用以下配置对通过 HAProxy TCP 负载平衡器传入 Rserve 的 R 脚本请求进行负载平衡。与问题部分中的配置非常相似,但前端和后端是分开的。

    #Load balancer stats page access at hostname:8080/haproxy_stats
    listen stats <load_balancer_hostname>:8080
        mode http
        log global
        stats enable
        stats realm Haproxy\ Statistics 
        stats uri /haproxy_stats
        stats hide-version
        stats auth admin:admin@rserve
    
    frontend rserve_frontend
        bind *:81
        mode tcp
        option tcplog
        timeout client  1m
        default_backend rserve_backend
    
    backend rserve_backend
        mode tcp
        option tcplog
        option log-health-checks
        option redispatch
        log global
        balance roundrobin
        timeout connect 10s
        timeout server 1m   
        server rserve1 <rserve hostname1>:6311 check
        server rserve2 <rserve hostname2>:6311 check
        server rserve2 <rserve hostname3>:6311 check
    

    关键是使用以下命令为 HAproxy 启用远程连接(大部分情况下没有明确的文档)

    /usr/sbin/setsebool -P haproxy_connect_any 1
    

    还要确保使用 Rserve 配置文件中的“启用远程”参数在 Rserve 中启用远程连接。

    【讨论】:

    • 嗨 - 这很有趣。你为什么不使用 nginx ?由于我们大多数人都使用 nginx,因此在那里看到解决方案会非常酷。请注意,nginx 支持 tcp(使用流和/或代理协议)
    • @Sandeep 没有不使用 nginx 的具体原因。发现 haproxy 是反向代理专有的,并且几十年来都做得很好,我不需要 nginx 提供的任何其他东西(比如 web 服务器)。是的。我们可以只使用反向代理的一部分。但刚刚和 haproxy 安定下来。
    • @Sandeep 这里是 nginx 实现 TCP 负载均衡的例子。 nginx.com/resources/admin-guide/tcp-load-balancing
    • @Sandeep 我们目前使用 nginx 进行 tcp 反向代理,但正在寻求切换到 HAProxy,因为 nginx 只有被动健康检查,除非您升级到 nginx+。当 HAProxy 免费提供时,我们并不热衷于每年支付 2.5k。
    • @MichaelHobbs 除了目前的研究之外,没有使用它的经验,但它(HAProxy)在负载平衡能力方面确实看起来很有前途。内置的统计页面确实非常好。
    猜你喜欢
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    相关资源
    最近更新 更多