redis配置master-slave模式
由于云服务器存在闪断现象,项目线上会存在基于redis的功能在闪断时段内出现异常,所以redis需要做master-slave模式。直接上代码:
原单机redis,RedisConnectionFactory设置代码
```
@Bean
public RedisConnectionFactory jedisConnectionFactory(){
JedisPoolConfig poolConfig=new JedisPoolConfig();
poolConfig.setMaxIdle(5);
poolConfig.setMinIdle(1);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setNumTestsPerEvictionRun(10);
poolConfig.setTimeBetweenEvictionRunsMillis(60000);
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(poolConfig);
//单机redis的host、port设置
jedisConnectionFactory.setHostName(redishost);
jedisConnectionFactory.setPort(redisport);
jedisConnectionFactory.setDatabase(0);
return jedisConnectionFactory;
}
```
哨兵节点设置代码
```
@Bean
public RedisConnectionFactory jedisConnectionFactory(){
JedisPoolConfig poolConfig=new JedisPoolConfig();
poolConfig.setMaxIdle(5);
poolConfig.setMinIdle(1);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setNumTestsPerEvictionRun(10);
poolConfig.setTimeBetweenEvictionRunsMillis(60000);
//哨兵节点host、port设置,可设置多个哨兵,只需要链式新增 .sentinel(sentinelhost, sentinelport)
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration() .master("mymaster")
.sentinel(sentinelhost, sentinelport);
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(sentinelConfig,poolConfig);
return jedisConnectionFactory;
}
```
由此,在master节点down了的时候,slave节点会自动升级到master。然后我们的服务会自动新建redis连接池到新的master节点。
```
2016-07-29 10:42:28,525 [MasterListener-mymaster-[10.10.180.37:26379]] INFO redis.clients.jedis.JedisSentinelPool - Created JedisPool to master at 10.10.129.188:6379
```
当哨兵节点down了的时候,服务日志会提示Lost connection to Sentinel,此时redis连接池不会断开,可继续使用,不影响业务,但是这时当master失去响应时就不会自动切换连接池了。为了避免这种情况可以配置多个哨兵(sentinel)节点,也可以通过sentinel配置文件的方式,当哨兵节点down了之后,通知运维同学。
```
2016-07-29 10:50:36,820 [MasterListener-mymaster-[10.10.180.37:26379]] ERROR redis.clients.jedis.JedisSentinelPool - Lost connection to Sentinel at 10.10.180.37:26379. Sleeping 5000ms and retrying.
2016-07-29 10:50:41,821 [MasterListener-mymaster-[10.10.180.37:26379]] ERROR redis.clients.jedis.JedisSentinelPool - Lost connection to Sentinel at 10.10.180.37:26379. Sleeping 5000ms and retrying.
2016-07-29 10:50:46,823 [MasterListener-mymaster-[10.10.180.37:26379]] ERROR redis.clients.jedis.JedisSentinelPool - Lost connection to Sentinel at 10.10.180.37:26379. Sleeping 5000ms and retrying.
2016-07-29 10:50:51,825 [MasterListener-mymaster-[10.10.180.37:26379]] ERROR redis.clients.jedis.JedisSentinelPool - Lost connection to Sentinel at 10.10.180.37:26379. Sleeping 5000ms and retrying.
2016-07-29 10:50:56,826 [MasterListener-mymaster-[10.10.180.37:26379]] ERROR redis.clients.jedis.JedisSentinelPool - Lost connection to Sentinel at 10.10.180.37:26379. Sleeping 5000ms and retrying.
redis配置master-slave模式的更多相关文章
- Redis的master/slave复制
摘自:Redis的master/slave复制 Redis的master/slave数据复制方式可以是一主一从或者是一主多从的方式,Redis在master是非阻塞模式,也就是说在slave执行数据同 ...
- Redis主从复制(Master/Slave)
Redis主从复制(Master/Slave) 修改配置文件 拷贝多个redis.conf文件分别配置如下参数: 开启daemonize yes pidfile port logfile dbfile ...
- jenkins的Master/Slave模式
一. Master/Slave模式 分担jenkins服务器的压力,任务分配到其它执行机来执行 Master:Jenkins服务器 Slave:执行机(奴隶机).执行Master分配的任务,并返回任务 ...
- Jenkins—Master/Slave模式
Jenkins可部署在windows或者linux平台上,项目系统的用户多数为windows系统.如果Jenkins部署在linux上,而自动化任务要在windows平台执行,那么就需要使用Jenki ...
- Redis主从复制(Master/Slave) 与哨兵模式
Redis主从复制是什么? 行话:也就是我们所说的主从复制,主机数据更新后根据配置和策略, 自动同步到备机的master/slaver机制,Master以写为主,Slave以读为主 Redis主从复制 ...
- redis之master.slave主从复制
简介 主机数据更新后根据配置和策略,自动同步到备机的master/slave机制,master以写为主,slave以读为主 从库配置 配置从库,不配主库 配置从库: 格式: slaveof 主库ip ...
- MySQL master/slave 模式
1 .复制 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的 数据复制到其它主机(slaves)上,并重 ...
- ActiveMQ集群支持Master/Slave模式
现在ActiveMQ, 在Failover方面有两种解决方案:Pure Master Slave和Shared File System Master Slave. 先看Pure Master ...
- ActiveMQ使用Zookeeper+LevelDb配置Master/Slave集群
前言: 本文介绍的AMQ集群是Master-Slave模式的,官网介绍三种方案: (1)基于共享文件系统的,(2)基于JDBC,(3)基于可复制的LevelDB. 关于三种方式的对比网上已经有很多,本 ...
随机推荐
- vue项目条形码和二维码生成工具试用
项目开发需要,优惠券分不同类型,简单的使用id生成条形码供店铺使用,麻烦点的需要多个字段的就需要使用二维码来展示了,对应的效果如下 条形码(一维码)使用工具code128 需引入code128.js ...
- appium+python自动化60-windows上同时启动多个appium服务,让多个android机器并行运行
前言 做android自动化的时候,启动一个appium服务,只能匹配一个手机去自动化执行.有时候想同一套代码,可以在不同的手机上执行,测下app在不同手机上兼容性. 这就需要启动多个appium服务 ...
- 对于Ian的访谈,不少关于GAN的内容
文章链接如下: http://3g.163.com/dy/article/DD1GBSLF0511ABV6.html 里面提到胶囊网络,我找了这篇文章看了下: https://blog.csdn.ne ...
- add-strings
https://leetcode.com/problems/add-strings/ package com.company; import java.util.LinkedList; import ...
- Orchard运用 - 定制呈现最新博客文章
每个博客系统为了吸引更多访问量,一般都会在首页或侧边栏列举一些最新文章/随笔以获取更多点击.其实也就是查询出最新的几篇文章并按照简练的方式呈现,比如一般都只有标题及其对应的链接,有时也会标注一下作者和 ...
- 【转】vim折叠功能
原文:https://www.yupengsir.com/topic/content?i=140 这个作者的vim系列是高级的用法, 要学习一下. https://blog.easwy.com/arc ...
- Asp 将MSXML2.serverXMLHTTP返回的responseBody 内容转换成支持中文编码
参考:ASP四个小技巧,抓取网页:GetBody,字节转字符BytesToBstr,正则表达式测试方法,生成静态页 Function GetBody(weburl) '创建对象 Dim ObjXMLH ...
- SSH ProxyCommand 实践
在阿里上搭了典型的 Nginx + APP server 的架构: 即,只有 Nginx 服务器与公网链接.然后,每次部署升级服务器都要先 SSH 到 Nginx 再 SSH 到 server1 ...
- 【SSH三大框架】Hibernate基础第五篇:利用Hibernate完毕简单的CRUD操作
这里利用Hibernate操作数据库完毕简单的CRUD操作. 首先,我们须要先写一个javabean: package cn.itcast.domain; import java.util.Date; ...
- 自用封装javascript函数
(function(){ var JHRZ_IMG_Arr = JHRZ_IMG_Arr || {}; JHRZ_IMG_Arr.loading = ["/static/images/loa ...