使用不同端口时,HAproxy 找不到后端

使用不同端口时,HAproxy 找不到后端

我有两个后端,它们是同一台服务器,运行两个相同的 Docker 映像,但每个映像的端口不同。也就是说,在后端服务器上,两者之间唯一的不同就是端口映射。我的负载均衡器 (HAProxy) 是位于 10.0.0.2 的独立物理机器。

frontend http-in
    bind *:80
    bind *:443 ssl crt /etc/ssl/mydomain.com/both.pem
    http-request redirect scheme https unless { ssl_fc }

    acl eighty_http        hdr(host)     -m beg -i eighty.
    acl eightyhundred_http        hdr(host)     -m beg -i eightyhundred.

    use_backend eighty if eighty_http
    use_backend eightyhundred if eightyhundred_http

backend eighty
    server      twenty 10.0.0.20:80 check maxconn 300

backend eightyhundred
    server      twenty 10.0.0.20:8000 check maxconn 300

当我使用 sudo systemctl restart haproxy 时,它告诉我“后端 eightyhundred 没有可用的服务器!”但是,我可以从负载均衡器成功 curl 两个端口。

我在 iptables 中输入了以下内容:

sudo iptables -A OUTPUT -p tcp -d 10.0.0.0/16 --sport 8000 -j ACCEPT

...对于 selinux:

sudo semanage port --add --type http_port_t --proto tcp 8000

两者都没有什么区别。

我在这里遗漏了什么?

答案1

简而言之,问题在于您不能随机选择一个端口用于后端。在这里,8000 已经添加到 soundd_port_t,而 haproxy 不属于该组。因此,“sudo semanage port --add --type http_port_t --proto tcp 8000”无法实现此处的预期目的。当它说这个端口已经添加(它已经添加到其他端口)时,它实际上无法完成您认为它可能完成的任务。简单的解决方案是选择 HAProxy 可以访问的端口。这个人对此进行了最好的解释:

https://unix.stackexchange.com/questions/363878/which-selinux-policies-apply-to-haproxy

相关内容