博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis Sentinel实现Failover
阅读量:5314 次
发布时间:2019-06-14

本文共 4222 字,大约阅读时间需要 14 分钟。

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
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                    
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
[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的配置。

转载于:https://www.cnblogs.com/Eivll0m/p/4810507.html

你可能感兴趣的文章
IIS 7.0的集成模式和经典模式
查看>>
Discrete Log Algorithms :Baby-step giant-step
查看>>
HDOJ1860 ( 统计字符 ) 【水题】
查看>>
hdu 1863(最小生成树kruskal)
查看>>
史上最全的Angular.js 的学习资源
查看>>
IOS原生地图与高德地图
查看>>
团队项目开发篇章8
查看>>
Java SpringMvc+hibernate架构中,调用Oracle中的sp,传递数组参数
查看>>
经验总结03-dwr
查看>>
[BZOJ 1072] 排列perm
查看>>
带有控制按钮的图片滚动
查看>>
11月16日站立会议
查看>>
Web前端笔试面试题汇总(转自github)
查看>>
Comparison of video container formats
查看>>
网络编程资源
查看>>
Android SDK 目录说明
查看>>
嵌入式第11次实验
查看>>
管道模式 pipe
查看>>
MySQL--字符集
查看>>
[USACO13JAN] Cow Lineup (单调队列,尺取法)
查看>>