[alibaba/tengine]tengine+luajit(session_sticky)+ 移植openresty下的健康检查healthcheck的问题

2024-07-10 789 views
9

1、tengine+luajit下的session_sticky+移植openresty下healthcheck判断一张网页状态码的问题 (说明:为啥不直接用http://tengine.taobao.org/document_cn/http_upstream_check_cn.html? 因为后期健康检查还需要改upstream-healthcheck下的lua文件,改动方便嘛。) http://tengine.taobao.org/document_cn/http_upstream_session_sticky_cn.html https://github.com/openresty/lua-resty-upstream-healthcheck

问题(下面第2点): 1、当一个成员DOWN掉时,新的请求cookie里面不带uumyid的,确实会踢掉DOWN节点调度到up的节点上。 2、先前已经建立的到down的节点的请求,请求中cookie带有uumyid时,还是会调度到标识为DOWN的节点上(测试操作 mv go.htm 33.htm)。 3、接上面第2点,当(mv go.htm 33.htm)时,再关掉tengine ,然后,真的会踢掉DOWN的节点。

tengine的配置如下
    lua_package_path "/usr/local/app/nginx/html/healthcheck.lua;;";

    # sample upstream block:
    upstream cluster1 {
            session_sticky cookie=uumyid fallback=on path=/ mode=insert option=direct;
            server 192.168.10.225:80;
            server 192.168.10.226:80;
            server 192.168.10.227:80;
    }

    ## 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 = "cluster1", -- defined by "upstream"
            type = "http",

            http_req = "GET /go.htm HTTP/1.0\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, 301},  -- 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
    }

回答

5

file: auto/modules

if [ $HTTP_UPSTREAM_CHECK = YES ]; then
    have=NGX_HTTP_UPSTREAM_CHECK . auto/have
    NGX_DSO_ABI_COMPATIBILITY=$(($NGX_DSO_ABI_COMPATIBILITY|$NGX_DSO_UPSTREAM_CHECK_TAG))
    HTTP_MODULES="$HTTP_MODULES $HTTP_UPSTREAM_CHECK_MODULE"
    HTTP_SRCS="$HTTP_SRCS $HTTP_UPSTREAM_CHECK_SRCS"
fi

file: auto/options

--with-http_upstream_check_module)         HTTP_UPSTREAM_CHECK=YES           ;;

file: src/http/modules/ngx_http_upstream_session_sticky_module.c

static ngx_int_t
ngx_http_upstream_session_sticky_get_peer(ngx_peer_connection_t *pc, void *data)
{
    ...

#if (NGX_HTTP_UPSTREAM_CHECK)
    if (ngx_http_upstream_check_peer_down(server[i].check_index)) {
        if (ctx->sscf->flag & NGX_HTTP_SESSION_STICKY_FALLBACK_OFF) {
            return NGX_BUSY;

        } else {
            goto failed;
        }
    }
 #endif

    ...

如上,你检查一下是否在编译时已禁止http_upstream_check_module

2

[root@hzggt-test-ssl-33 ~]# /usr/local/app/nginx/sbin/nginx -V Tengine version: Tengine/2.2.0 (nginx/1.8.1) built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) TLS SNI support enabled configure arguments: --user=nobody --group=nobody --prefix=/usr/local/app/nginx --conf-path=/usr/local/app/nginx/conf/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_ssl_module --with-http_geoip_module --with-http_stub_status_module --with-http_concat_module --add-module=/srv/software/ngx_devel_kit-0.3.0 --add-module=/srv/software/lua-nginx-module-0.10.8 --add-module=/srv/software/lua-upstream-nginx-module nginx: loaded modules: nginx: ngx_core_module (static) nginx: ngx_errlog_module (static) nginx: ngx_conf_module (static) nginx: ngx_dso_module (static) nginx: ngx_events_module (static) nginx: ngx_event_core_module (static) nginx: ngx_epoll_module (static) nginx: ngx_procs_module (static) nginx: ngx_proc_core_module (static) nginx: ngx_openssl_module (static) nginx: ngx_regex_module (static) nginx: ngx_http_module (static) nginx: ngx_http_core_module (static) nginx: ngx_http_log_module (static) nginx: ngx_http_upstream_module (static) nginx: ngx_http_static_module (static) nginx: ngx_http_gzip_static_module (static) nginx: ngx_http_autoindex_module (static) nginx: ngx_http_index_module (static) nginx: ngx_http_random_index_module (static) nginx: ngx_http_concat_module (static) nginx: ngx_http_auth_request_module (static) nginx: ngx_http_auth_basic_module (static) nginx: ngx_http_access_module (static) nginx: ngx_http_limit_conn_module (static) nginx: ngx_http_limit_req_module (static) nginx: ngx_http_realip_module (static) nginx: ngx_http_geo_module (static) nginx: ngx_http_geoip_module (static) nginx: ngx_http_map_module (static) nginx: ngx_http_split_clients_module (static) nginx: ngx_http_referer_module (static) nginx: ngx_http_rewrite_module (static) nginx: ngx_http_ssl_module (static) nginx: ngx_http_proxy_module (static) nginx: ngx_http_fastcgi_module (static) nginx: ngx_http_uwsgi_module (static) nginx: ngx_http_scgi_module (static) nginx: ngx_http_memcached_module (static) nginx: ngx_http_empty_gif_module (static) nginx: ngx_http_browser_module (static) nginx: ngx_http_user_agent_module (static) nginx: ngx_http_secure_link_module (static) nginx: ngx_http_upstream_hash_module (static) nginx: ngx_http_upstream_ip_hash_module (static) nginx: ngx_http_upstream_consistent_hash_module (static) nginx: ngx_http_upstream_check_module (static) nginx: ngx_http_upstream_least_conn_module (static) nginx: ngx_http_upstream_keepalive_module (static) nginx: ngx_http_upstream_dynamic_module (static) nginx: ngx_http_stub_status_module (static) nginx: ndk_http_module (static) nginx: ngx_http_lua_upstream_module (static) nginx: ngx_http_write_filter_module (static) nginx: ngx_http_header_filter_module (static) nginx: ngx_http_chunked_filter_module (static) nginx: ngx_http_range_header_filter_module (static) nginx: ngx_http_gzip_filter_module (static) nginx: ngx_http_postpone_filter_module (static) nginx: ngx_http_ssi_filter_module (static) nginx: ngx_http_charset_filter_module (static) nginx: ngx_http_addition_filter_module (static) nginx: ngx_http_userid_filter_module (static) nginx: ngx_http_footer_filter_module (static) nginx: ngx_http_trim_filter_module (static) nginx: ngx_http_headers_filter_module (static) nginx: ngx_http_upstream_session_sticky_module (static) nginx: ngx_http_reqstat_module (static) nginx: ngx_http_lua_module (static) nginx: ngx_http_copy_filter_module (static) nginx: ngx_http_range_body_filter_module (static) nginx: ngx_http_not_modified_filter_module (static)