openresty upstream健康检查,Lua代码实现:
resty.upstream.healthcheck
#lua_shared_dict healthcheck 1m;
#lua_socket_log_errors off;
#init_worker_by_lua_block {
# local hc = require "resty.upstream.healthcheck"
# local ok, err = hc.spawn_checker {
# shm = "healthcheck",
# upstream = "rp_10_10_10_10_80cn",
# type = "http",
# http_req = "GET /status HTTP/1.0\r\nHost: rp_10_10_10_1-0_80cn\r\n\r\n",
# interval = 2000,
# timeout = 3000,
# fall = 3,
# rise = 2,
# valid_statuses = {200, 302, 404},
# concurrency = 10,
# }
# if not ok then
# ngx.log(ngx.ERR, "=======> failed to spawn health checker: ", err)
# return
# end
#}
#location /status {
# access_log off;
# default_type text/plain;
# content_by_lua_block {
# local hc = require "resty.upstream.healthcheck"
# ngx.say("Nginx Worker PID: ", ngx.worker.pid())
# ngx.print(hc.status_page())
# }
#}