【redis使用系列】redis5.0的sentinel模式体验

参考资料

https://www.cnblogs.com/ibethfy/p/9965902.html
http://redisdoc.com/topic/sentinel.html

sentinel架构和整体规划

sentinel模式的整体架构

部署整体规划

redis-server节点

一主两从(生产环境不要部署在一台机器上,从概率学的角度,风险很大):

master: 192.168.172.4:7001
slave1: 192.168.172.4:7002
slave2: 192.168.172.4:7003

redis-sentinel节点

三个节点(生产环境不要部署在一台机器上,从概率学的角度,风险很大):

node1: 192.168.172.7:27001
node2: 192.168.172.7:27002
mode3: 192.168.172.7:27003

编译、安装、配置和启动

编译安装

编译安装参考单节点安装redis 5.0集群

配置

master节点配置

cat /data/redis/conf/redis7001.conf

#redis监听的本地IP地址
bind 192.168.172.4
#监听端口
port 7001
#开启后台运行,no表示运行在前台
daemonize yes
#pid文件,另一个节点改为7002
pidfile /var/run/redis_7001.pid
#开启aof日志,每次写操作都会记录一条日志
appendonly yes
appendfilename "appendonly7001.aof"
#开启集群,把注释去掉
cluster-enabled no
dbfilename dump7001.rdb

slave1节点配置

cat /data/redis/conf/redis7002.conf

#redis监听的本地IP地址
bind 192.168.172.4
#监听端口
port 7002
#开启后台运行,no表示运行在前台
daemonize yes
#pid文件,另一个节点改为7002
pidfile /var/run/redis_7002.pid
#开启aof日志,每次写操作都会记录一条日志
appendonly yes
appendfilename "appendonly7002.aof"
#开启集群,把注释去掉
cluster-enabled no
dbfilename dump7002.rdb
replicaof 192.168.172.4 7001

slave2节点配置

cat /data/redis/conf/redis7003.conf

#redis监听的本地IP地址
bind 192.168.172.4
#监听端口
port 7003
#开启后台运行,no表示运行在前台
daemonize yes
#pid文件,另一个节点改为7002
pidfile /var/run/redis_7003.pid
#开启aof日志,每次写操作都会记录一条日志
appendonly yes
appendfilename "appendonly7003.aof"
#开启集群,把注释去掉
cluster-enabled no
dbfilename dump7003.rdb
replicaof 192.168.172.4 7001

sentinel服务节点1配置

cat conf/sentinel27001.conf

protected-mode no
port 27001
daemonize yes
pidfile "/data/redis/sentinel27001/sentinel.pid"
logfile "/data/redis/sentinel27001/27001.log"
dir "/data/redis/sentinel27001"
#sentinel auth-pass master7000 ibethfy
sentinel monitor master7001 192.168.172.4 7001 2
# Generated by CONFIG REWRITE
sentinel down-after-milliseconds master7001 5000
sentinel failover-timeout master7001 30000

sentinel服务节点2配置

cat conf/sentinel27002.conf

protected-mode no
port 27002
daemonize yes
pidfile "/data/redis/sentinel27002/sentinel.pid"
logfile "/data/redis/sentinel27002/27002.log"
dir "/data/redis/sentinel27002"
#sentinel auth-pass master7000 ibethfy
sentinel monitor master7001 192.168.172.4 7001 2
# Generated by CONFIG REWRITE
sentinel down-after-milliseconds master7001 5000
sentinel failover-timeout master7001 30000

sentinel服务节点3配置

cat conf/sentinel27003.conf

protected-mode no
port 27003
daemonize yes
pidfile "/data/redis/sentinel27003/sentinel.pid"
logfile "/data/redis/sentinel27003/27003.log"
dir "/data/redis/sentinel27003"
#sentinel auth-pass master7001 ibethfy
sentinel monitor master7001 192.168.172.4 7001 2
# Generated by CONFIG REWRITE
sentinel down-after-milliseconds master7001 5000
sentinel failover-timeout master7001 30000

疑惑

在没有相互配置地址的时候,三个sentinel节点之间怎么相互发现呢。从官网看下说明:

启动服务

启动master节点:

redis-server /data/redis/conf/redis7001.conf

启动slave1节点:

redis-server /data/redis/conf/redis7002.conf

启动slave2节点:

redis-server /data/redis/conf/redis7003.conf

启动sentinel节点1:

redis-sentinel /data/redis/conf/sentinel27001.conf

启动sentinel节点2:

redis-sentinel /data/redis/conf/sentinel27002.conf

启动sentinel节点3:

redis-sentinel /data/redis/conf/sentinel27003.conf

体验

redis主从情况

sentinel服务情况

sentinel之间怎么相互发现的