Redis Predixy 集群

如果您对Redis的了解不够深入请关注本栏目,本栏目包括Redis安装Redis配置文件说明Redis命令和数据类型说明Redis持久化配置Redis主从复制和哨兵机制Redis Cluster(集群)配置

一、概述

  • Predixy 是一个开源的代理软件,通常用于提供 Redis 数据存储的高可用性和负载均衡。它的主要用途是充当 Redis 代理,通过分布式代理和负载均衡来管理和优化 Redis 集群的性能和可用性和安全性。适用于需要大规模部署 Redis 数据存储的应用程序,特别是对于需要负载均衡和高可用性的情况。

  • 我在前面讲过Redis Cluster 集群配置,那么即然官方自带了 Redis Cluster 为什么还要使用 Predixy 呢?因为 Predixy 还有 Redis Cluster 没有的功能,如下:

    • 多种部署:Redis Cluster 只支持一种特定的哈希分片架构,而 Predixy 可以适用于多种部署拓扑。而且增加Redis群集后应用程序代码无需修改,就连配置都不修改。
    • 动态的负载均衡:根据实时的节点状态和负载情况,Predixy 智能地将请求路由到最佳的 Redis 节点,以实现负载均衡。
    • 故障转移:当节点发生故障时,Predixy 可以自动检测并将请求重新路由到可用的节点,实现故障转移。
    • 读写分离:Predixy 支持读写分离的配置。它可以将读操作路由到从节点,以分担主节点的负载,并提高读取性能。同时,写操作仍然会路由到主节点,以确保数据的一致性。
    • 其他功能:Predixy 提供了一些额外的功能,如请求重试、请求限流、缓存、请求日志等。这些功能可以增强 Redis 的性能、安全性和稳定性。
  • 开源地址:https://github.com/joyieldInc/predixy

二、测试规划

  • 我这里在同一主机上开启4个Redis服务实例(2主2从),3个Redis Sentinel服务来测试(监控2主2从),示意图如下:
    在这里插入图片描述

三、Redis 服务实例准备

3.1 配置Redis实例

  • 新建4个Redis配置文件,用于配置2主2从Redis服务实例节点。分别为:redis_6391.conf、redis_6392.conf、redis_6393.conf、redis_6394.conf

  • redis_6391.conf

include redis.conf

port 6391
dir /var/lib/redis/6391
pidfile /var/run/redis_6391.pid

supervised no
daemonize no
logfile ""
appendonly no
  • redis_6392.conf
include redis.conf

port 6392
dir /var/lib/redis/6392
pidfile /var/run/redis_6392.pid

supervised no
daemonize no
logfile ""
appendonly no

replicaof 127.0.0.1 6391
  • redis_6393.conf
include redis.conf

port 6393
dir /var/lib/redis/6393
pidfile /var/run/redis_6393.pid

supervised no
daemonize no
logfile ""
appendonly no
  • redis_6394.conf
include redis.conf

port 6394
dir /var/lib/redis/6394
pidfile /var/run/redis_6394.pid

supervised no
daemonize no
logfile ""
appendonly no

replicaof 127.0.0.1 6393

3.2 创建相关资源

mkdir -p /var/lib/redis/6391
mkdir -p /var/lib/redis/6392
mkdir -p /var/lib/redis/6393
mkdir -p /var/lib/redis/6394

3.2 启动Redis服务实例

  • 启动2个Redis主从服务实例
# 主节点1,端口6391
redis-server redis_6391.conf
# 从节点1,端口6392
redis-server redis_6392.conf

# 主节点2,端口6393
redis-server redis_6393.conf
# 从节点2,端口6394
redis-server redis_6394.conf

四、Sentinel 监控准备

  • 配置 sentinel 监控上面的两个Redis主从。

4.1 配置 sentine l

  • sentinel_26391.conf
port 26391
sentinel monitor shard001 127.0.0.1 6391 2
sentinel monitor shard002 127.0.0.1 6393 2
  • sentinel_26392.conf
port 26392
sentinel monitor shard001 127.0.0.1 6391 2
sentinel monitor shard002 127.0.0.1 6393 2
  • sentinel_26393.conf
port 26393
sentinel monitor shard001 127.0.0.1 6391 2
sentinel monitor shard002 127.0.0.1 6393 2

3.2 开启 Sentinel

redis-sentinel sentinel_26391.conf
redis-sentinel sentinel_26392.conf
redis-sentinel sentinel_26393.conf
  • 也可通过这种方式启动:redis-server sentinel_6379.conf --sentinel

五、安装配置 Predixy

5.1 下载 Predixy

  • 下载安装 Predixy
wget https://github.com/joyieldInc/predixy/releases/download/1.0.5/predixy-1.0.5-bin-amd64-linux.tar.gz
tar -zxvf predixy-1.0.5-bin-amd64-linux.tar.gz
cd predixy-1.0.5
cp conf/predixy.conf conf/predixy.conf.bk
cp conf/sentinel.conf conf/sentinel.conf.bk

5.2 配置 Predixy

  • 修改 Predixy 的配置文件:vi conf/predixy.conf

    • 配置端口和哨兵配置文件(sentinel.conf)
    # 修改以下内容
    
    Bind 127.0.0.1:7617
    
    ################################### SERVERS ####################################
    # Include cluster.conf
    Include sentinel.conf
    # Include try.conf
    
    
  • 修改 Predixy 的哨兵配置文件(sentinel.conf):vi conf/sentinel.conf

    • 注意这个不是Redis自带的sentinel.conf,而是 Predixy 配置文件目录的 sentinel.conf
    # 添加以下内容
    
    SentinelServerPool {
        Databases 16
        Hash crc16
        HashTag "{}"
        Distribution modula
        MasterReadPriority 60
        StaticSlaveReadPriority 50
        DynamicSlaveReadPriority 50
        RefreshInterval 1
        ServerTimeout 1
        ServerFailureLimit 10
        ServerRetryTimeout 1
        KeepAlive 120
        Sentinels {
            + 127.0.0.1:26391
            + 127.0.0.1:26392
            + 127.0.0.1:26393
        }
        Group shard001 {
    
        }
        # 可以直保留一个组,只有一个组时才能使用事务。
        Group shard002 {
        }
    }
    
    

5.3 启动 Predixy 代理

  • bin/predixy conf/predixy.conf
    

六、测试

  • redis-cli -p 7617
    

[root@yiqifu-redis conf]# redis-cli -p 7617
127.0.0.1:7617> set aaa 111
OK
127.0.0.1:7617> set bbb 222
OK
127.0.0.1:7617> set ccc 3333
OK
127.0.0.1:7617> watch ccc
(error) ERR forbid transaction in current server pool
127.0.0.1:7617> multi
(error) ERR forbid transaction in current server pool
127.0.0.1:7617>

  • 测试发现不能进行事务和监控操作,这是他的缺点。但是他有扩展方便、动态负载均衡、故障转移、读写分离等功能。还有 Predixy 的集群可以使用Nginx反向代理来实现。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QIFU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值