文件名称:
基于Lua的upstream管理和健康检查模块Lua-Resty-Checkups.zip
开发工具:
文件大小: 333kb
下载次数: 0
上传时间: 2019-07-19
详细说明: 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
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
相关搜索: