openrestry 后端服务upstream 健康检查配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openrestry 后端服务upstream 健康检查配置相关的知识,希望对你有一定的参考价值。
openrestry 后端服务upstream 健康检查配置 http {
# 在http模块中增加以下配置
lua_package_path "/usr/local/openresty/lualib/resty/?.lua;/usr/local/openresty/lualib/resty/upstream/?.lua;;";
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 = "xx-tomcat",
type = "http",
http_req = "GET / HTTP/1.0\r\nHost: xx-tomcat\r\n\r\n",
interval = 2000,
timeout = 1000,
fall = 3,
rise = 2,
valid_statuses = {200, 302},
concurrency = 10,
}
if not ok then
ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
return
end
}
}
# 在server中增加一个location
location /ngx_stat {
allow 103.101.204.84;
deny all;
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())
}
}
配置完成后重新加载配置文件使之生效,浏览器访问http://test.0xsyshell.com/ngx_stat
效果如下:
Nginx Worker PID: 18561
Upstream xx-tomcat
Primary Peers
172.31.16.14:8080 up
172.31.16.15:8080 up
Backup Peers
以上是关于openrestry 后端服务upstream 健康检查配置的主要内容,如果未能解决你的问题,请参考以下文章
nginx_upstream_check_module监控后端服务器http
利用tengine的nginx_upstream_check_module来检测后端服务状态