Nginx health check module

In this section, we introduce a third-party module for Nginx to check the health status of backend UpStream cluster nodes: nginx_upstream_check_module ( https://github.com/yaoweibin/nginx_upstream_check_module ). This module is described as being developed by the TaoBao team, but I did not find direct evidence when I tried to verify it on GitHua.

It should be noted here that there are currently many Nginx modules that implement Nginx's health monitoring of back-end cluster nodes, not only nginx_upstream_check_module. Nginx officially has a module healthcheck_nginx_upstreams that can also monitor the health of backend nodes ( https://github.com/cep21/healthcheck_nginx_upstreams has a detailed installation and usage introduction)

Let's go back to the explanation of nginx_upstream_check_module. To use this third-party module, you first need to download it, then use the patch command to insert the patch into your original Nginx source code, and recompile and install it. Let's focus on the installation and use of this module.

Download the nginx_upstream_check_module module:

wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

您也可以直接到GitHua上进行下载,还一个在linux系统上使用git命令进行下载。

Unzip the installation, and insert the patch into the Nginx source code

# unzip ./nginx_upstream_check_module-master.zip

注意是将补丁打入Nginx源码,不是Nginx的安装路径:

# cd ./nginx-1.6.2

# patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch

如果补丁安装成功,您将看到以下的提示信息:
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h

这里请注意:在nginx_upstream_check_module官网的安装说明中,有一个打补丁的注意事项:
If you use nginx-1.2.1 or nginx-1.3.0, the nginx upstream round robin
module changed greatly. You should use the patch named
'check_1.2.1.patch'.
If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream
least_conn module. You should use the patch named 'check_1.2.2+.patch'.
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
module. You should use the patch named 'check_1.2.6+.patch'.
If you use nginx-1.5.12+, You should use the patch named
'check_1.5.12+.patch'.
If you use nginx-1.7.2+, You should use the patch named
'check_1.7.2+.patch'.

这里我们的Nginx的版本是1.6.2,那么就应该打入check_1.5.12+.patch这个补丁

 

Recompile and install Nginx:

注意重新编译Nginx,要使用add-module参数将这个第三方模块安装进去:

# ./configure --prefix=/usr/nginx-1.6.2/ --add-module=../nginx_upstream_check_module-master/

# make && make install

Through the above steps, the third-party nginx_upstream_check_module module is ready in Nginx. Next we explain how to use this module. First look at the upstream configuration information:

upstream cluster {
    # simple round-robin
    server 192.168.0.1:80;
    server 192.168.0.2:80;

    check interval=5000 rise=1 fall=3 timeout=4000;

    #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
    #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    #check_http_send "HEAD / HTTP/1.0\r\n\r\n";
    #check_http_expect_alive http_2xx http_3xx;
}

In the above code, the check part is the syntax for calling the nginx_upstream_check_module module:

check interval=milliseconds [fall=count] [rise=count]
[timeout=milliseconds] [default_down=true|false]
[type=tcp|http|ssl_hello|mysql|ajp|fastcgi]

interval: a necessary parameter, the interval for checking the request.

fall: When the number of check failures exceeds fall, the service node becomes down.

rise: When the number of successful checks exceeds the rise, the service node will become up again.

timeout: The request timeout time. After the waiting time is exceeded, the check will fail.

default_down: The initial state of the backend server. By default, the check function will set the status of all backend nodes to down when Nginx starts, and set it to up after the check is successful.

type: This is the protocol type to check for communication, default is http. The above types are all protocol types supported by the check function.

check_http_send http_packet

http_packet的默认格式为:"GET / HTTP/1.0\r\n\r\n"

check_http_send setting, this setting describes what kind of information the check module sends to the backend node each time it checks

check_http_expect_alive [ http_2xx | http_3xx | http_4xx | http_5xx ]

 

These status codes indicate that the server's HTTP response is OK and the backend node is available. The default settings are: http_2xx | http_3xx

After you have finished checking the configuration of the module according to your configuration requirements, first use the nginx -t command to monitor whether the configuration file is available, and then use nginx -s reload to restart nginx.

1.4, I have to mention tengine

Tengine is a web server project initiated by Taobao.com. On the basis of Nginx, it adds many advanced functions and features for the needs of high-traffic websites. The performance and stability of Tengine have been well tested on large websites such as Taobao.com and Tmall.com. Its ultimate goal is to create an efficient, stable, secure, and easy-to-use Web platform ( http://tengine.taobao.org/ ).

You should understand. I recommend that you introduce Tengine in the production environment in due course according to the actual situation of your business. However, when this blog was published, the 2.X version of Tengine was not stable, so it is recommended to use the stable version 1.5.2. Please remember that Tengine is Nginx after upgrading.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326491346&siteId=291194637
Recommended