Haproxy

如何避免在 Haproxy 中對同一台伺服器進行重複的健康檢查?

  • March 11, 2019

以下配置文件按預期工作,但對相同的代理伺服器進行重複的健康檢查,我怎樣才能避免這種重複的健康檢查?(我仍然想做健康檢查但不重複健康檢查)

global
   external-check
defaults
   option httplog
   log 127.0.0.1:514 user
   timeout connect 5000s
   timeout client 5000s
   timeout server 5000s
#Close the using connection when backend server marked as down
listen main-proxy1
   bind 127.0.0.1:8079
   mode http
   option external-check
   external-check command /checker
   balance static-rr
   server proxy1 127.0.0.1:9999 check on-marked-down shutdown-sessions on-marked-up shutdown-backup-sessions
#Don't close the using connection when backend server marked as down
listen main-proxy2
   bind 127.0.0.1:8080
   mode http
   option external-check
   external-check command /checker
   balance static-rr
   server proxy2 127.0.0.1:9999 check

您可以使用該track指令來跟踪另一台伺服器的狀態。在您的情況下,第二server行將是:

server proxy2 127.0.0.1:9999 track main-proxy1/proxy1

我認為解決這個問題最簡單的方法是定義一個前端和一個後端:

例子:

frontend www.mysite.com
   bind 10.0.0.3:80
   bind 10.0.0.3:443 ssl crt /etc/ssl/certs/mysite.pem
   http-request redirect scheme https unless { ssl_fc }
   use_backend api_servers if { path_beg /api/ }
   default_backend web_servers

backend web_servers
   balance roundrobin
   cookie SERVERUSED insert indirect nocache
   option httpchk HEAD /
   default-server check maxconn 20
   server server1 10.0.1.3:80 cookie server1
   server server2 10.0.1.4:80 cookie server2

您將在後端進行執行狀況檢查,現在您可以將同一個後端用於多個前端。

引用自:https://serverfault.com/questions/957144