繁体   English   中英

Haproxy 总是报 503 服务不可用

[英]Haproxy always giving 503 Service Unavailable

我已经在 Kubernetes 容器上安装了 Haproxy 1.8。

每当我向 /test 发出任何请求时,我总是会收到 503 Service Unavailable 响应。 当我收到对 /test 的请求时,我想返回统计信息页面

以下是我的配置文件:

/etc/haproxy/haproxy.cfg:

global
        daemon
        maxconn 256

defaults
        mode http
        timeout connect 15000ms
        timeout client 150000ms
        timeout server 150000ms

frontend stats
        bind *:8404
        mode http
        stats enable
        stats uri /stats
        stats refresh 10s

frontend http-in
        bind *:8083
        default_backend servers
        acl ar1 path -i -m sub /test
        use_backend servers if ar1

backend servers
        mode http
        server server1 10.1.0.46:8404/stats maxconn 32
        # 10.1.0.46 is my container IP

我可以使用以下方式访问/stats页面:

curl -ik http://10.1.0.46:8404/stats

但是当我这样做时:

curl -ik http://10.1.0.46:8083/test

我总是得到以下回应:

HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Content-Type: text/html

<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>

我开始使用 haproxy:

/etc/init.d/haproxy restart

然后使用以下命令重新启动它:

haproxy -f haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid) 

以下是netstat -anlp

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      54/python3.5
tcp        0      0 0.0.0.0:8083            0.0.0.0:*               LISTEN      802/haproxy
tcp        0      0 0.0.0.0:8404            0.0.0.0:*               LISTEN      802/haproxy
tcp        0      0 10.1.0.46:8404          10.0.15.225:20647       TIME_WAIT   -
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path

以下是ps -eaf的 output :

UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Jul22 ?        00:00:00 /bin/sh -c /bin/bash -x startup_script.sh
root           6       1  0 Jul22 ?        00:00:00 /bin/bash -x startup_script.sh
root          54       6  0 Jul22 ?        00:00:09 /usr/local/bin/python3.5 /usr/local/bin/gunicorn --bind 0.0.0.0:5000 runner:app?
root          57      54  0 Jul22 ?        00:02:50 /usr/local/bin/python3.5 /usr/local/bin/gunicorn --bind 0.0.0.0:5000 runner:app?
root          61       0  0 Jul22 pts/0    00:00:00 bash
root         739       0  0 07:02 pts/1    00:00:00 bash
root         802       1  0 08:09 ?        00:00:00 haproxy -f haproxy.cfg -p /var/run/haproxy.pid -sf 793
root         804     739  0 08:10 pts/1    00:00:00 ps -eaf

为什么我总是得到 503 不可用?

为什么在 2.2.x 已经存在时使用 HAProxy 1.8?

您将需要采用无法在服务器级别设置的后端路径。

backend servers
  mode http
  http-request set-path /stats
  server server1 10.1.0.46:8404 maxconn 32
  # 10.1.0.46 is my container IP

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM