Redis配置哨兵模式
2020-03-05 本文已影响0人
FilesFan
1、创建3台虚拟机,相关信息如下
服务类型 是否为主节点 IP地址 端口
redis 是 192.168.1.4 6379
redis 否 192.168.1.5 6379
redis 否 192.168.1.6 6379
sentinel 192.168.1.4 26379
sentinel 192.168.1.5 26379
sentinel 192.168.1.6 26379
2、安装redis及sentinel
apt-get install redis redis-sentinel
3、修改配置文件
redis.conf redis服务的配置文件,因为是测试其他基本不需要修改,这里只列出做修改的部分
#grep -Ev '^$|^#' /etc/redis/redis.conf
bind 0.0.0.0 #绑定所有ip
protected-mode no #去掉保护模式,否则执行sentinel相关命名会失败
slaveof 192.168.1.4 6379 #只有2个slave节点配置
相关配置截图如下:

sentinel配置,因为都是一样的,我这里只贴一个

4、配置完成后重启redis及sentinel
systemctl restart redis
systemctl restart redis-sentinel
5、检查集群状态
redis状态

sentinel状态

master状态

slave状态


6.故障测试
将主节点192.168.1.4的服务停掉,查看slave日志

可以看到192.168.1.6成为了master。执行info命令查看,也可以看到角色的改变