redis-sentinel高可用哨兵
redis支持多实例-------基于多个配置文件,运行处多个redis相互独立的进程
1、配置三个redis
#redis-6379.conf -----主
port 6379
daemonize yes
logfile "6379.log"
dbfilename "dump-6379.rdb"
dir "/test/data/"
#redis-6380.conf------从1
port 6380
daemonize yes
logfile "6380.log"
dbfilename "dump-6380.rdb"
dir "/test/data/"
slaveof 127.0.0.1 6379
#redis-6381.conf-----从2
port 6381
daemonize yes
logfile "6381.log"
dbfilename "dump-6381.rdb"
dir "/test/data/"
slaveof 127.0.0.1 6379
2、启动好三个redis redis-server redis-6380.conf
使用命令redis-cli -p 6379 info replication
看到如下则成功
3、配置三个哨兵
port 26379
dir /test/data/
logfile "26379.log"
// 当前Sentinel节点监控 192.168.119.10:6379 这个主节点
// 2代表判断主节点失败至少需要2个Sentinel节点节点同意
// mymaster是主节点的别名
sentinel monitor msredis 127.0.0.1 6379 2
//每个Sentinel节点都要定期PING命令来判断Redis数据节点和其余Sentinel节点是否可达,如果超过30000毫秒30s且没有回复,则判定不可达
sentinel down-after-milliseconds msredis 30000
//当Sentinel节点集合对主节点故障判定达成一致时,Sentinel领导者节点会做故障转移操作,选出新的主节点,
原来的从节点会向新的主节点发起复制操作,限制每次向新的主节点发起复制操作的从节点个数为1
sentinel parallel-syncs msredis 1
//故障转移超时时间为180000毫秒
sentinel failover-timeout msredis 180000
daemonize yes
sentinel-26380.conf
port 26380
dir /test/data/
logfile "26380.log"
sentinel monitor msredis 127.0.0.1 6379 2
sentinel down-after-milliseconds msredis 30000
sentinel parallel-syncs msredis 1
sentinel failover-timeout msredis 180000
daemonize yes
sentinel-26381.conf
port 26381
dir /test/data/
logfile "26381.log"
sentinel monitor msredis 127.0.0.1 6379 2
sentinel down-after-milliseconds msredis 30000
sentinel parallel-syncs msredis 1
sentinel failover-timeout msredis 180000
daemonize yes
启动三个哨兵redis-sentinel sentinel-26379.conf
如下图则算启动成功
6379进程被杀死之后,哨兵会自动选择一个接入为主,重启6379重新连接会变为从库,如果需要和之前一样,需要重启配置文件
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下