Redis Sentinel配置小记
1 2 3 4 5 6 |
port 26329 sentinel monitor myredis 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 60000 sentinel failover-timeout mymaster 180000 sentinel parallel-syncs mymaster 1 sentinel notification-script myredis <script-path> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/etc/redis/redis-m.conf daemonize yes pidfile /var/run/redis/redis-server-m.pid port 6379 loglevel notice logfile /var/log/redis/redis-server-m.log databases 16 ##disable snapshot save "" dir /app/redis-m appendonly yes appendfilename "appendonly.aof" ##not to be a slave #slaveof no one /etc/redis/redis-s1.conf daemonize yes pidfile /var/run/redis/redis-server-s1.pid port 6380 loglevel warning logfile /var/log/redis/redis-server-s1.log databases 16 ##disable snapshot save "" dir /app/redis-s1 appendonly yes appendfilename "appendonly.aof" ##to be a slave /etc/redis/redis-s2.conf daemonize yes pidfile /var/run/redis/redis-server-s2.pid port 6381 loglevel warning logfile /var/log/redis/redis-server-s2.log databases 16 ##disable snapshot,enable AOF save "" dir /app/redis-s2 appendonly yes appendfilename "appendonly.aof" ##to be a slave slaveof 127.0.0.1 6379 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
ps -ef | grep redis root 17560 1 0 09:48 ? 00:00:00 redis-server *:6379 root 17572 1 0 09:48 ? 00:00:00 redis-server *:6380 root 17609 1 0 09:49 ? 00:00:00 redis-server *:6381 redis-cli 127.0.0.1:6379> info replication # Replication role:master connected_slaves:2 slave0:ip=127.0.0.1,port=6380,state=online,offset=547,lag=0 slave1:ip=127.0.0.1,port=6381,state=online,offset=547,lag=1 master_repl_offset:547 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:546 |
1 2 3 4 5 6 |
port 26379 sentinel monitor myredis 127.0.0.1 6379 2 sentinel down-after-milliseconds myredis 60000 sentinel failover-timeout myredis 180000 sentinel parallel-syncs myredis 1 sentinel notification-script myredis /etc/redis/log-issues.sh |
1 2 3 |
#!/bin/bash echo "master failovered at `date`" > /root/redis_issues.log |
1 2 3 4 |
# nohup redis-sentinel /etc/redis/sentinel1.conf > /root/sentinel1.log 2>&1 & [1] 18207 # nohup redis-sentinel /etc/redis/sentinel2.conf > /root/sentinel2.log 2>&1 & [2] 18212 |
1 2 3 4 5 |
[18207] 08 May 13:28:29.336 # Sentinel runid is d72be991001b994568d3de1b746f611884b0343a [18207] 08 May 13:28:29.336 # +monitor master myredis 127.0.0.1 6379 quorum 2 [18207] 08 May 13:28:29.339 * +slave slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6379 [18207] 08 May 13:28:29.339 * +slave slave 127.0.0.1:6381 127.0.0.1 6381 @ myredis 127.0.0.1 6379 [18207] 08 May 13:28:36.602 * +sentinel sentinel 127.0.0.1:26479 127.0.0.1 26479 @ myredis 127.0.0.1 6379 |
1 2 3 |
# redis-cli -p 26379 127.0.0.1:26379> ping PONG |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
127.0.0.1:26379> sentinel masters 1) 1) "name" 2) "myredis" 3) "ip" 4) "127.0.0.1" 5) "port" 6) "6379" 7) "runid" 8) "a88ffd6548e333f3ac895cf1b890ef32a527dd66" ...... 37) "parallel-syncs" 38) "1" 39) "notification-script" 40) "/etc/redis/log-issues.sh" 127.0.0.1:26379> sentinel slaves myredis 1) 1) "name" 2) "127.0.0.1:6381" 3) "ip" 4) "127.0.0.1" 5) "port" 6) "6381" ...... 2) 1) "name" 2) "127.0.0.1:6380" 3) "ip" 4) "127.0.0.1" 5) "port" 6) "6380" ....... |
1 2 3 |
127.0.0.1:26379> sentinel get-master-addr-by-name myredis 1) "127.0.0.1" 2) "6379" |
1 2 |
127.0.0.1:26379> sentinel failover myredis OK |
1 2 3 4 5 6 7 8 9 10 11 |
127.0.0.1:26379> sentinel get-master-addr-by-name myredis 1) "127.0.0.1" 2) "6381" ## redis-cli中 redis-cli 127.0.0.1:6379> info replication # Replication role:slave master_host:127.0.0.1 master_port:6381 master_link_status:up |
1 2 3 4 5 |
127.0.0.1:26379> PSUBSCRIBE * Reading messages... (press Ctrl-C to quit) 1) "psubscribe" 2) "*" 3) (integer) 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
1) "pmessage" 2) "*" 3) "+new-epoch" 4) "2" 1) "pmessage" 2) "*" 3) "+try-failover" 4) "master myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+vote-for-leader" 4) "d72be991001b994568d3de1b746f611884b0343a 2" 1) "pmessage" 2) "*" 3) "+elected-leader" 4) "master myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+failover-state-select-slave" 4) "master myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+selected-slave" 4) "slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+failover-state-send-slaveof-noone" 4) "slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+failover-state-wait-promotion" 4) "slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "-role-change" 4) "slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381 new reported role is master" 1) "pmessage" 2) "*" 3) "+promoted-slave" 4) "slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+failover-state-reconf-slaves" 4) "master myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+slave-reconf-sent" 4) "slave 127.0.0.1:6379 127.0.0.1 6379 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+slave-reconf-inprog" 4) "slave 127.0.0.1:6379 127.0.0.1 6379 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+slave-reconf-done" 4) "slave 127.0.0.1:6379 127.0.0.1 6379 @ myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+failover-end" 4) "master myredis 127.0.0.1 6381" 1) "pmessage" 2) "*" 3) "+switch-master" 4) "myredis 127.0.0.1 6381 127.0.0.1 6380" 1) "pmessage" 2) "*" 3) "+slave" 4) "slave 127.0.0.1:6379 127.0.0.1 6379 @ myredis 127.0.0.1 6380" 1) "pmessage" 2) "*" 3) "+slave" 4) "slave 127.0.0.1:6381 127.0.0.1 6381 @ myredis 127.0.0.1 6380" 1) "pmessage" 2) "*" 3) "-role-change" 4) "slave 127.0.0.1:6381 127.0.0.1 6381 @ myredis 127.0.0.1 6380 new reported role is master" 1) "pmessage" 2) "*" 3) "+role-change" 4) "slave 127.0.0.1:6381 127.0.0.1 6381 @ myredis 127.0.0.1 6380 new reported role is slave" |
1 2 3 4 5 |
127.0.0.1:6379> info replication # Replication role:slave master_host:127.0.0.1 master_port:6380 |
1 2 3 4 5 6 7 |
[18207] 08 May 14:20:32.784 # +sdown master myredis 127.0.0.1 6380 [18207] 08 May 14:20:32.855 # +odown master myredis 127.0.0.1 6380 #quorum 2/2 [18207] 08 May 14:20:32.855 # +new-epoch 3 ......投票、选举...... [18207] 08 May 14:20:34.989 # +switch-master myredis 127.0.0.1 6380 127.0.0.1 6381 [18207] 08 May 14:20:34.989 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ myredis 127.0.0.1 6381 [18207] 08 May 14:20:34.992 * +slave slave 127.0.0.1:6380 127.0.0.1 6380 @ myredis 127.0.0.1 6381 |
1 2 3 4 5 6 7 8 |
$ redis-server /etc/redis/redis-s1.conf $ redis-cli -p 6380 127.0.0.1:6380> info replication # Replication role:slave master_host:127.0.0.1 master_port:6381 master_link_status:up |
1 2 3 4 5 6 7 |
vim sentinel.py from redis.sentinel import Sentinel sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1) master = sentinel.master_for('myredis', socket_timeout=0.1) master.set('foo', 'bar') slave = sentinel.slave_for('myredis', socket_timeout=0.1) slave.get('foo') |
1 2 |
python sentinel.py bar |
Redis Sentinel配置小记的更多相关文章
- redis sentinel 配置
在最小配置:master.slave各一个节点的情况下,不管是master还是slave down掉一个,“完整的”读/写功能都将受影响,这在生产环境中显然不能接受.幸好redis提供了sentine ...
- Redis Sentinel 高可用服务搭建
阅读目录: 关于 Redis 的概念 关于 Redis Sentinel 的概念 搭建 Redis Server(master) 搭建 Redis Server(slave) 搭建 Redis Sen ...
- 【转载】Redis Sentinel 高可用服务架构搭建
作者:田园里的蟋蟀 出处:http://www.cnblogs.com/xishuai/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 阅读 ...
- Redis 安装,主从配置及Sentinel配置自动Failover
1.安装redis 首页地址:http://redis.io/ 下载地址:http://download.redis.io/ 下载最新的源码包 tar -zxvf redis-stable.tar.g ...
- redis sentinel集群配置及haproxy配置
ip分布情况: sentinel-1/redis 主 10.11.11.5 sentinel-2/redis 从 10.11.11.7 sentinel-3/redis 从 10.11.11.8 ha ...
- laravel redis sentinel 和 redis cluster 配置
laravel redis sentinel配置: 'redis' => [ 'cluster' => false, 'options' => [ 'replication' =&g ...
- Redis Sentinel主从高可用方案
Redis Sentinel主从高可用方案 本文介绍一种通过Jed和Sentinel实现Redis集群(主从)的高可用方案,该方案需要使用Jedis2.2.2及以上版本(强制),Redis2.8及以上 ...
- spring集成redis——主从配置以及哨兵监控
Redis主从模式配置: Redis的主从模式配置是非常简单的,首先我们需要有2个可运行的redis环境: master node : 192.168.56.101 8887 slave node: ...
- redis sentinel集群
ip分布情况: sentinel-1/redis 主 10.11.11.5 sentinel-2/redis 从 10.11.11.7 sentinel-3/redis 从 10.11.11.8 ha ...
随机推荐
- 一段文字中的几个keyword显示高亮
将一段文字中的几个keyword显示高亮 演示样例:将"我的愿望是当个绿巨人,所以我想让我的皮(derma)肤是绿色"中的"皮肤"显示绿色. <span ...
- string.prototype.replace 和正则表达式
字符串的replace方法是操作字符串的常用方法之一,但这个方法只有当与正则合并使用时,才能体现出它的强大之处. 语法:str.replace(regexp|substr, newsubStr|fun ...
- 学习Git的最佳资料
1. ProGit中文版:https://git-scm.com/book/zh/v2 2. 廖雪峰的Git教程: http://www.liaoxuefeng.com/wiki/0013739516 ...
- C# 接口使用方法
之前一直不理解接口这一概念,今天无意中翻书,网上查资料悟道其中的道理,现在工作没有用到interface这一块,怕以后会遇到忘记实现的方法便记录下来,哪里写的不对希望读者指出,话不多说,接下来看我对接 ...
- Spark术语
1.resilient distributed dataset (RDD) The core programming abstraction in Spark, consisting of a fau ...
- Asp.Net Web API(六)
Asp.Net Web API不可以需要IIS.可以自己在主机上承载一个Web API 创建WebAPI.Server项目 创建一个控制器项目的服务端 在Nuget中添加Microsoft.AspNe ...
- 解决win7中防火墙的0x6D9问题的方法
问题: 打开windows防火墙管理单元时出错:代码0x6d9" 解决方法: 下一步-->下一步-->完成.
- iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
iOS超全开源框架.项目和学习资料汇总--数据库.缓存处理.图像浏览.摄像照相视频音频篇 感谢:Ming_en_long 的分享 大神超赞的集合,http://www.jianshu.com/p/f3 ...
- 本地如何操作服务器的mysql,详细教程
前置条件: 1.在阿里云服务器de系统是win service 2012. 2.服务器里自己安装了my sql 5.7 3.本地也安装了my sql 5.7 需求:想通过本地的mysql连接上远程的服 ...
- Python 多线程进程高级指南(二)
本文是如何<优雅地实现Python通用多线程/进程并行模块>的后续.因为我发现,自认为懂了一点多线程开发的皮毛,写了那么个multi_helper的玩意儿,后来才发现我靠原来就是一坨屎.自 ...