搭建redis-5.0.5哨兵模式

前提:已安装好单机模式

版本:redid-5.0.5

创建redis-sentinel目录,用于存放相关配置

拷贝redis.conf sentinel.conf文件到redis-sentinel文件夹下

cp redis.conf sentinel.conf /work/redis-sentinel/

1.redis配置

1.1修改配置文件

将redis.conf重命名为redis6381.conf,并复制redis6382.conf、redis6383.conf,修改相应配置文件

redis6382.conf

daemonize yes
port 6381
pidfile /var/run/redis_sentinel_6381.pid
logfile "mylog6381"
dbfilename dump6381.rdb

redis6382.conf

daemonize yes
port 6382
pidfile /var/run/redis_sentinel_6381.pid
logfile "mylog6382"
dbfilename dump6382.rdb
slaveof 192.168.56.103 6381

redis6383.conf

daemonize yes
port 6383
pidfile /var/run/redis_sentinel_6381.pid
logfile "mylog6383"
dbfilename dump6383.rdb
slaveof 192.168.56.103 6381

1.2redis启动

redis-server /work/redis-sentinel/redis6381.conf
redis-server /work/redis-sentinel/redis6382.conf
redis-server /work/redis-sentinel/redis6383.conf

搭建redis-5.0.5哨兵模式_第1张图片

连接客户端查看

搭建redis-5.0.5哨兵模式_第2张图片

2.sentinel配置

2.1修改配置文件

分别创建sentinel01、sentinel01、 sentinel02文件夹,并把sentinel.conf分别拷贝到这三个文件夹里面,修改相应配置

sentinel01

daemonize yes
port 26381
protected-mode no
dir /work/redis-sentinel/sentinel01
sentinel monitor redis-master 192.168.56.103 6381 2
sentinel down-after-milliseconds redis-master 30000
sentinel failover-timeout redis-master 180000
sentinel parallel-syncs redis-master 1

sentinel02

daemonize yes
port 26382
protected-mode no
dir /work/redis-sentinel/sentinel02
sentinel monitor redis-master 192.168.56.103 6381 2
sentinel down-after-milliseconds redis-master 30000
sentinel failover-timeout redis-master 180000
sentinel parallel-syncs redis-master 1

sentinel03

daemonize yes
port 26383
protected-mode no
dir /work/redis-sentinel/sentinel03
sentinel monitor redis-master 192.168.56.103 6381 2
sentinel down-after-milliseconds redis-master 30000
sentinel failover-timeout redis-master 180000
sentinel parallel-syncs redis-master 1

2.2sentinel启动

redis-sentinel /work/redis-sentinel/sentinel01/sentinel.conf
redis-sentinel /work/redis-sentinel/sentinel02/sentinel.conf
redis-sentinel /work/redis-sentinel/sentinel03/sentinel.conf

搭建redis-5.0.5哨兵模式_第3张图片

3.测试

关闭master节点

搭建redis-5.0.5哨兵模式_第4张图片

连接到slave查看,发现master已经转移到6383这个实例上面了

搭建redis-5.0.5哨兵模式_第5张图片

搭建redis-5.0.5哨兵模式_第6张图片

重启6381,发现是slave角色,不再是master了。

搭建redis-5.0.5哨兵模式_第7张图片

 

你可能感兴趣的:(redis,redis,sentinel,redis哨兵模式)