Created
August 19, 2021 08:05
-
-
Save woodgear/d4de35b30be303900233ccf00bf2b554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events { | |
worker_connections 1024; | |
} | |
http { | |
error_log /var/log/nginx/error.log info; | |
access_log /var/log/nginx/access.log; | |
lua_package_path '/usr/local/lib/lua/?.lua;;'; | |
lua_package_cpath '/usr/local/lib/lua/?.so;;'; | |
client_max_body_size 0; | |
server { | |
listen 81; | |
location /ip-test { | |
content_by_lua_block { | |
local resty_chash = require "resty.chash" | |
local servers={ | |
} | |
servers["10.244.1.10:80"]=25 | |
servers["10.244.1.11:80"]=25 | |
servers["10.244.1.12:80"]=25 | |
servers["10.244.1.13:80"]=25 | |
local keys={ | |
"10.244.0.17", | |
"10.244.0.16", | |
"10.244.0.20", | |
"10.244.0.14", | |
"10.244.0.19", | |
"10.244.0.24", | |
"10.244.0.21", | |
"10.244.0.28", | |
"10.244.0.25", | |
"10.244.0.3", | |
"10.244.0.23", | |
"10.244.0.27", | |
"10.244.0.2", | |
"10.244.0.22", | |
"10.244.0.29", | |
"10.244.0.26", | |
"10.244.0.7", | |
"10.244.0.15", | |
"10.244.0.13", | |
"10.244.0.61" | |
} | |
local counter={} | |
local chash = resty_chash:new(servers) | |
for i,key in ipairs(keys) do | |
local backend, idx = chash:find(key) | |
ngx.log(ngx.NOTICE,"key "..key.. " backend " ..backend.. "idx " ..idx) | |
if counter[backend] ==nil then | |
counter[backend]=1 | |
else | |
counter[backend]=counter[backend]+1 | |
end | |
end | |
for b,c in pairs(counter) do | |
ngx.log(ngx.NOTICE," backend " ..b.. " count " ..c) | |
end | |
ngx.log(ngx.NOTICE," len " ..#keys) | |
ngx.say("ok") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment