1.redis采用m-s配置的高可用方案。
sentinel的主要功能:
1、master存活检测
2、集群中M-S服务监控
3、自动故障转移,M-S角色转换等能力(当master失效后,sentinel可以帮助我们自动将slave提升为master)
总之,监控Redis M-S(master,slaves)存活并对相应故障进行处理,提高redis集群的可用性。
集群情况:最小M-S单元各有一个maste和slave组成;也可以一个maste多个slave组成
1.修改master配置文件 redis.conf
bind 172.31.225.21 #本地ip 不要使用127.0.0.1
port 6379 #端口
requirepass 7890uiop 访问密码
2.修改slave配置文件
port 6380 #端口
slaveof 172.31.225.21 6379
masterauth 7890uiop
requirepass 7890uiop #和master的密码要一样,因为sentinel将slave提升为master时,要密码验证
bind 172.31.225.21 #同一台主机也不要用127.0.0.1,使用ip
3.修改slave2配置文件
port 6380 #端口
slaveof 172.31.225.21 6379
masterauth 7890uiop
requirepass 7890uiop #和master的密码要一样,因为sentinel将slave提升为master时,要密码验证
bind 172.31.225.21 #同一台主机也不要用127.0.0.1,使用ip
4.sentinel的配置文件
bind 172.31.225.21
port 26379
dir "D:\\Redis-x64-3.2.100\\sentinel"
sentinel myid 6933e46f2a5c0071ef22f5be2a77eee0faaf6665
sentinel monitor mymaster 172.31.225.21 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel auth-pass mymaster 7890uiop
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 1
sentinel known-slave mymaster 172.31.225.21 6381
sentinel known-slave mymaster 172.31.225.21 6380
sentinel current-epoch 1
5.sentinel-1的配置文件
bind 172.31.225.21
port 26380
dir "D:\\Redis-x64-3.2.100\\sentinel"
sentinel myid 6933e46f2a5c0071ef22f5be2a77eee0faaf6665
sentinel monitor mymaster 172.31.225.21 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel auth-pass mymaster 7890uiop
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 1
sentinel known-slave mymaster 172.31.225.21 6381
sentinel known-slave mymaster 172.31.225.21 6380
sentinel current-epoch 1
5.sentinel-2的配置文件
bind 172.31.225.21
port 26381
dir "D:\\Redis-x64-3.2.100\\sentinel"
sentinel myid 6933e46f2a5c0071ef22f5be2a77eee0faaf6665
sentinel monitor mymaster 172.31.225.21 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel auth-pass mymaster 7890uiop
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 1
sentinel known-slave mymaster 172.31.225.21 6381
sentinel known-slave mymaster 172.31.225.21 6380
sentinel current-epoch 1
到此配置结束,sentinel配置的每个属性,这里不再细说,自己百度。然后启动master slave sentinel