HAproxy 503 服務不可用 沒有伺服器可以處理此請求

HAproxy 503 服務不可用 沒有伺服器可以處理此請求

我是這個負載平衡場景的新手,我的任務是找出如何讓這個負載平衡發揮作用。

我的環境:

Centos 6.4 64 Bit
Webserver: Lighttpd
All running in ESXI
virtual IP: 192.168.1.6
LB1: 192.168.1.4
LB2: 192.168.1.5
Webserver 1: 192.168.1.12
Webserver 2: 192.168.1.13
Gateway: 192.168.1.1

嘗試在生產之前使用 HAproxy 和 keepalived 在實驗室中執行測試。這是我的 keepalived 設定:

! keepalived 的設定檔

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.1.4
   smtp_connect_timeout 30
   router_id 192.168.1.1
}

vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 1                     # check every second
weight 2                       # add 2 points of prio if OK
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101  #priority 101 for master
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.6

    }

    track_script {
    chk_haproxy
            }

            }

這是我對 HAproxy 的設置

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    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                    http
    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

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
#    acl url_static       path_beg       -i /static /images /javascript /stylesheets
#    acl url_static       path_end       -i .jpg .gif .png .css .js

#    use_backend static          if url_static
#    default_backend             view

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
#backend static
#    balance     roundrobin
#    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
mode tcp
    balance     roundrobin
    server  server1 192.168.1.12:80 check inter 2000 rise 2 fall 5
    server  server2 192.168.1.13:80 check inter 2000 rise 2 fall 5

當我啟動 HAproxy 時,我收到了這個錯誤,但我不太確定從哪裡開始修復它。也許做過很多次這樣的人可以幫助我闡明一些觀點?

503 Service Unavailable No server is available to handle this request. 

但是,手動連接到 webserver1 和 webserver2 效果很好。

我想要的只是為位於 HAproxy 後面的網路伺服器提供一個簡單的負載平衡。任何意見或建議都絕對值得讚賞。請幫忙?非常感謝。

答案1

我從未使用過 HAproxy,但快速搜尋讓我認為您需要default_backend app立即在下面添加frontend main *:80。我在該配置中看不到將後端和前端連接在一起的地方。

答案2

問題出在您的 HAProxy 配置。當我從您的配置中刪除所有註釋時,我將得到以下資訊:

global
  log         127.0.0.1 local2

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

  stats socket /var/lib/haproxy/stats

defaults
  mode                    http
  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

frontend  main *:80

backend app
  mode tcp
  balance roundrobin
  server  server1 192.168.1.12:80 check inter 2000 rise 2 fall 5
  server  server2 192.168.1.13:80 check inter 2000 rise 2 fall 5

現在你可以清楚地看到前端根本沒有配置。請求透過 HAProxy 到達,frontend main但 HAProxy 不知道哪些伺服器可以可靠地處理它,因此將傳回 503。

您必須使用default_backendacl 將後端連結到前端。

您也應該使用 stats,不僅可以使用套接字,還可以使用受保護的 Web 介面。我可以向您展示有關 haproxy 背後的集群的信息,哪些伺服器離線,哪些伺服器有任何問題,有關響應時間等。對於調試非常有用。

答案3

我遇到了類似的錯誤,因為 HAProxy 認為我的後端由於預設的運行狀況檢查而關閉。我禁用了健康檢查,503 就消失了。

我正在使用 pfsense GUI: 在此輸入影像描述

答案4

當您使用 TLS 憑證時,預設情況下 PFSense 會自動(有些不可見)新增附加 ACL。我使用“其他證書”部分添加了第二個虛擬主機和第二個證書。這保留了預設證書 ACL。

停用這些 ACL 並重新啟動就可以了。

在此輸入影像描述

相關內容