1、测试代码如下:

public static void main(String[] args) {
Set<String> sentinels = new HashSet<String>();
sentinels.add("118.25.7.111:26379");
sentinels.add("118.25.7.111:26380");
sentinels.add("118.25.7.111:26381");
String clusterName = "mymaster";
//此处添加密码
String password = "foo" ;
// 建立连接池配置参数
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxIdle(50);
//设置最小空闲数
config.setMinIdle(8);
config.setMaxWaitMillis(10000);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
//Idle时进行连接扫描
config.setTestWhileIdle(true);
//表示idle object evitor两次扫描之间要sleep的毫秒数
config.setTimeBetweenEvictionRunsMillis(30000);
//表示idle object evitor每次扫描的最多的对象数
config.setNumTestsPerEvictionRun(10);
//表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义
config.setMinEvictableIdleTimeMillis(60000);
JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName,sentinels,config,password);
Jedis jedis = null;
try {
jedis = redisSentinelJedisPool.getResource();
jedis.set("key", "aaa");
System.out.println(jedis.get("key"));
System.out.println(jedis.get("bbb"));
} catch (Exception e) {
e.printStackTrace();
} finally {
//redisSentinelJedisPool.returnResource(jedis);
jedis.close();
}
redisSentinelJedisPool.close();
}

问题:

1、-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

解决:此处是因为sentinel的保护模式开启(默认)导致的,在sentinel对应的配置文件中将其关闭即可,即

#关闭保护模式
protected-mode no

2、redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:209)
at com.ww.wwta.config.client.RedisClusterClient.main(RedisClusterClient.java:92)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:889)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:433)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:362)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 2 more

解决:未将对应的主服务的端口加入防火墙,将设置端口加入防火墙即可,即

firewall-cmd --permanent --zone=public --add-port=/tcp
firewall-cmd --reload

查看是否已加入:

firewall-cmd --permanent --zone=public --list-ports

3、连接127.0.0.1:6780连接拒绝

需将sentinel配置sentinel monitor mymaster 127.0.0.1 6380 2 -> sentinel monitor mymaster 118.25.7.111 6380 2

java 集成Redis 一主多从的更多相关文章

  1. springboot 集成Redis一主二从三哨兵

    1.Centos7 Redis一主二从三哨兵配置 Redis一主二从三哨兵环境搭建 2.接入过程 与集成redis单机不同的是jedis相关的配置做了修改,JedisPool换成了JedisSenti ...

  2. springboot集成redis(mybatis、分布式session)

    安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...

  3. Spring Boot 如何快速集成 Redis 哨兵?

    上一篇:Spring Boot 如何快速集成 Redis? 前面的分享栈长介绍了如何使用 Spring Boot 快速集成 Redis,上一篇是单机版,也有粉丝留言说有没有 Redis Sentine ...

  4. 【springBoot】springBoot集成redis的key,value序列化的相关问题

    使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...

  5. Java实现Redis持久化到数据库的关键方法

    import java.util.Date; import java.util.Iterator; import java.util.Set;   import redis.clients.jedis ...

  6. spring集成redis

    redis是一种非关系型数据库,与mongoDB不同的是redis是内存数据库,所以访问速度很快.常用作缓存和发布-订阅式的消息队列.redis官方没有提供windows版本的软件.windows版本 ...

  7. Windows环境下springboot集成redis的安装与使用

    一,redis安装 首先我们需要下载Windows版本的redis压缩包地址如下: https://github.com/MicrosoftArchive/redis/releases 连接打开后如下 ...

  8. linux系统下安装redis以及java调用redis

    关系型数据库:MySQL  Oracle 非关系型数据库:Redis 去掉主外键等关系数据库的关系性特性 1)安装redis编译的c环境,yum install gcc-c++ 2)将redis-2. ...

  9. Spring Boot 项目实战(四)集成 Redis

    一.前言 上篇介绍了接口文档工具 Swagger 及项目监控工具 JavaMelody 的集成过程,使项目更加健壮.在 JAVA Web 项目某些场景中,我们需要用缓存解决如热点数据访问的性能问题,业 ...

随机推荐

  1. xib上的控件属性为什么要使用weak

    常规中,从xib拖出一个控件时,系统会自动生成一段代码,如下: 从这个图片中,可以看到控件的属性都是用的weak,这是为什么呢? 首先,如果把weak修改成strong其实也是可以的,但是会出现一个问 ...

  2. MSIL实用指南-struct的生成和操作

    struct(结构)是一种值类型,用于将一组相关的信息变量组织为一个单一的变量实体.所有的结构都继承自System.ValueType类,因此是一种值类型,也就是说,struct实例分配在线程的堆栈( ...

  3. QFramework 使用指南 2020(七):Res Kit (1)概述与基本使用

    在上一篇,我们刚刚结束了 脚本生成专题,我们知道 QF 提供了两种脚本生成模式,一种是 ViewController + Bind ,另一种是 UI Kit 模式. 本来打算,介绍完 ViewCont ...

  4. mysql 主主从配置

    配置主服务器:主服务器1 Ip:  192.168.0.1 主服务器2 Ip:  192.168.0.2 主服务器1配置 2.1.修改mysql配置文件 vim /etc/my.conf Server ...

  5. 结合生活案例实现rabbitmq消息通信

    title: 基于springboot实现rabbitmq消息通信 date: 2019-09-11 09:00:30 tags: - [rabbitmq] categories: - [spring ...

  6. Loadrunner 11 的安装

    安装包可以直接在我的百度网盘下载,这里用的是LR11的版本.电脑系统是win7 链接: https://pan.baidu.com/s/1OApfUemG3oVjLUE79qaikw 提取码: 7n3 ...

  7. 4.cache每个参数的意义和作用以及工作原理?

    在程序开发过程中,适当使用 Cache 缓存能有效提高程序执行效率.比如一些常常调用的系统公共变量,把它们缓存到 Cache 中,当需要使用它们时,直接从 Cache 中读取,不必每次都从数据库或文件 ...

  8. dubbo 的 spi 思想是什么?

    面试题 dubbo 的 spi 思想是什么? 面试官心理分析 继续深入问呗,前面一些基础性的东西问完了,确定你应该都 ok,了解 dubbo 的一些基本东西,那么问个稍微难一点点的问题,就是 spi, ...

  9. android 和 webService交互

    webService 很久不用了,第一次使用还是13年, 早已忘记怎么搞了.今天看了篇博文,写了个demo .记录下吧! 首先要下载skoap2  .... xxx.jar  ,我用的是最新的3.6. ...

  10. 记一次神奇的sql查询经历,group by慢查询优化

    一.问题背景 现网出现慢查询,在500万数量级的情况下,单表查询速度在30多秒,需要对sql进行优化,sql如下: 我在测试环境构造了500万条数据,模拟了这个慢查询. 简单来说,就是查询一定条件下, ...