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. 关于三种方式的对比网上已经有很多,本 ...
随机推荐
- linq Distinct 去除重复数据
转载:http://www.cnblogs.com/ldp615/archive/2011/08/01/distinct-entension.html 只可惜linq默认不支持.Distinct(p ...
- redis.conf配置解释
daemonize:如果需要在后台运行,把该项改为yespidfile:配置多个pid的地址,默认在/var/run/redis.pidbind:绑定ip,设置后只接受来自该ip的请求port:监听端 ...
- Interactive Messager
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Andorid之Annotation框架初使用(六)
EVENT @Click :点击事件,只能有0个或1个参数,且参数为View @Click(R.id.myButton) void myButtonWasClicked() { [...] } @Cl ...
- Android内存调试命令
adb shell dumpsys meminfo 包名 比如: adb shell dumpsys meminfo cn.com.test
- 关于Predicate<T>委托
Predicate<T>委托在.NET类类库中经常出现,此委托的定义如下: public delegatebool Predicate<T>(T obj); 从其定义可以看到, ...
- 高性能CSS
避免使用@import 有两种方式加载样式文件,一种是link元素,另一种是CSS 2.1加入@import.而在外部的CSS文件中使用@import会使得页面在加载时增加额外的延迟.虽然规则允许在样 ...
- [Python爬虫] 之三十一:Selenium +phantomjs 利用 pyquery抓取消费主张信息
一.介绍 本例子用Selenium +phantomjs爬取央视栏目(http://search.cctv.com/search.php?qtext=消费主张&type=video)的信息(标 ...
- 构建高可用Linux服务器一
1.显示物理CPU个数:cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -1 2.显示每个物理CPU中的core ...
- 【转】vim折叠功能
原文:https://www.yupengsir.com/topic/content?i=140 这个作者的vim系列是高级的用法, 要学习一下. https://blog.easwy.com/arc ...