首页 > 数据库 >使用keydb 简化redis openresty 集成

使用keydb 简化redis openresty 集成

时间:2023-03-19 21:35:21浏览次数:46  
标签:haproxy errors http keydb redis etc 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

标签:haproxy,errors,http,keydb,redis,etc,openresty
From: https://www.cnblogs.com/rongfengliang/p/17234367.html

相关文章

  • 第三方接口的熔断方案(openresty)
    背景很多项目都需要调用到第三方的接口,曾经就有调用第三方接口慢,大量超时响应的请求不断堆积,造成服务不可用,间接堵塞了我司服务的整条依赖链,最后导致整个业务系统雪崩。不......
  • redis跳跃表
    Redis使用跳跃表作为有序集合键的底层实现之一,同时Redis是在集群节点内用作内部数据结构。跳跃表的实现Redis的跳跃表由redis.h/zskiplistNode和redis.h/zskiplist两个结......
  • Redis持久化机制
    Redis持久化机制redis是用来做缓存。持久化:数据从内存->磁盘Redis官方提供了两种持久化机制。快照(SNAPSHOT)RDBAOF(AppendOnlyFile)只追加日志文件快照特点:这种方......
  • Redis的Linus下的安装
    RedisNoSQL:NotOnlySQL非关系型数据库。缓存流量比较大,不需要写sql语句。NoSQL的四大分类:1、键值(Key-Value)存储数据库。使用到一个哈希表,这个表中有一个指针指向特定的......
  • Redis的Linux下的安装
    Linus一,虚拟机下安装Linus选择虚拟机安装CentOS-7-x86_64-Minimal-1804的镜像,按顺序操作下一步创建root密码,如123456,点击完成,重启输入root和设定的密码123456进入系......
  • nchan 集成keydb简单测试&一些说明
    因为keydb是完整兼容redis的,所以对于单机版本的兼容是很简单的,配置就行了参考单机运行docker-compose文件version:'3'services:db3:imag......
  • docker 安装redis
    dockersearchredis   或者去dockerHub上去找版本哪个版本用的人多就用哪个 2.dockerpulredis(dockerpull<镜像名称>:<版本号>默认是拉取latest)  ......
  • Redis-超卖问题
    悲观锁:简单粗暴,性能一般。认为线程安全一定会发生,在操作数据之前获取锁,确保线程串行执行。Synchronized。Lock都属于悲观锁 乐观锁,性能较好。认为线程安全问题不一定......
  • Redis实战—优惠卷
    全局ID生成器,满足以下特性: 1.唯一性,2.高可用,3.高性能,4.递增性,5.安全性。实现:拼接,ID会用数值:Long型直接插入数据库策略:UUID;Redis自增;雪花算法;数据库自增Redis自增:......
  • golang常用库包:缓存redis操作库go-redis使用(03)-高级数据结构和其它特性
    Redis高级数据结构操作和其它特性第一篇:go-redis使用,介绍Redis基本数据结构和其他特性,以及go-redis连接到Redishttps://www.cnblogs.com/jiujuan/p/17207166.html第......