![]()
upstream ats_servers {
server 192.168.1.211:80;
server 192.168.1.212:80;
consistent_hash $host$request_uri;
}
init_worker_by_lua_block {
local hc = require "resty.upstream.healthcheck"
local ok, err = hc.spawn_checker{
shm = "healthcheck", -- defined by "lua_shared_dict"
upstream = "ats_servers", -- defined by "upstream"
type = "http",
http_req = "GET /status HTTP/1.0\r\nHost: foo.com\r\n\r\n",
-- raw HTTP request for checking
interval = 2000, -- run the check cycle every 2 sec
timeout = 1000, -- 1 sec is the timeout for network operations
fall = 3, -- # of successive failures before turning a peer down
rise = 2, -- # of successive successes before turning a peer up
valid_statuses = {200, 302}, -- a list valid HTTP status code
concurrency = 10, -- concurrency level for test requests
}
if not ok then
ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
return
end
}
如上是我的配置,一致性hash模块来自https://www.nginx.com/resources/wiki/modules/consistent_hash/,单独使用没问题,和resty.upstream.healthcheck一起使用时worker启动时会coredump,起不来,gdb调试如下:
![]()