一.序言
redis 前面介绍了下master-salve ,但是其实它还无法完成故障自动切换的的效果。redis 2.8+ 已经提供了一种相对稳定的机制,防止单点:sentinel ,地址:http://redis.io/topics/sentinel
二.基本功能点
1.Monitor :它能监控redis 实例是否运行正常
2.Notification : 发现监控的redis 实例错误,它能能通过API,通知另一个机器
3.Automatic failover:如果master没按预期的运行,那么它会自动将salve提升为master,并提供连接。并且其他的salve 也会连接到新的master 上。
4.Configuration provider :Sentinel 作为连接客户端的中心,客户端连接上sentinel 并提供一个可用的服务,如果服务挂掉,会自动转移到新的可用服务上。
三.sentinel 支持分布式集群
它本身就支持集群部署,通常我们要2n+1个节点,和ZK原理类似,如果有一半节点发现redis master不可用,那么就会认为不可用,则转移节点。这样能减少误判。
目前稳定版是2.8 和 3.0 版本是最稳定的。
四.简单配置
1. 有个redis-sentinel 启动器,和 redis-server 类似的,启动方式 redis-sentinel sentinel.conf
redis-sentinel sentinel.conf
2. sentinel.conf 配置,这里我也用了3个节点配置
# 端口,每个sentinel 实例不同,端口不同 port 26379 # 监控的master节点信息, 2:表示需要2个监控着同意 判定失败 # 2 只是一个配置值,必须是大多数 就行了,少了 会自动更改的 sentinel monitor mymaster 127.0.0.1 6379 2 # 6秒ping 不通,认为失败 sentinel down-after-milliseconds mymaster 60000 # 故障超时时间,英语不好,就不解释了 sentinel failover-timeout mymaster 180000 # 我的理解是,故障恢复后,新的master 和 savle 之间同步线程数, # 因为要进行新一次的同步,slave 很多,这个值越小越慢 sentinel parallel-syncs mymaster 1 # salve 转移的配置,resque 没找到说明- - sentinel monitor resque 127.0.0.1 10001 4 sentinel down-after-milliseconds resque 10000 sentinel failover-timeout resque 180000 sentinel parallel-syncs resque 5
3.启动redis 实例 和 sentinel 监控
# 路径就不贴了 redis-server redis-6379.conf redis-server redis-10001.conf redis-sentinel redis-sentinel-23769.conf redis-sentinel redis-sentinel-23768.conf redis-sentinel redis-sentinel-23767.conf
4. 能启动就OK了
五.jredis 测试
@org.junit.Test public void sentinePool(){ // 连接监控就行了 Set sentinels = new HashSet(); sentinels.add(new HostAndPort("localhost", 26379).toString()); sentinels.add(new HostAndPort("localhost", 26378).toString()); sentinels.add(new HostAndPort("localhost", 26377).toString()); JedisSentinelPool sentinelPool = new JedisSentinelPool("mymaster", sentinels); Jedis jredis = sentinelPool.getResource(); System.out.println(jredis.keys("*")); }
测试反馈:
1.key数据全部获取(很少数据)
2.手动停掉master 6379 ,几秒后 连接OK,转移途中会有异常
3.重启6379 成为了salve,数据同步OK。
4.反复操作,能保证可用性,但是挂掉的时候有几秒连不上。
5.同时停掉redis,再重启,恢复到重启前,MS结果不变,因为conf 有持久化的ID
六.其他:
当你通过配置这个时候,sentinel.conf 的文件会改写,持久化一些ID进去,这是该改写后的文件:
# 其中一个文件的 port 26377 sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 60000 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3 sentinel known-slave mymaster 127.0.0.1 10001 sentinel known-sentinel mymaster 127.0.0.1 26379 627853b7495425dc3a558ba981f5cbcd619b6417 sentinel known-sentinel mymaster 127.0.0.1 26378 0a825a64892c136b033f1a961f3f4feb92ef2402 sentinel monitor resque 127.0.0.1 10001 4 # Generated by CONFIG REWRITE dir "/Users/qqr" sentinel down-after-milliseconds resque 10000 sentinel parallel-syncs resque 5 sentinel config-epoch resque 0 sentinel leader-epoch resque 0 sentinel known-slave resque 127.0.0.1 6379 sentinel known-sentinel resque 127.0.0.1 26379 627853b7495425dc3a558ba981f5cbcd619b6417 sentinel known-sentinel resque 127.0.0.1 26378 0a825a64892c136b033f1a961f3f4feb92ef2402 sentinel current-epoch 3
小结:
1.这仅仅是个简单试用,很多配置还是看原文代码
2.原理是通过发布订阅完成监控,挺好的~。~,很多东西还没深入,有错请指出
相关推荐
redis-sentinel 基于 phpredis 扩展的 redis-sentinel 客户端
Windos系统的Redis sentinel集群。 启动命令:D:\redis-2.8.18.rar\redis-2.8.18>redis-server.exe sentinel.conf --sentinel
Redis Sentinel 主从部署 使用Python脚本获取Redis主从节点信息
示例:$sentinel = new \Jenner\RedisSentinel\Sentinel(); $sentinel->connect('127.0.0.1', 6379); $address = $sentinel->getMasterAddrByName('mymaster'); $redis = new Redis(); $redis->connect($...
redis sentinel与redis cluster 集群配置
Redis Sentinel(哨兵)部署.pdf Redis Sentinel(哨兵)部署.pdf Redis Sentinel(哨兵)部署.pdf
二、Redis sentinel的工作机制 三、案例:构建Redis sentinel集群 四、案例:Keepalived+Haproxy+Redis实现高可用
Windows环境下的Redis Sentinel 集群搭建,包括安装文件和配置文件
linux docker redis sentinel 安装配置文件
redishappy, Redis Sentinel高availabillity守护进程 redishappy 提供高度可用的Redis服务的一种方法是使用 Redis Sentinel 部署。Redis Sentinel监视你的Redis集群并检测故障,提升从节点成为新的主机。 RedisHappy...
用于Redis Sentinel的Laravel驱动程序 用于Laravel和Lumen的Redis Sentinel集成。 有助于为配置为主从复制的Redis服务器提供高可用性,监视和负载平衡。 内置了对Redis的支持,但是我们不能灵活地开箱即配置...
redis Sentinel模式详解.docx
NULL 博文链接:https://yuhuiblog695685688425687986842568269.iteye.com/blog/2391347
spring + redis + sentinel 配置文件,同学们可以下载使用,有问题请指教。
predixy是一款高性能、全特性的redis代理,性能之高超越所有其它同类...redis全特性支持,无论是redis cluster还是redis sentinel都不在话下,更不用说redis自身的阻塞式命令、多key命令、事务、发布订阅、脚本等。
ansible-redis, 高度可以配置的Ansible角色,可以从源代码安装Redis和 Redis Sentinel ansible-redis Ansible 2.1 与大多数版本的ubuntu/debian和 rhel/centos 6兼容电子邮件内容安装工具正在开始运行。单一 Redis ...
redis+sentinel+tomcat部署Linux详细步骤,带安装包,自动脚本。redis+sentinel+tomcat部署Linux详细步骤,带安装包,自动脚本。redis+sentinel+tomcat部署Linux详细步骤,带安装包,自动脚本。
redis sentinel部署(Windows下实现).rar
Redis sentinel原理及实现源码剖析冯光普 @ 多点Dmall• 多点Dmall数据库负责人• bugfix、特性开发、技术研究主要内容• Senti
实现了自动安装配置redis 已经测试过了,如果有问题,请留言 启动脚本需要 3个参数 serverIP masterIP redisType 例如, 作为master ./redis_create.sh 192.168.10.10 192.168.10.10 master 作为slave ./redis_...