redis高可用集群之哨兵机制

Redis哨兵机制工作原理(心跳检测+自动故障转移)
1).当哨兵启动时,首先会监控主机,从主机中获取当前所有的节点的状态,同时哨兵开启心跳检测机制.
2).当主机发生宕机的现象时,由于哨兵有PING-PONG机制 发现主机宕机,则哨兵开始进行选举.
3).当选举成功之后,新的主机当选之后,其他的节点当新主机的从.
解决: 1.单节点并发压力问题 2.单节点内存和磁盘物理上限
在这里插入图片描述

搭建环境

 1.在主节点上创建哨兵配置
- 在Master对应redis.conf同目录下新建sentinel.conf文件,名字绝对不能错;

 2.配置哨兵,在sentinel.conf文件中填入内容:
- sentinel monitor 被监控数据库名字(自己起名字) ip port 1

 3.启动哨兵模式进行测试
- redis-sentinel sentinel.conf
	说明:这个后面的数字2,是指当有两个及以上的sentinel服务检测到master宕机,才会去执行主从切换的功能。

编辑监控配置
在这里插入图片描述
修改选举时间
在这里插入图片描述
2.4 启动哨兵服务
命令: redis-sentinel sentinel.conf
在这里插入图片描述
高可用检查:
1).先关闭主机 等待10秒检查是否进行选举.
2).启动6379. 检查是否当选新主机的从.

用jedis操作redis
springboot整合哨兵机制
1.创建配置文件存储redis信息
在这里插入图片描述
jedis配置哨兵
在这里插入图片描述
springboot整合哨兵在程序配置文件中配置

 redis sentinel 配置
 master书写是使用哨兵监听的那个名称
spring.redis.sentinel.master=mymaster
连接的不再是一个具体redis主机,书写的是多个哨兵节点
spring.redis.sentinel.nodes=192.168.202.206:26379
  • 注意:如果连接过程中出现如下错误:RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2)
  • 解决方案:在哨兵的配置文件中加入bind 0.0.0.0 开启远程连接权限
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值