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 ...
随机推荐
- SAP ABAP编程 Table Control动态隐藏列
在SAP DIALOG设计中,有时候须要动态的隐藏某些列,以下是方法. ***数据定义 CONTROLS: table_control TYPE TABLEVIEW USING SCREEN 0100 ...
- 【Jquery系列】JqGrid参数详解
1 概述 本篇文章主要与大家分享JqGrid插件参数问题. 2 参数详解 2.1 初始化参数 2.2 ColModel参数 3 json数据 jqGrid可支持的数据类型:xml.jso ...
- Python笔记·第七章—— IO(文件)处理
一.文件处理简介 计算机系统分为:计算机硬件,操作系统,应用程序三部分. 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件,众所周知 ...
- Java中流-----个人总结心得
流 字符流 字节流 缓冲区 数据流---用于传输数据.IO流---Input/Output流.数据从外部流向程序---输入流:数据从程序流向外部的时候--输出流.读取一个文件---数据从文件流向程序- ...
- Nginx干货(二)配置详解
此篇就不矫情了.直接上个配置吧.以后若有更新,继续修补 /usr/local/nginx/conf目录下面的nginx.conf文件 以用户nginx的身份来运行 user nginx; 启动进程,通 ...
- C#备份一个文件到指定的文件夹里面
一开始我的想法是这样的: //在控制台里面操作 static void Main(string[] args) { //backup( @"D:\gg\config.xml", @ ...
- arcgis api for js入门开发系列十五台风轨迹
上一篇实现了demo的地图最近设施点路径分析,本篇新增台风轨迹,截图如下: 下面简单介绍相关知识点: 警戒线 警戒线坐标集合: var lineArr24=[[127,34],[127,21],[11 ...
- MySQL in or效率对比
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/60 考虑如下两个sql: select * from table ...
- Who's in the Middle
FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' ...
- ecsmart的开发经历
ecsmart是ecshop的产品之一,是2015年发布的一套系统.关于它的介绍请到官网去了解,也可以百度 “商之翼” “ecsmart” 1.ecsmart分别在pc.mobile.app三个方面都 ...