upyun / lua-resty-checkups Goto Github PK
View Code? Open in Web Editor NEWManage Nginx upstreams in pure Lua.
Manage Nginx upstreams in pure Lua.
我按照 demo进行操作,报这样的错误
2019/12/18 15:28:09 [error] 55676#12685090: init_by_lua error: init_by_lua:4: attempt to call field 'init' (a nil value)
stack traceback:
init_by_lua:4: in main chunk
下面是 配置文件片段
lua_package_path "/usr/local/etc/openresty/config.lua;;";
lua_code_cache on;
lua_shared_dict state 10m;
lua_shared_dict mutex 1m;
lua_shared_dict locks 1m;
lua_shared_dict config 10m;
init_by_lua_block {
local config = require "config.lua"
local checkups = require "resty.checkups.api"
checkups.init(config)
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /hehe {
default_type 'text/plain';
content_by_lua_block {
ngx.say(package.path)
ngx.say(package.cpath)
}
}
我是通过 opm get upyun/lua-resty-checkups
来安装的
可以看出 这个库是位于 package.path里面的,但是 为啥会报错啊?
获取 upstream 的时候(extract_servers_from_upstrea
)是否可以考虑如下优化?
Hi
I am developing a cdn api system (proxy server) and I need to add load balancer option by having heartbeat and ... it's important for me to have runtime data structure update (every 5 mins) but all I see is that we have to config our data structure just at the start time!
is runtime update possible now in lua-resty-checkups?
看了下说明,,只有一个worker做 health check, 然后调用 upstream.set_peer_down;
但是 set_peer_down 是worker级别的行为,没看到同步到其他所有worker的逻辑? 这是bug吧?
https://github.com/openresty/lua-upstream-nginx-module#set_peer_down
Note that this method only changes the peer settings in the current Nginx worker process. You need to synchronize the changes across all the Nginx workers yourself if you want a server-wide change (for example, by means of ngx_lua's ngx.shared.DICT).
目前心跳检查是串行的。一旦一个节点发生宕机(关机)或者节点不存在,SYN
在第一次请求失败之后,会重新以时间倍数增长的方式发起请求,直到请求时间达到一分钟,才会进入下个节点的心跳检测。一旦多台节点同时宕机或者配置了多个不存在的节点,就会堵塞N * 60s
的时间,以至于影响其他机子的心跳检测。
主要用于balance动态选择,现在多个域名对应相同后端,只能配置多次。
upstream backend {
server 0.0.0.0;
balancer_by_lua_block {
require "wario.balancer"
}
}
如上面的代码块,lua-resty-checkups提供的update和delete好像都是预先需要在nginx.conf里面声明了一个backend,才能去动态变更后段的servers,能不能连这个指令也能通过lua来创建呢?
因为我试过lua-resty-checkups的api是做不到的,不知道是不是姿势不对,希望能得到回复,谢谢
heartbeat timer执行了一段时间后无任何日志地自动挂了
i want use lua-resty-checkups to realize a micro service gateway,this is my way:
nginx.conf
lua_shared_dict state 10m;
lua_shared_dict mutex 1m;
lua_shared_dict locks 1m;
lua_shared_dict config 10m;
upstream charles{
server 10.72.8.81:80 weight=2;
}
init_by_lua_block {
local config = require "config"
local checkups = require "resty.checkups.api"
checkups.init(config)
}
init_worker_by_lua_block {
local config = require "config"
local checkups = require "resty.checkups.api"
checkups.prepare_checker(config)
checkups.create_checker()
}
server {
location / {
set $dynamic_proxy '';
set_by_lua_file $test_var /opt/openresty/lua_script/dynamic_route.lua;
proxy_pass http://$dynamic_proxy/;
}
dynamic_route.lua
local ngx_re = require "ngx.re"
local uri = ngx.var.uri
local array = ngx_re.split(uri, "/")
local context_path = array[2]
if "charles" == context_path then
ngx.var.dynamic_proxy = "charles"
end
if "charles1" == context_path then
ngx.var.dynamic_proxy = "test_upstream"
end
config.lua
_M = {}
_M.global = {
checkup_timer_interval = 15,
checkup_shd_sync_enable = true,
shd_config_timer_interval = 1,
}
_M.test_upstream = {
cluster = {
{
servers = {
{ host = "10.72.8.81", port = 80, weight=10, max_fails=3, fail_timeout=10 },
}
},
},
}
return _M
curl http://localhost/charles
<!DOCTYPE html>
<html>
<head>
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="https://openresty.org/">openresty.org</a>.<br/>
Commercial support is available at
<a href="https://openresty.com/">openresty.com</a>.</p>
<p><em>Thank you for flying OpenResty.</em></p>
</body>
</html>
curl http://localhost/charles1
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty/1.13.6.2</center>
</body>
</html>
2019/06/05 09:56:17 [error] 47#0: *2630 no resolver defined to resolve test_upstream, client: 172.17.0.1, server: , request: "GET /charles1 HTTP/1.1", host: "localhost"
默认是使用round_robin的,但是测试的时候发现,2台后端server,请求速率低的时候1个QPS 总是轮训到第一个,只有更高QSP的时候轮训交替正常。
hello,请教下:
1 为何创建check timer要用lock的方式而不是用ngx.worker.id的方式来创建唯一timer?是有什么特殊的考虑吗?
2 在lock方式中(目前的方式),base.CHECKUP_TIMER_KEY在设置到mutex shdict中时为何要设置超时时间?(默认60s) ,
谢谢
I did a test found Request distributed Uneven with consistent_hash method.
upstream test have two servers:
upstream test{
server 192.168.46.111:80;
server 192.168.46.110:80;
}
hash arguments is cid.
I use 10w cid to test.
I found that the request deliver to server 192.168.46.111:80 is about 89036 .
More than eighty percent
BUT i also test original nginx with consistent method,the number of request forward to two server is equality.
DO YOU encounter the same problem? OR What is wrong with me?
后端cls选择节点策略如果是consistent_hash时,
若选到的节点突然挂掉,无法及时fail over到好的节点,会有部分502
in base.lua
local CHECKUP_TIMER_KEY = "checkups:timer:" .. os.time()
os.time 这个函数 老生常谈了,这里是否应该使用消耗更小的 ngx.time 更为合适?
Any plan to register this repo to OPM - OpenResty Package Manager?
hello:
读了整个代码,发现各个节点健康检查的状态只是存放到了state dict中,
除了get_status这个API将健康状况展示之外,在做流量转发的时候,并没有使用到这些状态。
是我没看到么?try_cluster选节点的时候貌似也没有涉及到健康状态。
谢谢。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.