hi,
最近在尝试用您的lua-resty-upstream-healthcheck,但是发现健康检查一直返回up,似乎检查不起作用,用的是openresty-1.11.2.3里面的lua-resty-upstream-healthcheck-0.04。
我的配置如下:
http段的配置:
http {
.....
upstream teslaServer {
server 10.0.1.75:8001;
server 10.0.1.76:8001;
}
lua_package_path "/opt/dwj/App/nginx/nginx/lua-resty-upstream-healthcheck/lib/?.lua;;";
# the size depends on the number of servers in upstream {}:
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", -- defined by "lua_shared_dict"
upstream = "teslaServer", -- defined by "upstream"
type = "http",
http_req = "GET /status HTTP/1.0\r\nHost: tesla2.maihaoche.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 = {500, 403}, -- 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
-- Just call hc.spawn_checker() for more times here if you have
-- more upstream groups to monitor. One call for one upstream group.
-- They can all share the same shm zone without conflicts but they
-- need a bigger shm zone for obvious reasons.
}
}
server段的配置:
server {
server_name tesla2.maihaoche.com;
listen 80 ;
listen [::]:80 ;
#access_log /etc/nginx/logs/tesla.maihaoche.com.access.log main;
#error_log /etc/nginx/logs/tesla.maihaoche.com.error.log;
#rewrite ^/$ /index.htm last;
location / {
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header CLIENT_IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
client_max_body_size 5000m;
proxy_pass_header User-Agent;
proxy_pass http://teslaServer;
}
location = /status {
access_log off;
allow 127.0.0.1;
deny all;
#proxy_pass http://teslaServer;
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())
}
}
}
似乎不管怎样,/status总是返回up, 那怕后端服务器已经被掐断,不知道为啥?我哪里用错了吗?多谢!