2015-03-25 65 views
5

我不確定是否遺漏了一些關鍵配置,或者只是從根本上誤解了強制保留haproxy的目的(在Ubuntu 14.04上使用版本1.5.11) 。從文檔:haproxy的工作配置與持久性設置

的「力堅持」語句允許一個申報各種基於ACL 條件,滿足時,會引起請求忽視的 向下狀態的服務器仍嘗試連接到它。這樣可以啓動 服務器,仍然對運行狀況檢查回覆錯誤,並運行配置的瀏覽器來測試該服務。

這聽起來像是正是我想要的行爲,在那裏我可以把所有的應用程序服務器整合到「維護模式」爲代碼部署,但允許某些IP地址仍然爲了測試一下連接,-推出後,然後再給每個人訪問權限。下面是我的配置已經設置了:

global 
    log /dev/log local0 
    log /dev/log local1 notice 
    chroot /var/lib/haproxy 
    stats socket /run/haproxy/admin.sock mode 660 level admin 
    stats timeout 30s 
    user haproxy 
    group haproxy 
    daemon 

    # Default SSL material locations 
    ca-base /etc/ssl/certs 
    crt-base /etc/ssl/private 

    # Default ciphers to use on SSL-enabled listening sockets. 
    # For more information, see ciphers(1SSL). 
    ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL 
    ssl-default-bind-options no-sslv3 

defaults 
    log global 
    mode http 
    option httplog 
    option dontlognull 
    timeout connect 300s 
    timeout client 50000 
    timeout server 50000 
    errorfile 400 /etc/haproxy/errors/400.http 
    errorfile 403 /etc/haproxy/errors/403.http 
    errorfile 408 /etc/haproxy/errors/408.http 
    errorfile 500 /etc/haproxy/errors/500.http 
    errorfile 502 /etc/haproxy/errors/502.http 
    errorfile 503 /etc/haproxy/errors/503.http 
    errorfile 504 /etc/haproxy/errors/504.http 

listen mysite 
    bind *:80 
    bind *:443 ssl crt mysite.pem 
    http-request set-header X-Forwarded-Port %[dst_port] 
    http-request add-header X-Forwarded-Proto https if { ssl_fc } 
    redirect scheme https if !{ ssl_fc } 
    balance roundrobin 
    option forwardfor 
    option httpchk HEAD /haproxy_health_check.php 
    acl whitelist src -f /etc/haproxy/whitelist.lst 
    force-persist if whitelist 
    server app-1 10.1.4.32:80 maxconn 20 check inter 10000 

有了這個配置,我認爲我應該能夠發出以下命令:

echo "disable server mysite/app-1" | socat /run/haproxy/admin.sock stdio 

採取單一的應用程序服務器進行旋轉,只要我來自/etc/haproxy/whitelist.lst中列出的IP地址,我仍然應該能夠看到網站,就好像服務器仍然處於啓用狀態。然而,我最終看到的是503錯誤頁面,如果我是普通用戶,通常我會期望它,但不是來自列入白名單的IP。要刪除我被錯誤地指定的IP地址,或者使用acl命令錯誤的可能性,我嘗試了變化,在這裏我簡單的設置:

force-persist if TRUE 

從我的文檔閱讀,我認爲這會就好像我從來不會禁用服務器,不管我來自哪個IP。不幸的是,我仍然得到了503.

有更笨拙的方式,包括通過額外的配置和重新加載haproxy,我可以用它來實現這個工作,但「強制持久」,以及方便的通過命令禁用的能力線似乎是一個更優雅的方法,如果我能使它工作,我肯定會更喜歡它。

有沒有其他人試圖讓haproxy以這種方式工作?以這種方式解釋「強制持久」是否是錯誤的?我需要一些額外的配置才能使它工作嗎?

+1

你解決了嗎?我有同樣的問題。 – 2016-12-19 18:24:30

+0

@CosmicOssifrage查看Willy Tareau的答案。 – 2018-02-20 18:40:03

回答

4

沒有規定指出在此配置中要堅持的內容。通常你會使用這種結合基於cookie的持久性。例如:

cookie SERVERID insert indirect nocache 
server srv1 1.1.1.1:80 cookie s1 check 
server srv2 2.2.2.2:80 cookie s2 check 
acl from_management_net src 10.0.0.0/8 
force-persist if from_management_net 

那麼你的客戶端上,訪問的第一個服務器,獲得分配的cookie,關閉服務器,並再次訪問它,你會繼續去那裏。通常,人們會實施一個特定的HTML頁面,列出所有服務器及其各自的cookie,這些服務器只需點擊它們即可幫助客戶選擇服務器。