Nginx adds the nginx_heath module, nginxnginx_heath
Why? Why the nginx_heath module is used, for example, when nginx + tomcat is deployed, nginx-> upstream polling can be used to kill the suspended tomcat service after tomcat is suspended, if the deployed machine fails, nginx polling cannot be kicked off. If the service sends a request again, the request times out!
1. ngx_http_proxy_module and ngx_http_upstream_module (built-in)
Address: http://nginx.org/cn/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
2. nginx_upstream_check_module
Https://github.com/yaoweibin/nginx_upstream_check_module
3. ngx_http_healthcheck_module
Http://wiki.nginx.org/NginxHttpHealthcheckModule
Currently, the second solution is used:
1. Add the nginx_heath Module
First you need to add the [nginx_upstream_check_module] module: http://pan.baidu.com/s/1caLNUe
./Nginx-V
View added nginx modules such as -- prefix =/opt/nginx-new -- with-http_ssl_module -- with-http_v2_module -- with-http_stub_status_module -- with-pcre
Install nginx in the nginx source code: patch-p0 <.. /nginx_upstream_check_module-master/check_1.5.12 +. patch. This requires an appropriate version. Otherwise, patching may fail. If you are prompted that there is no patch command, install yum-y install patch first.
Append the nginx_upstream_check_module module: -- prefix =/opt/nginx-new -- with-http_ssl_module -- with-http_v2_module -- with-http_stub_status_module -- with-pcre -- add-module =/home/software/nginx_upstream_check_module-master
Then make
2. Configure upstream to add health check
Upstream name {
Server 10.144.48.157: 8205;
Server 119.29.204.12: 8889;
Check interval = 3000 rise = 2 fall = 3 timeout = 3000 type = tcp;
}
The above configuration indicates that all nodes in the Server Load balancer entry name are detected once every 3 seconds. If the request is normal twice, the status of the realserver is marked as up. If the detection fails five times, the status of the realserver is down and the timeout time is 1 second.
Meaning of the specified parameter:
-Interval: The interval between health check packets sent to the backend.
-Fall (fall_count): if the number of consecutive failures reaches fall_count, the server is considered as down.
-Rise (rise_count): if the number of consecutive successes reaches rise_count, the server is considered as up.
-Timeout: the timeout value of the backend health request.
-Default_down: sets the initial state of the server. If it is true, the default state is down. If it is false, it is up. The default value is true, that is, the server is considered to be unavailable at the beginning. It will not be considered healthy until the Health Check package reaches a certain number of successes.
-Type: the type of the health check package. The following types are supported:
-Tcp: A simple tcp connection. If the connection is successful, the backend is normal.
-Ssl_hello: Send an initial SSL hello package and accept the SSL hello package of the server.
-Http: Send an HTTP request. The status of the backend response package is used to determine whether the backend is alive.
-Mysql: connects to the mysql server and determines whether the backend is alive by receiving the greeting package of the server.
-Ajp: sends the Cping package of the AJP protocol to the backend, and determines whether the backend is alive by receiving the Cpong package.
-Port: Specifies the check port of the backend server. You can specify the ports of backend servers different from the real services. For example, if the backend provides an application with port 443, you can check the status of port 80 to determine the backend health status. The default value is 0, indicating the same port as the backend server that provides real services. This option appears in the Tengine-1.4.0.
3. Configure the web page
Location/nstatus {
Check_status;
Access_log off;
}
If any of
Parameter requests are also supported? Status = up. The upstream in the up status is displayed.