Redis一主二从Sentinel监控配置

Redis一主二从Sentinel监控配置

游戏|数码彩彩2024-03-30 7:48:01491A+A-

 

本文基于redis单实例安装安装。

开启哨兵模式,至少需要3个Sentinel实例(奇数个,否则无法选举Leader)。

本例通过3个Sentinel实例监控3个Redis服务(1主2从)。

IP地址	 节点角色&端口
192.168.8.203	Master:6379 / Sentinel : 26379
192.168.8.204	Slave :6379 / Sentinel : 26379
192.168.8.205	Slave :6379 / Sentinel : 26379

网络结构图:

Redis一主二从Sentinel监控配置

 

在204和205的redis.conf配置中添加一行

slaveof 192.168.8.203 6379

在203、204、205创建sentinel配置文件(单例安装后根目录下默认有sentinel.conf,可以先备份默认的配置)

cd /usr/local/soft/redis-5.0.5
mkdir logs
mkdir rdbs
mkdir sentinel-tmp
vim sentinel.conf

sentinle.conf配置文件内容,三台机器相同

daemonize yes
port 26379
protected-mode no
dir "/usr/local/soft/redis-5.0.5/sentinel-tmp"
sentinel monitor redis-master 192.168.8.203 6379 2
sentinel down-after-milliseconds redis-master 30000
sentinel failover-timeout redis-master 180000
sentinel parallel-syncs redis-master 1

在3台机器上分别启动Redis和Sentinel

cd /usr/local/soft/redis-5.0.5/src
./redis-server ../redis.conf
./redis-sentinel ../sentinel.conf

在3台机器上查看集群状态:

redis> info replication
Redis一主二从Sentinel监控配置

 

模拟master宕机,在203执行:

redis> shutdown

注意看sentinel.conf里面的redis-master被修改了,变成了当前master的IP端口。

redis> info replication

这个时候会有一个slave节点被Sentinel设置为master。

再次启动master,它不一定会被选举为master。

slave宕机和恢复测试省略。

点击这里复制本文地址 版权声明:本文内容由网友提供,该文观点仅代表作者本人。本站(https://www.angyang.net.cn)仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

昂扬百科 © All Rights Reserved.  渝ICP备2023000803号-3网赚杂谈