请在我的开源博文:Redis 主从复制Replication功能 https://blog.youkuaiyun.com/dong19891210/article/details/106669143的基础上看下文,我是接着续写
把redis默认Sentinel配置文件sentinel.conff重命名为sentinelMaster.conf(名字可以随便起,但最好一看名字就知道意思)
mv sentinel.conf sentinelMaster.conf
然后通过复制sentinelMaster.conf的方式生成两个salve配置文件:sentinelSlave01.conf和sentinelSlave02.conf
cp sentinelMaster.conf sentinelSlave01.conf
cp sentinelMaster.conf sentinelSlave02.conf
分别一一修改三个配置文件vim sentinelMaster.conf修改以下参数内容:
然后依次启动三个哨兵节点:
redis-sentinel /dgm/redis/sentinelMaster.conf
redis-sentinel /dgm/redis/sentinelSlave01.conf
redis-sentinel /dgm/redis/sentinelSlave02.conf
检查验证Sentinel状态,连接任意Sentinel节点:
[root@master redis]# redis-cli -h 192.168.8.200 -p 26379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.200:26379> info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
192.168.8.200:26379>
可观察到master地址,端口正确。slave节点,sentinel节点数量正确。
sentinel monitor mymaster 127.0.0.1 6379 2
配置代表节点需要监控127.0.0.1:6379这个主节点,2代表判断主节点失败至少需要2个Sentinel节点同意,mymaster是主节点的别名。
配置代码已上传:https://github.com/dongguangming/java/tree/master/redis
参考:
0、Redis Sentinel Documentation
https://redis.io/topics/sentinel
1、 《Redis官方文档》sentinel https://ifeve.com/redis-sentinel/
2、Redis哨兵(Sentinel)模式 https://www.jianshu.com/p/06ab9daf921d
3. Redis Sentinel高可用 http://www.bjpowernode.com/tutorial_redis/340.html
4. 基于Sentinel的Redis高可用方案 http://www.360doc.com/content/15/0323/17/5054188_457454442.shtml
5、How to Setup Redis For High Availability with Sentinel in CentOS 8 https://www.tecmint.com/setup-redis-high-availability-with-sentinel-in-centos-8/
6. redis sentinel设计与实现 http://www.blogjava.net/jinfeng_wang/archive/2016/12/14/432107.html
7. redis哨兵(Sentinel)模式详解 https://zhuanlan.zhihu.com/p/67917170
8. redis sentinel 中的一个坑bind 顺序 https://blog.51cto.com/axe999/2338530
9. redis主从设置以及通过Sentinel(哨兵)实现的高可用 https://blog.51cto.com/kerry/2341308?source=dra