hdfs、yarn、hbase這些組件的master支持多個,實現自動主備切換,其中hdfs、hbase不管訪問主master或者備master均可以正常訪問頁面,可是yarn比較特別,只有主master的頁面能夠訪問,備master會返回Refresh,3s後重定向;html
一種方式是提供兩個域名,分別對應兩個yarn的master,一旦有master切換,須要手工切換到另一個,有沒有更好的方式?nginx
訪問備master過程以下:git
curl http://standby_ip:8088/cluster -vgithub
* About to connect() to standby_ip port 8088 (#0)curl
* Trying standby_ip...ide
* Connected to standby_ip (standby_ip) port 8088 (#0)url
> GET /cluster HTTP/1.1code
> User-Agent: curl/7.29.0server
> Host: standby_ip:8088htm
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Expires: Tue, 25 Sep 2018 03:59:22 GMT
< Date: Tue, 25 Sep 2018 03:59:22 GMT
< Pragma: no-cache
< Expires: Tue, 25 Sep 2018 03:59:22 GMT
< Date: Tue, 25 Sep 2018 03:59:22 GMT
< Pragma: no-cache
< Content-Type: text/plain; charset=UTF-8
< Refresh: 3; url=http://active_ip:8088/cluster
< Content-Length: 103
< Server: Jetty(6.1.26)
<
This is standby RM. Redirecting to the current active RM: http://active_ip:8088/cluster
* Connection #0 to host standby_ip left intact
可見備master響應http status爲200,包含Refresh頭,同時body爲This is standby RM. Redirecting to the current active RM:***
有沒有可能在load balancer(好比nginx)上配置實現自動切換?這裏非法響應須要判斷header包含‘Refresh’或者判斷body包含‘This is standby RM’
1)被動切換,支持http status以及timeout等判斷,不知足
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;
2)主動健康檢查,最經常使用的開源module,只支持http status級別的健康檢查,不知足
https://github.com/yaoweibin/nginx_upstream_check_module
check_http_expect_alive
syntax: *check_http_expect_alive [ http_2xx | http_3xx | http_4xx |
http_5xx ]*
default: *http_2xx | http_3xx*
context: *upstream*
description: These status codes indicate the upstream server's http
response is ok, the backend is alive.
3)nginx收費版本的ngx_http_upstream_hc_module,支持header和body的判斷,能夠知足
Dynamically configurable group with periodic health checks is available as part of our commercial subscription:
http://nginx.org/en/docs/http/ngx_http_upstream_hc_module.html
match active {
body !~ "This is standby RM";
}