CentOS7下Redis4.0.10集群 Sentinel哨兵集群模式
主节点配置:主节点使用默认配置文件即可运行,具体配置如下:
发布日期:2021-04-30 21:01:16
浏览次数:116
分类:精选文章
本文共 1833 字,大约阅读时间需要 6 分钟。
Redis哨兵(Sentinel)集群部署指南
1.哨兵经典架构
哨兵(Sentinel)是Redis提供的一种高可用性解决方案,通过部署多个Redis实例并使用哨兵进行故障转移和自动化恢复,确保 Redis服务的高可用性和可靠性。
1.1哨兵结构
哨兵架构由以下几个关键组件构成:
- Redis Master: 主节点,负责数据的写入和读取,其他从节点复制数据
- Redis Slave: 从节点,负责数据的复制和读取,通常用于负载均衡和数据冗余
- 哨兵(Sentinel): 监控Master和Slave节点的状态,负责故障转移和自动化恢复
2.集群环境
2.1Linux服务器列表
以下是当前集群环境下的Linux服务器列表:
| IP | HOSTNAME |
|---|---|
| 192.168.48.13 | node3.xzsyr.com |
| 192.168.48.14 | node4.xzsyr.com |
| 192.168.48.15 | node5.xzsyr.com |
2.2Redis服务部署环境
在上述Linux服务器中,部署了Redis服务,构成一个 Sentinel 集群。具体配置如下:
| IP | HOSTNAME | Sentinel |
|---|---|---|
| 192.168.48.13 | node3.xzsyr.com | √ |
| 192.168.48.14 | node4.xzsyr.com | √ |
| 192.168.48.15 | node5.xzsyr.com | √ |
2.3配置并启动Redis主从集群
配置步骤
# slaveofslaveof 192.168.48.13 6379
- 从节点配置:从节点需要修改配置文件,添加以下内容:
- 启动主节点:
- 启动从节点:
- 验证集群状态:通过Redis CLI查看主节点的复制状态:
- 编辑Sentinel配置文件:
- 启动Sentinel服务:在所有Redis节点上执行以下命令:
- 停止主节点:
- 启动主节点:
- 验证故障转移:通过查看从节点的复制状态,确保数据恢复正常。
# slaveofslaveof 192.168.48.13 6379
启动步骤
[root@node3 src]# ./redis-server 192.168.48.13:6379
[root@node4 src]# ./redis-server ../redis.conf 6379[root@node5 src]# ./redis-server ../redis.conf 6379
[root@node3 src]# ./redis-cli -h 192.168.48.13 -p 6379 info Replication
2.4配置Sentinel集群并启动
配置步骤
# sentinel monitor mymaster 192.168.48.13 6379 2# sentinel down-after-milliseconds master001 30000# sentinel parallel-syncs master001 1# sentinel failover-timeout master001 180000
[root@node3 src]# ./redis-sentinel ../sentinel.conf[root@node4 src]# ./redis-sentinel ../sentinel.conf[root@node5 src]# ./redis-sentinel ../sentinel.conf
查看集群状态
通过Redis CLI查看Sentinel集群状态:
[root@node3 src]# ./redis-cli -h 192.168.48.13 -p 26379 info Sentinel
2.5测试Sentinel集群
测试步骤
[root@node3 src]# ./redis-cli -h 192.168.48.13 -p 6379 shutdown
[root@node3 src]# ./redis-server 192.168.48.13:6379
[root@node4 src]# ./redis-cli -h 192.168.48.14 -p 6379 info Replication
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2026年05月24日 19时32分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!