
哨兵模式
redis集群搭建以后,就有了主从的架构模式,如果主节点挂了以后,虽然从节点是可以正常的读取数据,但是一旦有写的请求进来,就会报错,所以这个时候我们就需要一种模式可以进行保障主从的架构稳定可靠,这个就是哨兵模式。
下面是哨兵模式的配置:








将配置拿出来,其他的注释删掉,就是下面这种简化版本的配置了。


然后我们需要把这个配置都复制到另外的redis节点,然后就可以挨个启动了,使用命令redis-sentinel sentinel.conf
如果没有什么报错,就可以使用ps -ef | grep redis来查看下redis-sentinel是否启动了。
机制或者说成果:
如果有三台redis,1是主节点,2和3是从节点
如果1挂了,那么2和3中会竞选出一个作为主节点,假如是2节点成为了主节点那么:
1: 挂掉
2:主节点
3:从节点
这个时候如果1又重启正常了,那么1只能成为从节点:
1:从节点
2:主节点
3:从节点
网友评论