redis版本:2.8.17
 
服务器规划:
10.50.13.34(6379 master)
10.50.13.35(6379 slave)
10.50.13.36(6379 slave)
10.50.13.37(6379 slave)
 
一、安装redis
tar zxf redis-2.8.17.tar.gz
cd redis-2.8.17
make
make install
mv redis-2.8.17 /app/sinova/redis
cd /app/sinova/redis
mkdir bin,conf,rdb,log
mv redis.conf sentinel.conf conf
find -maxdepth 1 -type f -delete
cd src
mv mkreleasehdr.sh redis-benchmark redis-sentinel redis-server redis-cli redis-check-aof redis-check-dump ../bin/
 
二、配置redis
redis.conf配置文件修改如下内容:
master配置:
daemonize yes
pidfile /app/sinova/redis/redis.pid 
logfile  /app/sinova/redis/log/redis.log
dir /app/sinova/redis/rdb

slave配置:

daemonize yes
pidfile /app/sinova/redis/redis.pid 
logfile  /app/sinova/redis/log/redis.log
dir /app/sinova/redis/rdb
slaveof 10.50.13.34 6379
 
三、配置sentinel

daemonize yes
logfile "/app/sinova/redis/log/sentinel.log"
 
sentinel monitor mymaster 10.50.13.34 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
 
四、启动redis
先启动master,然后再启动slave,命令相同,如下:
/app/sinova/redis/bin/redis-server /app/sinova/redis/conf/redis.conf
 
启动后查看主从状态:
 redis-cli info Replication
# Replication
role:master
connected_slaves:3
slave0:ip=10.50.13.35,port=6379,state=online,offset=29,lag=0
slave1:ip=10.50.13.36,port=6379,state=online,offset=29,lag=0
slave2:ip=10.50.13.37,port=6379,state=online,offset=29,lag=0
master_repl_offset:29
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:28
 
五、启动sentinel
先启动master,然后再启动slave,命令相同,如下:
/app/sinova/redis/bin/redis-sentinel /app/sinova/redis/conf/sentinel.conf
 
在master上查看/app/sinova/redis/log/sentinel.log   #slave下也有此日志,可以看到内容有变化
$ cat sentinel.log
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.17 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 16995
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'

[16995] 15 Sep 15:30:11.226 # Sentinel runid is cac946f212073a0e7c353e058dc7c83c9c62a161
[16995] 15 Sep 15:30:11.226 # +monitor master mymaster 10.50.13.34 6379 quorum 2
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.36:6379 10.50.13.36 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.264 * +sentinel sentinel 10.50.13.35:26379 10.50.13.35 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.306 * +sentinel sentinel 10.50.13.37:26379 10.50.13.37 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.312 * +sentinel sentinel 10.50.13.36:26379 10.50.13.36 26379 @ mymaster 10.50.13.34 6379

 
 
六、测试
停掉master上的redis
$ redis-cli shutdown
 
查看日志:
[16995] 15 Sep 15:33:54.131 # +sdown master mymaster 10.50.13.34 6379
[16995] 15 Sep 15:33:54.139 # +new-epoch 1
[16995] 15 Sep 15:33:54.145 # +vote-for-leader c6e609a1978e5cdb68ead8983ba88568aa85180d 1
[16995] 15 Sep 15:33:54.215 # +odown master mymaster 10.50.13.34 6379 #quorum 4/2
[16995] 15 Sep 15:33:54.215 # Next failover delay: I will not start a failover before Tue Sep 15 15:35:54 2015
[16995] 15 Sep 15:33:55.339 # +config-update-from sentinel 10.50.13.36:26379 10.50.13.36 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:33:55.339 # +switch-master mymaster 10.50.13.34 6379 10.50.13.36 6379
[16995] 15 Sep 15:33:55.339 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.36 6379
[16995] 15 Sep 15:33:55.344 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.36 6379
[16995] 15 Sep 15:33:55.350 * +slave slave 10.50.13.34:6379 10.50.13.34 6379 @ mymaster 10.50.13.36 6379
 
可以看到新的master为10.50.13.36
 
原来的master恢复后,会加入slave的行列:
查看sentinel.log:
[16995] 15 Sep 15:40:33.897 # -sdown slave 10.50.13.34:6379 10.50.13.34 6379 @ mymaster 10.50.13.36 6379
 
 
Sentinel在实现Failover过程中,会自动修改redis.conf和sentinel.conf的配置。

Redis Sentinel实现Failover的更多相关文章

  1. Redis Sentinel:集群Failover解决方案(转载)

    本文转载自:http://shift-alt-ctrl.iteye.com/blog/1884370 文中的配置例子,还有failover过程中触发的订阅事件具有很好的参考价值. Redis sent ...

  2. Redis Sentinel 高可用实现说明

    背景:      前面介绍了Redis 复制.Sentinel的搭建和原理说明,通过这篇文章大致能了解Sentinel的原理和实现方法以及相关的搭建.这篇文章就针对Redis Sentinel的搭建做 ...

  3. Redis Sentinel机制与用法说明【转】

    本文来自:https://segmentfault.com/a/1190000002680804 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Ma ...

  4. redis sentinel基本命令与参数

    1.redis基本命令1)获取sentinel的状态(1)info查看sentinel的状态(2)sentinel masters 获取sentinel中监控的所有master的节点(3)sentin ...

  5. Redis Sentinel机制与用法(一)

    Sentinel spring 集群配置: 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕 ...

  6. Redis Sentinel高可用架构

    Redis目前高可用的架构非常多,比如keepalived+redis,redis cluster,twemproxy,codis,这些架构各有优劣,今天暂且不说这些架构,今天主要说说redis se ...

  7. redis高可用之REDIS SENTINEL

    1. Redis主从配置 1.1. 设置主从复制 Master <= Salve 10.24.6.5:6379 <= 10.24.6.7:6379 1.2.   取消主从复制 1.3.   ...

  8. 【Redis】使用Redis Sentinel实现Redis HA

    阅读目录 1 sentinel down-after-milliseconds mymaster 30000 sentinel failover-timeout mymaster 18000 sent ...

  9. Redis Sentinel机制与用法

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...

随机推荐

  1. Objective-C:属性(@property)

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  2. linux-3.0下input_dev模型按键驱动

    该代码在FL2440开发板上测试通过,为方便教学,将驱动中的platform_device和platform_driver故意分为两个驱动模块. [guowenxue@centos6 input_kb ...

  3. openmpi+NFS+NIS搭建分布式计算集群

    1.        配置防火墙 正确配置防火墙的过滤规则,否则会造成NFS文件系统的挂载失败,NIS账户认证的失败,mpirun远程任务实例投放的失败.一般情况下,计算集群是在内部局域网中使用,所以可 ...

  4. CakePHP之Model

    模型 模型在应用程序中是作为业务层而存在的(怎么感觉是数据层......).这就意味着,模型应当负责管理几乎所有涉及数据的事情,其合法性,以及你的业务领域中数据在工作流程中的演化和互动 . 通常模型类 ...

  5. 在Weex中定制自定义组件

    1.配置自定义组件 public class MyViewComponent extends WXComponent{ public MyViewComponent(WXSDKInstance ins ...

  6. linux进程地址空间详解(转载)

    linux进程地址空间详解(转载) 在前面的<对一个程序在内存中的分析 >中很好的描述了程序在内存中的布局,这里对这个结果做些总结和实验验证.下面以Linux为例(实验结果显示window ...

  7. xpath 操作XML

    1.xpath 操作XML,底下部分代码被注释了,但是是完整功能,去除注释是正常使用的(有写命名和其他冲突,所以注释了) 总体有:完整读取xml,对xml的增删改查,对xml的特定操作 using S ...

  8. c#读取文件

    你平时是怎么读取文件的?使用流读取.是的没错,C#给我们提供了非常强大的类库(又一次吹捧了.NET一番), 里面封装了几乎所有我们可以想到的和我们没有想到的类,流是读取文件的一般手段,那么你真的会用它 ...

  9. eclipse build很慢的时候,有可能是js文件编译验证慢的问题

    第一步: 去除eclipse的JS验证: 将windows->preference->Java Script->Validator->Errors/Warnings-> ...

  10. HDU 3359 Kind of a Blur(高斯消元)

    题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...