Redis哨兵配置
Sentinel(哨兵)是Redis 的高可用性解决方案:由一个或多个Sentinel 实例 组成的Sentinel 系统可以监视任意多个主服务器,以及这些主服务器属下的所有从服务器,并在被监视的主服务器进入下线状态时,自动将下线主服务器属下的某个从服务器升级为新的主服务器。
192.168.56.11的redis配置如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | bind 0.0 . 0.0 protected - mode yes port 6379 tcp - backlog 511 timeout 0 tcp - keepalive 300 daemonize yes supervised no pidfile "/var/run/redis_6379.pid" loglevel notice logfile "" databases 16 always - show - logo yes stop - writes - on - bgsave - error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "/etc/redis" masterauth "123456" slave - serve - stale - data yes slave - read - only yes repl - diskless - sync no repl - diskless - sync - delay 5 repl - disable - tcp - nodelay no slave - priority 100 requirepass "123456" lazyfree - lazy - eviction no lazyfree - lazy - expire no lazyfree - lazy - server - del no slave - lazy - flush no appendonly no appendfilename "appendonly.aof" appendfsync everysec no - appendfsync - on - rewrite no auto - aof - rewrite - percentage 100 auto - aof - rewrite - min - size 64mb aof - load - truncated yes aof - use - rdb - preamble no lua - time - limit 5000 slowlog - log - slower - than 10000 slowlog - max - len 128 latency - monitor - threshold 0 notify - keyspace - events "" hash - max - ziplist - entries 512 hash - max - ziplist - value 64 list - max - ziplist - size - 2 list - compress - depth 0 set - max - intset - entries 512 zset - max - ziplist - entries 128 zset - max - ziplist - value 64 hll - sparse - max - bytes 3000 activerehashing yes client - output - buffer - limit normal 0 0 0 client - output - buffer - limit slave 256mb 64mb 60 client - output - buffer - limit pubsub 32mb 8mb 60 hz 10 aof - rewrite - incremental - fsync yes |
192.168.56.12的redis配置是一样的
启动两台主机的redis
1 | redis - server / etc / redis / 6379.conf |
在192.168.56.12的redis命令行执行命令设置主从
1 | slaveof 192.168 . 56.11 6379 |
在11上面查看主从状态
在12上面查看主从状态
设置两台主机的哨兵配置/etc/redis/sentinel.conf
1 2 3 4 5 6 7 8 9 10 | protected - mode no port 26379 daemonize yes logfile "/var/log/redis/sentinel.log" dir "/tmp" sentinel myid 3e945f7ff33d43dc4a451fa13297bd0bd3940338 sentinel monitor mymaster 192.168 . 56.11 6379 2 sentinel auth - pass mymaster 123456 sentinel config - epoch mymaster 4 sentinel leader - epoch mymaster 4 |
两台主机配置一样
只需要设置监控的master对应的主机IP和端口,不要忘记需要设置加密的密码
启动哨兵
1 | redis - sentinel / etc / redis / sentinel.conf |
查看进程
关闭主的redis模拟master宕机同时查看哨兵日志
登录192.168.56.12查看主从状态可以看到提升为master了从是空的
重新启动11的redis
1 | redis - server / etc / redis / 6379.conf |
查看日志11成为12的从,12还是master
登录11查看主从状态
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!