|
| 1 | +Name |
| 2 | +==== |
| 3 | + |
| 4 | +nginx_stream_upstream_check_module - support stream upstream health check with Nginx, can work with nginx-stream-upsync-moudle. The module is mainly based on [nginx_tcp_proxy_module](https://github.com/yaoweibin/nginx_tcp_proxy_module) |
| 5 | + |
| 6 | +Table of Contents |
| 7 | +================= |
| 8 | + |
| 9 | +* [Name](#name) |
| 10 | +* [Status](#status) |
| 11 | +* [Synopsis](#synopsis) |
| 12 | +* [Description](#description) |
| 13 | +* [Directives](#functions) |
| 14 | + * [check](#upsync) |
| 15 | + * [interval](#interval) |
| 16 | + * [rise](#rise) |
| 17 | + * [fall](#fall) |
| 18 | + * [timeout](#timeout) |
| 19 | + * [type](#type) |
| 20 | + * [check_http_send](#check_http_send) |
| 21 | + * [check_http_expect_alive](#check_http_expect_alive) |
| 22 | + * [check_shm_size](#check_shm_size) |
| 23 | + * [stream_check_status](#stream_check_status) |
| 24 | +* [TODO](#todo) |
| 25 | +* [Compatibility](#compatibility) |
| 26 | +* [Installation](#installation) |
| 27 | +* [Author](#author) |
| 28 | +* [Copyright and License](#copyright-and-license) |
| 29 | + |
| 30 | +Status |
| 31 | +====== |
| 32 | + |
| 33 | +This module is still under active development. |
| 34 | + |
| 35 | +Synopsis |
| 36 | +==== |
| 37 | + |
| 38 | +``` |
| 39 | +stream { |
| 40 | +
|
| 41 | + upstream cluster { |
| 42 | +
|
| 43 | + # simple round-robin |
| 44 | + server 192.168.0.1:80; |
| 45 | + server 192.168.0.2:80; |
| 46 | +
|
| 47 | + check interval=5000 rise=1 fall=3 timeout=4000; |
| 48 | + } |
| 49 | +
|
| 50 | + server { |
| 51 | + listen 8081; |
| 52 | +
|
| 53 | + proxy_pass stream://cluster; |
| 54 | + } |
| 55 | +
|
| 56 | + server { |
| 57 | + listen 9091; |
| 58 | +
|
| 59 | + stream_check_status; |
| 60 | + } |
| 61 | +
|
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +Description |
| 66 | +==== |
| 67 | + |
| 68 | +Add the support of health check with the stream upstream servers. |
| 69 | + |
| 70 | +Directives |
| 71 | +==== |
| 72 | + |
| 73 | +check |
| 74 | +-------- |
| 75 | +``` |
| 76 | +syntax: check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [type=tcp|http|ssl_hello|mysql|pop3|imap] |
| 77 | +``` |
| 78 | +default: none, if parameters omitted, default parameters are interval=30000 fall=5 rise=2 timeout=1000 type=tcp |
| 79 | + |
| 80 | +context: upstream |
| 81 | + |
| 82 | +description: Add the health check for the upstream servers. |
| 83 | + |
| 84 | +The parameters' meanings are: |
| 85 | + |
| 86 | +* interval: the check request's interval time. |
| 87 | + |
| 88 | +* fall(fall_count): After fall_count check failures, the server is marked down. |
| 89 | + |
| 90 | +* rise(rise_count): After rise_count check success, the server is marked up. |
| 91 | + |
| 92 | +* timeout: the check request's timeout. |
| 93 | + |
| 94 | +* type: the check protocol type: |
| 95 | + |
| 96 | + 1. *tcp* is a simple tcp socket connect and peek one byte. |
| 97 | + |
| 98 | + 2. *ssl_hello* sends a client ssl hello packet and receives the |
| 99 | + server ssl hello packet. |
| 100 | + |
| 101 | + 3. *stream* sends a http request packet, receives and parses the http |
| 102 | + response to diagnose if the upstream server is alive. |
| 103 | + |
| 104 | + 4. *mysql* connects to the mysql server, receives the greeting |
| 105 | + response to diagnose if the upstream server is alive. |
| 106 | + |
| 107 | + 5. *ajp* sends a AJP Cping packet, receives and parses the AJP |
| 108 | + Cpong response to diagnose if the upstream server is alive. |
| 109 | + |
| 110 | + 6. *fastcgi* send a fastcgi request, receives and parses the |
| 111 | + fastcgi response to diagnose if the upstream server is alive. |
| 112 | + |
| 113 | +check_http_send |
| 114 | +-------- |
| 115 | +``` |
| 116 | +syntax: check_http_send http_packet |
| 117 | +``` |
| 118 | +default: "GET / HTTP/1.0\r\n\r\n" |
| 119 | + |
| 120 | +context: upstream |
| 121 | + |
| 122 | +description: If you set the check type is stream, then the check function will sends this http packet to check the upstream server. |
| 123 | + |
| 124 | +check_stream_expect_alive |
| 125 | +-------- |
| 126 | +``` |
| 127 | +syntax: check_http_expect_alive [ http_2xx | http_3xx | http_4xx | stream_5xx ] |
| 128 | +``` |
| 129 | +default: http_2xx | http_3xx |
| 130 | + |
| 131 | +context: upstream |
| 132 | + |
| 133 | +description: These status codes indicate the upstream server's stream response is ok, the backend is alive. |
| 134 | + |
| 135 | +check_shm_size |
| 136 | +-------- |
| 137 | +``` |
| 138 | +syntax: check_shm_size size |
| 139 | +``` |
| 140 | +default: 1M |
| 141 | + |
| 142 | +context: stream |
| 143 | + |
| 144 | +description: Default size is one megabytes. If you check thousands of servers, the shared memory for health check may be not enough, you can |
| 145 | + enlarge it with this directive. |
| 146 | + |
| 147 | +stream_check_status |
| 148 | +-------- |
| 149 | +``` |
| 150 | +syntax: stream_check_status |
| 151 | +``` |
| 152 | +default: none |
| 153 | + |
| 154 | +context: server |
| 155 | + |
| 156 | +description: Display the health checking servers' status by HTTP. This directive should be set in the server block. |
| 157 | + |
| 158 | +[Back to TOC](#table-of-contents) |
| 159 | + |
| 160 | +TODO |
| 161 | +==== |
| 162 | + |
| 163 | +* http check. |
| 164 | + |
| 165 | +[Back to TOC](#table-of-contents) |
| 166 | + |
| 167 | +Compatibility |
| 168 | +============= |
| 169 | + |
| 170 | +The module was developed based on nginx-1.10.1. |
| 171 | + |
| 172 | +Compatible with Nginx-1.9.0+. |
| 173 | + |
| 174 | +[Back to TOC](#table-of-contents) |
| 175 | + |
| 176 | +Installation |
| 177 | +==== |
| 178 | +This module can be used independently, can be download[Github](https://github.com/xiaokai-wang/nginx_stream_upstream_check_module.git). |
| 179 | + |
| 180 | +Grab the nginx source code from [nginx.org](http://nginx.org/), for example, the version 1.10.1 (see nginx compatibility), and then build the source with this module: |
| 181 | + |
| 182 | +```bash |
| 183 | +wget 'http://nginx.org/download/nginx-1.10.1.tar.gz' |
| 184 | +tar -xzvf nginx-1.10.1.tar.gz |
| 185 | +cd nginx-1.10.1/ |
| 186 | +``` |
| 187 | + |
| 188 | +```bash |
| 189 | +./configure --with-stream --add-module=/path/to/nginx_stream_upstream_check_module |
| 190 | +make |
| 191 | +make install |
| 192 | +``` |
| 193 | + |
| 194 | +[Back to TOC](#table-of-contents) |
| 195 | + |
| 196 | +Author |
| 197 | +==== |
| 198 | + |
| 199 | +Xiaokai Wang(王晓开) [email protected] |
| 200 | + |
| 201 | +Weibin Yao |
| 202 | + |
| 203 | +Copyright & License |
| 204 | +==== |
| 205 | + |
| 206 | +This README template copy from agentzh (<stream://github.com/agentzh>). |
| 207 | + |
| 208 | +The health check part is based on the design of Weibin Yao's tcp module [nginx_tcp_proxy_module](https://github.com/yaoweibin/nginx_tcp_proxy_module); |
| 209 | + |
| 210 | +This module is licensed under the BSD license. |
| 211 | + |
| 212 | +Copyright (C) 2016 by Xiaokai Wang < [email protected]> |
| 213 | + |
| 214 | +All rights reserved. |
| 215 | + |
| 216 | +Redistribution and use in source and binary forms, with or without |
| 217 | +modification, are permitted provided that the following conditions are met: |
| 218 | + |
| 219 | +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 220 | + |
| 221 | +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the |
| 222 | + documentation and/or other materials provided with the distribution. |
| 223 | + |
| 224 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 225 | +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 226 | +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 227 | +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 228 | +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 229 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
0 commit comments