0%

使用openresty来代替nginx

https://openresty.org/cn/

health check

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
lua_shared_dict healthcheck 2m;
lua_socket_log_errors off;

upstream backend-xxx {
ip_hash;
server 192.168.100.100:8000 weight=1 max_fails=3 fail_timeout=15s;
server 192.168.100.101:8000 weight=1 max_fails=3 fail_timeout=15s;
}

init_worker_by_lua_block {
local hc = require "resty.upstream.healthcheck"

local ok, err = hc.spawn_checker{
shm = "healthcheck", -- defined by "lua_shared_dict"
upstream = "backend-xxx", -- defined by "upstream"
type = "http",
http_req = "GET / HTTP/1.0\r\nHost: beidou.ymmoa.com\r\n\r\n",

interval = 2000, -- run the check cycle every 2 sec
timeout = 1000, -- 1 sec is the timeout for network operations
fall = 3, -- # of successive failures before turning a peer down
rise = 2, -- # of successive successes before turning a peer up
valid_statuses = {200, 302}, -- a list valid HTTP status code
concurrency = 10, -- concurrency level for test requests
}

local ok, err = hc.spawn_checker{
shm = "healthcheck", -- defined by "lua_shared_dict"
upstream = "backend-xxx", -- defined by "upstream"
type = "tcp",

interval = 2000, -- run the check cycle every 2 sec
timeout = 1000, -- 1 sec is the timeout for network operations
fall = 3, -- # of successive failures before turning a peer down
rise = 2, -- # of successive successes before turning a peer up
valid_statuses = {200, 302}, -- a list valid HTTP status code
concurrency = 10, -- concurrency level for test requests
}

if not ok then
ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
return
end
}

grinning all the time

😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄