호스트 이름이 서로 다른 여러 실행 중인 서버 간의 로드 밸런싱이 필요합니다. 각각에 동일한 가상 호스트를 설정할 수 없습니다.
여러 서버에 하나의 청취 구성만 갖고 상태 확인에서 지시문을 적용할 수 있습니까 http-send-name-header Host
? HAProxy 1.5를 사용하고 있습니다.
보시다시피 저는 이 작동하는 haproxy.cfg를 생각해 냈습니다. 상태 확인이 http-send-name-header Host
. 나는 변수나 다른 방법을 사용하고 일을 더 간결하게 유지하는 것을 선호했습니다.
global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000
stats enable
stats uri /haproxy?stats
stats refresh 5s
balance roundrobin
option httpclose
listen inbound :80
option httpchk HEAD / HTTP/1.1\r\n
server instance1 127.0.0.101 check inter 3000 fall 1 rise 1
server instance2 127.0.0.102 check inter 3000 fall 1 rise 1
listen instance1 127.0.0.101:80
option forwardfor
http-send-name-header Host
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.example.com
server www.example.com www.example.com:80 check inter 5000 fall 3 rise 2
listen instance2 127.0.0.102:80
option forwardfor
http-send-name-header Host
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.bing.com
server www.bing.com www.bing.com:80 check inter 5000 fall 3 rise 2
답변1
defaults
log global
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000
listen any-name-1
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname IpAddress:port check
listen any-name-2
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostanme IpAddress:port check
listen any-name-3
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname IpAddress:port check
listen any-name-4
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname IpAddress:port check
listen any-name-5
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname IpAddress:port check
listen haproxyadmin
bind HAproxyServerIP:HaproxyPort
mode http
stats enable
stats uri /haproxy
stats realm Strictly\ Private
stats auth username:password
답변2
업데이트: 설명하신 경우 하드코딩된 호스트 이름이 필요한 HTTP/1.1 검사가 필요합니다. 버전 1.5의 문서를 보면 http 검사를 삭제할 여유가 없다면(물론 일반적으로 권장되지 않음) 이를 피할 수 있는 방법은 없는 것 같습니다.
원래 답변: 나는 haproxy의 1.5 변경 사항에 익숙하지 않지만 1.4에서 수행할 작업은 다음과 같습니다(1.5에도 여전히 적용된다고 확신합니다). 프론트엔드/백엔드 분리는 개인적인 편의를 위한 것일 뿐이므로 듣기만 사용할 수도 있습니다.
defaults
mode http
option httplog
timeout connect 5000
timeout client 10000
timeout server 10000
frontend inbound
bind 127.0.0.1:8000
default_backend webservers
backend webservers
option forwardfor
option httpchk HEAD / HTTP/1.0
http-send-name-header Host
server google www.google.com:80 check inter 5000 fall 3 rise 2
server bing www.bing.com:80 check inter 5000 fall 3 rise 2
결과는 다음과 같습니다.
$ curl -i localhost:8000
HTTP/1.1 301 Moved Permanently
Cache-Control: no-cache
Content-Length: 0
Location: http://www.bing.com/
Server: Microsoft-IIS/8.0
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: _HOP=I=1&TS=1399981378; path=/
Edge-control: no-store
X-MSEdge-Ref: Ref A: 26CEE14531BF45EFAC91FAC3D1945EDF Ref B: 42CE8D142D427C30F7851B56F38837A6 Ref C: Tue May 13 04:42:58 2014 PST
Date: Tue, 13 May 2014 11:42:57 GMT
$ curl -i localhost:8000
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Tue, 13 May 2014 11:43:00 GMT
Expires: Thu, 12 Jun 2014 11:43:00 GMT
Cache-Control: public, max-age=2592000
Server: sffe
Content-Length: 219
X-XSS-Protection: 1; mode=block
Alternate-Protocol: 80:quic
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
$