You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lua file:
local u = "test.domain.com"
local ok, upstream = pcall(require, "ngx.upstream")
if not ok then
error("ngx_upstream_lua module required")
end
local set_peer_down = upstream.set_peer_down
local get_primary_peers = upstream.get_primary_peers
local get_backup_peers = upstream.get_backup_peers
local get_upstreams = upstream.get_upstreams
local function gen_peers_status_info(peers)
local npeers = #peers
for i = 1, npeers do
local peer = peers[i]
local stat = ""
if peer.down then
stat = " DOWN\n"
else
stat = " up\n"
end
ngx.log(ngx.DEBUG,"name:",peer.name,"stat:",stat)
end
return idx
end
local peers, err = get_primary_peers(u)
if not peers then
return "failed to get primary peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
peers, err = get_backup_peers(u)
if not peers then
return "failed to get backup peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
I use ngx.upstream.get_primary_peers and find a peer is down。But nginx still use the bad peer。
log:
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:123.157.76.2:80stat: up
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:123.157.76.5:80stat: DOWN
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:60.217.244.95:80stat: up
2018/10/12 16:14:36 [debug] 1998#1998: *508497 http cleanup add: 0000000003439608
2018/10/12 16:14:36 [debug] 1998#1998: *508497 http script var: "/a64/0/ads11euyc1dsa0pb.dsaudio"
2018/10/12 16:14:36 [debug] 1998#1998: *508497 consistent hash [peer name]:123.157.76.5:80 4170160978
2018/10/12 16:14:36 [debug] 1998#1998: *508497 stream socket 18
lua file:
local u = "test.domain.com"
local ok, upstream = pcall(require, "ngx.upstream")
if not ok then
error("ngx_upstream_lua module required")
end
local set_peer_down = upstream.set_peer_down
local get_primary_peers = upstream.get_primary_peers
local get_backup_peers = upstream.get_backup_peers
local get_upstreams = upstream.get_upstreams
local function gen_peers_status_info(peers)
local npeers = #peers
for i = 1, npeers do
local peer = peers[i]
local stat = ""
if peer.down then
stat = " DOWN\n"
else
stat = " up\n"
end
ngx.log(ngx.DEBUG,"name:",peer.name,"stat:",stat)
end
return idx
end
local peers, err = get_primary_peers(u)
if not peers then
return "failed to get primary peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
peers, err = get_backup_peers(u)
if not peers then
return "failed to get backup peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
upstream config :
upstream test.domain.com {
consistent_hash $uri;
#server 123.157.76.2:80 id=1001 weight=1 max_fails=2 fail_timeout=30s;
#server 123.157.76.5:80 id=1002 weight=1 max_fails=2 fail_timeout=30s;
server 123.157.76.2:80;
server 123.157.76.5:80;
The text was updated successfully, but these errors were encountered: