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 ...
随机推荐
- java_多态
一.多态(对象的多种形态)1.引用的多态 父类的引用指向本类的对象 父类的引用指向子类的对象(引用多态) (不允许子类对象指向父类)2.方法多态 创建本类对象时调用的方法为本类的方法 创建子类对象时, ...
- 【SqlServer】JSON函数
1 概述 本篇文件将结合MSND简要分析Sqlserver中JSON函数,主要包括ISJSON,JSON_VALUE,JSON_MODIFY,JSON_QUERY. 2 具体内容 2.1 J ...
- jersey实现文件下载
好久没有更新博客了,今天来再次总结一下,之前有整理过关于jersey实现文件上传功能的相关知识,但是前一阵子在实习过程中写接口又要实现文件下载的功能,由于这些东西基本都是使用jersey提供的注解和接 ...
- Postgres中的物化节点之sort节点
顾名思义,物化节点是一类可缓存元组的节点.在执行过程中,很多扩展的物理操作符需要首先获取所有的元组后才能进行操作(例如聚集函数操作.没有索引辅助的排序等),这时要用物化节点将元组缓存起来.下面列出了P ...
- springboot 结合mybatis
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 XML ...
- mouseout、mouseover和mouseleave、mouseenter区别
今天在使用鼠标事件时,用错了mouseout,于是做个测试总结. 结论: mouseenter:当鼠标移入某元素时触发. mouseleave:当鼠标移出某元素时触发. mouseover:当鼠标移入 ...
- ArcGIS 网络分析[2.2] 服务区分析
什么是服务区? 我们先提一个很常见的社会现象:一个医院,如果要发起抢救,那么10分钟内能去多远? 时间就是生命,当结合道路网的阻力进行最短路径分析时,得到的可达的覆盖区域,这个区域就是服务区. 服务区 ...
- express整合webpack的打包文件dist
对于我来说,第一次接触前后端整合问题的小白,刚开始是一脸懵逼,这个问题整整坑了我一个晚上加一个早上,现在写出来总结: 前端开发:vue-cli+webpack: 后台开发:nodejs框架expres ...
- 使用 Kafka 和 ELK 搭建测试日志系统(1)
本文仅供自己学习,不合适转载. 这是两篇文章的第一部分. 1. 安装 ELK 1.1 安装 ElasticSearch 在海航云上创建一个 Ubutu 16.4 虚机,2核4GB内存. (1)执行以下 ...
- uptime 命令详解
作用: 打印系统总共运行了多长时间和系统的平均负载. uptime 命令可以显示的信息依次为: 现在时间, 系统已经运行时间, 目前登录用户个数, 系统1,5,15 分钟内的平均负载 实例: up ...