nginx中文文档-nginx检测后端真实服务器健康状况

Nginx

nginx检测后端真实服务器健康状况的模块是外部模块 ,

nginx检测后端真实服务器健康状况的模块名称是nginx_http_upstream_check_module

nginx检测后端真实服务器健康状况简介:

[php]

http {

upstream cluster {

# simple round-robin
server 192.168.0.1:80;
server 192.168.0.2:80;

check interval=3000 rise=2 fall=5 timeout=1000;

#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 "GET / HTTP/1.0\r\n\r\n";
#check_http_expect_alive http_2xx http_3xx;
}

server {
listen 80;

location / {
proxy_pass http://cluster;
}

location /status {
check_status;

access_log   off;
allow SOME.IP.ADD.RESS;
deny all;
}
}

}

[/php]

nginx检测后端真实服务器健康状况描述
给负载均衡服务器添加健康检查的支持。

nginx检测后端真实服务器健康状况相关指令
check
syntax: *check interval=milliseconds [fall=count] [rise=count]
[timeout=milliseconds] [default_down=true|false]
[type=tcp|ssl_hello|mysql|ajp]*

default: *none, if parameters omitted, default parameters are
interval=30000 fall=5 rise=2 timeout=1000 default_down=true type=tcp*

context: *upstream*

description: Add the health check for the upstream servers.

The parameters' meanings are:

*   *interval*: the check request's interval time.

*   *fall*(fall_count): After fall_count check failures, the server is
marked down.

*   *rise*(rise_count): After rise_count check success, the server is
marked up.

*   *timeout*: the check request's timeout.

*   *default_down*: set initial state of backend server, default is
down.

*   *type*: the check protocol type:

1.  *tcp* is a simple tcp socket connect and peek one byte.

2.  *ssl_hello* sends a client ssl hello packet and receives the
server ssl hello packet.

3.  *http* sends a http requst packet, recvives and parses the http
response to diagnose if the upstream server is alive.

4.  *mysql* connects to the mysql server, recvives the greeting
response to diagnose if the upstream server is alive.

5.  *ajp* sends a AJP Cping packet, recvives and parses the AJP
Cpong response to diagnose if the upstream server is alive.

check_http_send
syntax: *check_http_send http_packet*

default: *"GET / HTTP/1.0\r\n\r\n"*

context: *upstream*

description: If you set the check type is http, then the check function
will sends this http packet to check the upstream server.

check_http_expect_alive
syntax: *check_http_expect_alive [ http_2xx | http_3xx | http_4xx |
http_5xx ]*

default: *http_2xx | http_3xx*

context: *upstream*

description: These status codes indicate the upstream server's http
response is ok, the backend is alive.

check_shm_size
syntax: *check_shm_size size*

default: *1m*

context: *http*

description: Default size is one megabytes. If you check thousands of
serveres, the shared memory for health check may be not enough, you can
enlarge it with this directive.

check_status
syntax: *check_status*

default: *none*

context: *location*

description: Display the health checking servers' status by HTTP. This
directive should be set in the http block.

nginx检测后端真实服务器健康状况模块安装
Download the latest version of the release tarball of this module from
github (<http://github.com/yaoweibin/nginx_upstream_check_module>)

Grab the nginx source code from nginx.org (<http://nginx.org/>), for
example, the version 1.0.14 (see nginx compatibility), and then build
the source with this module:

$ wget 'http://nginx.org/download/nginx-1.0.14.tar.gz'
$ tar -xzvf nginx-1.0.14.tar.gz
$ cd nginx-1.0.14/
$ patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch

$ ./configure --add-module=/path/to/nginx_http_upstream_check_module

$ make
$ make install

Note
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'.

The patch just adds the support for Round-Robin and Ip_hash upstream
module. But it's easy to expand my module to other upstream modules. See
the patch for detail.

If you want to add the support for upstream fair module, you can do it
like this:

$ git clone git://github.com/gnosek/nginx-upstream-fair.git
$ cd nginx-upstream-fair
$ patch -p2 < /path/to/nginx_http_upstream_check_module/upstream_fair.patch
$ cd /path/to/nginx-1.0.14
$ ./configure --add-module=/path/to/nginx_http_upstream_check_module --add-module=/path/to/nginx-upstream-fair-module
$ make
$ make install

Compatibility
*   My test bed is 0.7.67 and 0.8.49+.

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 67 queries in 0.435 seconds