使用keydb 简化redis openresty 集成
openresty 支持redis 的链接管理以及api 集成能力是一个很不错的功能,基于keydb 的多活模式可以简化redis 的维护
同时结合haproxy 可以解决负载的问题
参考玩法
简单说明:
keydb 基于Active-Replication 模式,可以同时读写,对于openresty 集成redis 的,基于haproxy lb keydb ,为了方便haproxy 与openresty 部署在一起(类似sidecar 模式)
参考配置
- haproxy
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
# The lines below enable multithreading. This should correlate to number of threads available you want to use.
nbthread 4
cpu-map auto:1/1-4 0-3
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# An alternative list with additional directives can be obtained from
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
maxconn 40000
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend main
bind :6379
maxconn 40000
mode tcp
option tcplog
default_backend app
backend app
balance first
option tcp-check
server keydb3 db:6379 maxconn 20000 check inter 1s
server keydb2 db2:6379 maxconn 20000 check inter 1s
- nginx 集成
user root;
master_process off;
worker_processes 1;
events {
worker_connections 65536;
}
error_log /opt/app.log debug;
http {
include mime.types;
default_type text/html;
lua_code_cache on;
lua_package_path '/opt/lua/?.lua;;';
real_ip_header X-Forwarded-For;
resolver 127.0.0.11;
server {
listen 80;
charset utf-8;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
default_type text/html;
location /test {
default_type text/html;
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
local ok, err = red:connect("haproxy", 6379)
red:auth("dalong")
local res, err = red:get("demoapp")
if not res then
ngx.say("failed to getdemoapp: ", err)
return
end
ngx.say(res)
}
}
}
}
说明
keydb 是一个很不错的redis 兼容替换方案,维护上可以简化不少部署问题,同时可以完整兼容redis,基于多线程也提供了不错的性能
参考资料
https://docs.keydb.dev/docs/haproxy
https://github.com/rongfengliang/keydb-nchan
https://docs.keydb.dev/docs/active-rep
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2022-03-19 lightdash基于dbt 构建的looker 可选工具
2020-03-19 graphqlize docker-compose 运行
2020-03-19 graphqlize 灵活方便的jvm graphql library试用
2020-03-19 graphqlize 基于jvm的快速生成graphql api 的库
2019-03-19 terraform 几个方便的工具
2019-03-19 几张简单的terraform flow 图——可以快速了解terraform的使用
2019-03-19 Stateful Kubernetes Applications Made Easier: PSO and FlashBlade