码迷,mamicode.com
首页 > 其他好文 > 详细

openrestry 后端服务upstream 健康检查配置

时间:2019-05-24 20:52:57      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:cal   erro   work   log   spawn   ali   init   backup   primary   

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 健康检查配置

标签:cal   erro   work   log   spawn   ali   init   backup   primary   

原文地址:https://blog.51cto.com/darren88/2399795

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!