gpt4 book ai didi

tcp - HAProxy 负载均衡 TCP 流量

转载 作者:可可西里 更新时间:2023-11-01 02:30:47 25 4
gpt4 key购买 nike

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

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

握手失败:需要 32 字节 header ,得到 -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

最佳答案

在为负载平衡 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 配置文件中使用“enable remote”参数在 Rserve 中启用远程连接。

关于tcp - HAProxy 负载均衡 TCP 流量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39016291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com