Redis集群-Sentinel模式

我的目录结构:

 

优点:

1、哨兵集群,基于主从复制模式,具备主从配置优点

2、主从自动切换

缺点:
1、主从模式不方便扩容,集群容量达上限,在线扩容比较麻烦

 

 1.启动三个redis(一主二从),只修改端口和后台运行,不开集群

bind 127.0.0.1 192.168.1.236 //本机ip
pidfile /var/run/redis_6379.pid //守护进程id
daemonize yes //后台运行
port 6379 //我复制到redis_conf中的文件端口分别为6379、6380、6381

 2.配置redis主从关系

分别登陆6380、6381 redis,执行slaveof 命令,将这两个redis认6379为master,这两个为slave

 

 使用info replication查看配置后的关系

 

 

 

 

 

3.复制redis文件夹下sentinel.conf到sentinel_conf文件夹,为保证高可用,哨兵至少要启动三台或者奇数

 

4.依次修改复制sentinel.conf配置文件

port 26379 //端口
daemonize yes //后台运行
pidfile /var/run/redis-sentinel-26379.pid //后台运行PID
sentinel monitor mymaster 192.168.0.103 6379 2 //sentinel monitor 是哨兵监控的固定命令 ;mymaster是自定义起的名字,linux中没有太大作用,只用于spring连接配置使用;192.168.0.103 6379 代表的是监控Redis master机器(如果master是其他地址端口需修改,否则哨兵失效);
                             最后的2,代表如果有两台哨兵都发现master连接超时,就进行新的master选举,将现有master废除 

5.依次运行哨兵

redis-sentinel ../../sentinel_conf/sentinel_26379.conf

redis-sentinel ../../sentinel_conf/sentinel_26380.conf

redis-sentinel ../../sentinel_conf/sentinel_26381.conf

redis-sentinel在redis-5.0.8/src下

6.查看运行情况

7.测试master故障

将master6379,shutdown关闭,如果没有修改哨兵的sentinel down-after-milliseconds这个配置,那默认30秒后就会进行新的master选举,选举后原master6379再次启动,也只能当做slave从机

 

 

 

 

 

 

 

 

我这次调试的redis和哨兵模式的配置文件点击下载

 

posted @ 2020-05-16 23:39  RollBack2010  阅读(164)  评论(0编辑  收藏  举报