一,问题描述:

(如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool

但是使用redis客户端可以连接集群(我使用的redis desktop manager)

在java中通过jedis连接redis单机也成功,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool,

我以命令行方式操作是没问题的,如下:

先贴代码:

<!-- redis客户端 -->
<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
  <version>2.8.2</version>
</dependency>

//相关代码如下:

JedisPoolConfig config = new JedisPoolConfig();
config =new JedisPoolConfig();
       config.setMaxTotal(60000);//设置最大连接数  
       config.setMaxIdle(1000); //设置最大空闲数 
       config.setMaxWaitMillis(3000);//设置超时时间  
       config.setTestOnBorrow(true);

// 集群结点
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7001")));
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7002")));
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7003")));
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7004")));
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7005")));
jedisClusterNode.add(new HostAndPort("192.168.246.128", Integer.parseInt("7006")));

JedisCluster jc = new JedisCluster(jedisClusterNode, config);
//JedisCluster jc = new JedisCluster(jedisClusterNode);
jc.set("name", "zhangsan");
String value = jc.get("name");
System.out.println(value);

纠结了两天也是没sei了,就这么几行代码,看来看去没问题啊,甚至上github去看作者的例子,一模一样啊,一度怀疑人生啊;

由于我的单机版用命令行和java代码访问都没问题,而且集群通过命令行方式也没问题,所以一直没怀疑我搭建的环境的问题,我怀疑代码,怀疑是否是工程依赖的jedis的版本的bug,换了几个版本还是报同样的错误,最后我才开始查环境,环境的话先关了防火墙,没用,然后再查配置文件,查到

二:找到问题:这个地方IP的问题,以上是正确的版本,以前有问题的版本的Ip是127.0.0.1,

原因是这个地方以前我没注释redis.conf文件中的bind 127.0.0.1 然后做集群时使用的命令是:

./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

三:解决问题:

删除以上所有里面这个node.conf文件

然后:

重新做集群:

./redis-trib.rb create --replicas 1 192.168.246.128:7001 192.168.246.128:7002 192.168.246.128:7003 192.168.246.128:7004 192.168.246.128:7005 192.168.246.128:7006

然后重新测试就解决了;

还要注意一下每个redis下面的redis.conf的配置(以下是我的):

port  7001                                        //端口7001,7002,7003        
bind 本机ip                                       //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群,我直接注释掉了
daemonize    yes                               //redis后台运行
pidfile  /var/run/redis_7000.pid          //pidfile文件对应7000,7001,7002
cluster-enabled  yes                           //开启集群  把注释#去掉
cluster-config-file  nodes_7000.conf   //集群的配置  配置文件首次启动自动生成 7001,7002,7003
cluster-node-timeout  15000                //请求超时  默认15秒,可自行设置
appendonly  yes                           //aof日志开启  有需要就开启,它会每次写操作都记录一条日志

通过jedis连接redis单机成功,使用redis客户端可以连接集群,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool的更多相关文章

  1. redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool

    一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...

  2. 【Redis】Could not get a resource from the pool 实乃集群配置问题

    先说些题外话~自上次确诊为鼻窦炎+过敏性鼻炎到现在已经一个月了,最初那会,从下午到晚上头疼难忍.大概是积劳成疾,以前流鼻涕.打喷嚏的时候从来没有注意过,结果病根一下爆发. 关键在于锁定问题,开始治疗一 ...

  3. 记redis一次Could not get a resource from the pool 异常的解决过程

    最近有个项目中的redis每天都会报 "Could not get a resource from the pool"的错误,而这套代码在另一地方部署又没有问题.一直找不到错误原因 ...

  4. JedisCluster 链接redis集群

    先贴代码: <!-- redis客户端 --><dependency>  <groupId>redis.clients</groupId>  <a ...

  5. Redis 一二事 - 在spring中使用jedis 连接调试单机redis以及集群redis

    Redis真是好,其中的键值用起来真心强大啊有木有, 之前的文章讲过搭建了redis集群 那么咋们该如何调用单机版的redis以及集群版的redis来使用缓存服务呢? 先讲讲单机版的,单机版redis ...

  6. redis单机连接池

    一.配置文件 1. db.properties配置文件#IP地址 redis.ip = 127.0.0.1 #端口号 redis.port= #最大连接数 redis.max.total= #最大空闲 ...

  7. redis提示Could not get a resource from the pool(jedis连接池配置)

    起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...

  8. 分布式应用下的Redis单机锁设计与实现

    背景 最近写了一个定时任务,期望是同一时间只有一台机器运行即可.因为是应用是在集群环境下跑的,所以需要自己实现类一个简陋的Redis单机锁. 原理 主要是使用了Redis的SET NX特性,成功设置的 ...

  9. 面向接口编程实现不改代码实现Redis单机/集群之间的切换

    开发中一般使用Redis单机,线上使用Redis集群,因此需要实现单机和集群之间的灵活切换 pom配置: <!-- Redis客户端 --> <dependency> < ...

随机推荐

  1. 洛谷P1029 最大公约数和最小公倍数问题 (简单数学题)

    一直懒的写博客,直到感觉不写不总结没有半点进步,最后快乐(逼着)自己来记录蒟蒻被学弟学妹打压这一年吧... 题目描述 输入22个正整数x_0,y_0(2 \le x_0<100000,2 \le ...

  2. spark日志+hivesql

    windows本地读取hive,需要在resource里面将集群中的hive-site.xml下载下来. <?xml version="1.0" encoding=" ...

  3. GitHub编辑README.md

    一.标题 等级表示法(六级): #一级标题 ##二级标题 ###三级标题 ####四级标题 #####五级标题 ######六级标题 一级标题/大标题(文本下面加上等于号): 大标题 === 二级标题 ...

  4. 前端页面适配的rem换算 为什么要使用rem

    之前有些适配做法,是通过js动态计算viewport的缩放值(initial-scale). 例如以屏幕320像素为基准,设置1,那屏幕375像素就是375/320=1.18以此类推. 但直接这样强制 ...

  5. C++中如何实现split的效果?

    C++中如何实现split的效果? 和Python等语言不同,C++的string类没有内置split函数,这对于实际应用中要经常分割字符串的情况非常不方便.有很多种方法来处理,这里讲一种比较方(to ...

  6. ORA-01846: 周中的日无效

    参考这篇博客:https://blog.csdn.net/yabingshi_tech/article/details/8678218

  7. jQuery中outerWidth()方法

    截图自:菜鸟教程https://www.runoob.com/jquery/html-outerwidth.html

  8. 【leetcode389】389. Find the Difference

    异或 找不同 —.— public class Solution { public char findTheDifference(String s, String t) { char temp = 0 ...

  9. HashMap 的实现原理(1.8)

    详见:https://blog.csdn.net/richard_jason/article/details/53887222 HashMap概述 1.初始容量默认为16 最大为2的30次方,负载因子 ...

  10. nacos集群搭建

    nacos介绍 Nacos 支持基于 DNS 和基于 RPC 的服务发现(可以作为springcloud的注册中心).动态配置服务(可以做配置中心).动态 DNS 服务. 1.从官网下载nacos压缩 ...