forked from yaoweibin/nginx_upstream_check_module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
237 lines (164 loc) · 7.54 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
Name
nginx_http_upstream_check_module - support health check with Nginx
Synopsis
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;
}
}
}
Description
Add the support of health check with the upstream servers.
Directives
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 request packet, receives and parses the http
response to diagnose if the upstream server is alive.
4. *mysql* connects to the mysql server, receives the greeting
response to diagnose if the upstream server is alive.
5. *ajp* sends a AJP Cping packet, receives 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
servers, 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.
Installation
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'.
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'.
The patch just adds the support for the official Round-Robin, Ip_hash
and least_conn 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
If you want to add the support for nginx sticky module, you can do it
like this:
$ svn checkout http://nginx-sticky-module.googlecode.com/svn/trunk/ nginx-sticky-module
$ cd nginx-sticky-module
$ patch -p0 < /path/to/nginx_http_upstream_check_module/nginx-sticky-module.patch
$ cd /path/to/nginx-1.0.14
$ ./configure --add-module=/path/to/nginx_http_upstream_check_module --add-module=/path/to/nginx-sticky-module
$ make
$ make install
Note that, the nginx-sticky-module also needs the original check.patch.
Compatibility
* My test bed is 0.7.67 and 0.8.49+.
Notes
TODO
Known Issues
* Developing
Changelogs
v0.1
* first release
Authors
Weibin Yao(姚伟斌) *yaoweibin at gmail dot com*
Matthieu Tourne
Copyright & License
This README template copy from agentzh (<http://github.com/agentzh>).
The health check part is borrowed the design of Jack Lindamood's
healthcheck module healthcheck_nginx_upstreams
(<http://github.com/cep21/healthcheck_nginx_upstreams>);
This module is licensed under the BSD license.
Copyright (C) 2012 by Weibin Yao <yaoweibin@gmail.com>.
Copyright (C) 2012 by Matthieu Tourne.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.