redis 哨兵模式的创建

1. 下载redis3.2.12版本。https://codeload.github.com/antirez/redis/zip/3.2.12

2.  解压后放到/usr/local/src/目录下面。

3.  拷贝三份 cp -R redis-3.2.13 redis1,cp -R redis-3.2.13 redis2,cp -R redis-3.2.13 redis3

4.  进入redis1目录

5.  make & make install

6. 配置redis配置文件。

redis.conf配置如下:

daemonize yes #在后台运行,

masterauth "myredis"

requirepass "myredis"

其他的保持默认。

7. cd src目录 启动redis  ./redis-server ../redis.conf

8. ps -ef | grep redis 查看redis 进程。

9. 配置从服务器配置文件

port 6380
daemonize yes
slaveof 127.0.0.1 6379

启动服务。

10. 配置从服务配置文件

port 6381
daemonize yes
slaveof 127.0.0.1 6379

启动服务

11. Redis sentinel配置

# 配置文件信息
// Sentinel节点的端口
port 26379

sentinel auth-pass mymaster myredis

// 当前Sentinel节点监控 127.0.0.1:6379 这个主节点
// 2代表判断主节点失败至少需要2个Sentinel节点节点同意
// mymaster是主节点的别名
sentinel monitor mymaster 127.0.0.1 6379 2

//每个Sentinel节点都要定期PING命令来判断Redis数据节点和其余Sentinel节点是否可达,如果超过30000毫秒30s且没有回复,则判定不可达
sentinel down-after-milliseconds mymaster 30000

//当Sentinel节点集合对主节点故障判定达成一致时,Sentinel领导者节点会做故障转移操作,选出新的主节点,
//原来的从节点会向新的主节点发起复制操作,限制每次向新的主节点发起复制操作的从节点个数为1
sentinel parallel-syncs mymaster 1

//故障转移超时时间为180000毫秒
sentinel failover-timeout mymaster 180000

12. 启动哨兵

./redis-sentinel ../sentinel.conf --sentinel

13. 同样的配置其他的从服务器的哨兵并启动

14. springboot配置

redis:
sentinel:
master: mymaster
nodes: 10.118.239.78:26379,10.118.239.78:26380,10.118.239.78:26381
password: myredis

15.  redis配置文件设置

@Value("#{'${spring.redis.sentinel.nodes}'.split(',')}")
private List<String> nodes; @Bean
@ConfigurationProperties(prefix = "spring.redis")
public JedisPoolConfig getRedisConfig() {
JedisPoolConfig config = new JedisPoolConfig();
return config;
} @Bean
public RedisSentinelConfiguration sentinelConfiguration() {
RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration();
//配置matser的名称
redisSentinelConfiguration.master("mymaster");
redisSentinelConfiguration.setPassword(RedisPassword.of(password));
//配置redis的哨兵sentinel
Set<RedisNode> redisNodeSet = new HashSet<>();
nodes.forEach(x -> {
redisNodeSet.add(new RedisNode(x.split(":")[0], Integer.parseInt(x.split(":")[1])));
});
redisSentinelConfiguration.setSentinels(redisNodeSet);
return redisSentinelConfiguration;
}

16. 启动项目测试。

springboot2.0.4对接redis3.2.12版本哨兵模式的更多相关文章

  1. SpringBoot2.0 基础案例(13):基于Cache注解模式,管理Redis缓存

    本文源码 GitHub地址:知了一笑 https://github.com/cicadasmile/spring-boot-base 一.Cache缓存简介 从Spring3开始定义Cache和Cac ...

  2. SpringBoot2.0拦截器 与 1.X版本拦截器 的实现

    1.5  版本 先写个拦截器,跟xml配置方式一样,然后将拦截器加入spring容器管理 .接着创建 配置文件类 继承 WebMvcConfigurerAdapter 类,重写父类方法addInter ...

  3. SpringBoot2.0 整合 QuartJob ,实现定时器实时管理

    一.QuartJob简介 1.一句话描述 Quartz是一个完全由java编写的开源作业调度框架,形式简易,功能强大. 2.核心API (1).Scheduler 代表一个 Quartz 的独立运行容 ...

  4. 升级项目版本:SpringBoot1.5.x到SpringBoot2.0.x

    1.升级版本的选择 首先去spring的官网看一下最新的版本与版本之间的依赖

  5. SpringBoot2.0 基础案例(12):基于转账案例,演示事务管理操作

    本文源码 GitHub地址:知了一笑 https://github.com/cicadasmile/spring-boot-base 一.事务管理简介 1.事务基本概念 一组业务操作ABCD,要么全部 ...

  6. Spring-Boot-2.0.0-M1版本将默认的数据库连接池从tomcat jdbc pool改为了hikari

    spring-configuration-metadata.json spring-boot-autoconfigure-2.0.0.M7.jar!/META-INF/spring-configura ...

  7. SpringBoot2.0之四 简单整合MyBatis

    从最开始的SSH(Struts+Spring+Hibernate),到后来的SMM(SpringMVC+Spring+MyBatis),到目前的S(SpringBoot),随着框架的不断更新换代,也为 ...

  8. springBoot2.0+redis+fastJson+自定义注解实现方法上添加过期时间

    springBoot2.0集成redis实例 一.首先引入项目依赖的maven jar包,主要包括 spring-boot-starter-data-redis包,这个再springBoot2.0之前 ...

  9. Springboot2.0部署阿里云服务器(nginx+域名+SSL)供Http和Https访问

    总算是弄出来了,先写下来供自己以后查阅. 1)首先你要有一个阿里云服务器,我用的是Centos7学生认证,10元/月,很便宜也很好用. 2)购买了域名,首年9元,很划算.域名买来之后经历了拍照备案,前 ...

随机推荐

  1. 通通WPF随笔(1)——基于lucene.NET让ComboBox拥有强大的下拉联想功能

    原文:通通WPF随笔(1)--基于lucene.NET让ComboBox拥有强大的下拉联想功能 我一直很疑惑百度.谷哥搜索框的下拉联想功能是怎么实现的?是不断地查询数据库吗?其实到现在我也不知道,他们 ...

  2. golang并发编程的两种限速方法

    引子 golang提供了goroutine快速实现并发编程,在实际环境中,如果goroutine中的代码要消耗大量资源时(CPU.内存.带宽等),我们就需要对程序限速,以防止goroutine将资源耗 ...

  3. 重写combobox模板,实现支持过滤的combobox

    先看效果图 客户提出需求后,首选在百度查找可靠方案 看了几个,效果都不理想, 大多是把isEditNable设置成true,IsTextSearchNable设置成false 再对itemsSourc ...

  4. Android adb shell 无法启动:insufficient permissions for device

    解决办法1:lsusb查看vendorId号,然后在/etc/udev/rules.d/目录下增加(或修改)51-android.rules文件.增加一条记录:SUBSYSTEM=="usb ...

  5. Qt4可以使用trUtf8函数,其内容可以是中文,也可以是\F硬编码

    显示在textBrowser->setText 中文乱码 转成QObject::trUtf8即可. ui->textBrowser->setText((QObject::trUtf8 ...

  6. Python杂谈: 集合中union和update的区别(Python3.x)

    集合中union和update方法都是将多个可迭代的对象合并,但是返回的结果和对初始对象的影响却不一样 # union() 方法 - a.union(b) 将集合a和集合b取并集,并将并集作为一个新的 ...

  7. ORACLE 错误 ora-01830 解决方法

    http://www.cnblogs.com/BetterWF/archive/2012/06/20/2556442.html 错误产生原因:date类型不能包含秒以后的精度. 如日期:2012-06 ...

  8. JVM的几个介绍

    关于jvm内存的几点 jvm在运行时分为方法区(Method Area) .虚拟机栈(VM Stack).本地方法栈(Native Method Stack).堆 (Heap).程序计数器 (Prog ...

  9. MIPS虚拟机代码

    http://download.eeworld.com.cn/download/mamselc/472333http://download.eeworld.com.cn/detail/lamas/36 ...

  10. 实现Qt日志功能并输出到文件(使用qInstallMsgHandler安装customMessageHandler)good

    原文 http://www.cppblog.com/lauer3912/archive/2011/04/10/143870.html 一.基本分类:qDebug : 调试信息提示qWarning: 一 ...