Lua-Resty-Checkups是一个基于lua的upstream管理和健康检查模块,由又拍云开源。
特点:
支持周期性upstream服务管理操作
支持管理和健康检查
支持upstream动态更新
有利于加权轮询或哈希平衡
支持 Nginx C upstream同步操作
可使用级别和键值实现集群
使用简介:
-- config.lua _M = {} _M.global = { checkup_timer_interval = 15, checkup_shd_sync_enable = true, shd_config_timer_interval = 1, } _M.ups1 = { cluster = { { servers = { {host="127.0.0.1", port=4444, weight=10, max_fails=3, fail_timeout=10}, } }, }, }
lua_package_path "/path/to/lua-resty-checkups/lib/checkups/?.lua;/path/to/config.lua;;"; lua_shared_dict state 10m; lua_shared_dict mutex 1m; lua_shared_dict locks 1m; lua_shared_dict config 10m; server { listen 12350; return 200 12350; } server { listen 12351; return 200 12351; } init_worker_by_lua_block { local config = require "config" local checkups = require "resty.checkups.api" checkups.prepare_checker(config) checkups.create_checker() } server { location = /12350 { proxy_pass http://127.0.0.1:12350/; } location = /12351 { proxy_pass http://127.0.0.1:12351/; } location = /t { content_by_lua_block { local checkups = require "resty.checkups.api" local callback = function(host, port) local res = ngx.location.capture("/" .. port) ngx.say(res.body) return 1 end local ok, err -- connect to a dead server, no upstream available ok, err = checkups.ready_ok("ups1", callback) if err then ngx.say(err) end -- add server to ups1 ok, err = checkups.update_upstream("ups1", { { servers = { {host="127.0.0.1", port=12350, weight=10, max_fails=3, fail_timeout=10}, } }, }) if err then ngx.say(err) end ngx.sleep(1) ok, err = checkups.ready_ok("ups1", callback) if err then ngx.say(err) end ok, err = checkups.ready_ok("ups1", callback) if err then ngx.say(err) end -- add server to new upstream ok, err = checkups.update_upstream("ups2", { { servers = { {host="127.0.0.1", port=12351}, } }, }) if err then ngx.say(err) end ngx.sleep(1) ok, err = checkups.ready_ok("ups2", callback) if err then ngx.say(err) end -- add server to ups2, reset rr state ok, err = checkups.update_upstream("ups2", { { servers = { {host="127.0.0.1", port=12350, weight=10, max_fails=3, fail_timeout=10}, {host="127.0.0.1", port=12351, weight=10, max_fails=3, fail_timeout=10}, } }, }) if err then ngx.say(err) end ngx.sleep(1) ok, err = checkups.ready_ok("ups2", callback) if err then ngx.say(err) end ok, err = checkups.ready_ok("ups2", callback) if err then ngx.say(err) end } }
Lua 配置示例:
_M = {} -- Here is the global part _M.global = { checkup_timer_interval = 15, checkup_timer_overtime = 60, default_heartbeat_enable = true, checkup_shd_sync_enable = true, shd_config_timer_interval = 1, } -- The rests parts are cluster configurations _M.redis = { enable = true, typ = "redis", timeout = 2, read_timeout = 15, send_timeout = 15, protected = true, cluster = { { -- level 1 try = 2, servers = { { host = "192.168.0.1", port = 6379, weight=10, max_fails=3, fail_timeout=10 }, { host = "192.168.0.2", port = 6379, weight=10, max_fails=3, fail_timeout=10 }, } }, { -- level 2 servers = { { host = "192.168.0.3", port = 6379, weight=10, max_fails=3, fail_timeout=10 }, } }, }, } _M.api = { enable = false, typ = "http", http_opts = { query = "GET /status HTTP/1.1\r\nHost: localhost\r\n\r\n", statuses = { [500] = false, [502] = false, [503] = false, [504] = false, }, }, mode = "hash", cluster = { dc1 = { servers = { { host = "192.168.1.1", port = 1234, weight=10, max_fails=3, fail_timeout=10 }, } }, dc2 = { servers = { { host = "192.168.1.2", port = 1234, weight=10, max_fails=3, fail_timeout=10 }, } } } } _M.ups_from_nginx = { timeout = 2, cluster = { { -- level 1 upstream = "api.com", }, { -- level 2 upstream = "api.com", upstream_only_backup = true, }, }, } return _M
Health Checker for Nginx Upstream Servers in Pure Lua. Project homepage: https://github.com/agentzh/lua-resty-upstream-healthcheck This library is enabled by default. You can specify the --without-lua
一个基于 OpenResty 的仿 Yii 的 web 框架,通过本框架能够极大降低openresty的开发入门门槛。 运行机制概述 每一次应用开始处理 HTTP 请求时,它都会进行一个近似的流程。 用户提交指向 入口脚本 index.lua 的请求 入口脚本会创建一个 应用(Application) 实例用于处理该请求,并加载配置。 应用会通过 request(请求) 应用组件解析被请求的路由。
lua-resty-session 是一个面向 OpenResty 的安全和灵活的 session 库,它实现了 Secure Cookie Protocol。 更详细的说明请查看 https://github.com/bungle/lua-resty-session/blob/master/README.md http { server { listen 8080
lua-resty-weauth,适用于 OpenResty / ngx_lua 的基于企业微信组织架构的登录认证。 使用 下载 cd /path/togit clone git@github.com:ledgetech/lua-resty-http.gitgit clone git@github.com:SkyLothar/lua-resty-jwt.gitgit clone git@githu
lua-resty-ffi提供了一个通用高效的接口,使得你可以使用Go,Python,Java和Rust为 OpenResty/Nginx 直接开发你想要的功能。 众所周知,OpenResty使用的lua和C,生态很弱,很多重造的轮子也缺乏维护,以至于跟外围生态系统互通时,巧妇难为无米之炊。 特色: 非阻塞,以协程的方式运行 简单可扩展的接口,支持任何符合C ABI的语言 一劳永逸,无需再编写任何
This Nginx C module exposes a Lua API to Lua Nginx Module for classic Nginx upstreams. Documentation: https://github.com/agentzh/lua-upstream-nginx-module Project page: https://github.com/agentzh/lua-