通过jedis连接redis单机成功,使用redis客户端可以连接集群,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool
一,问题描述:
(如题目)通过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的更多相关文章
- redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool
一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...
- 【Redis】Could not get a resource from the pool 实乃集群配置问题
先说些题外话~自上次确诊为鼻窦炎+过敏性鼻炎到现在已经一个月了,最初那会,从下午到晚上头疼难忍.大概是积劳成疾,以前流鼻涕.打喷嚏的时候从来没有注意过,结果病根一下爆发. 关键在于锁定问题,开始治疗一 ...
- 记redis一次Could not get a resource from the pool 异常的解决过程
最近有个项目中的redis每天都会报 "Could not get a resource from the pool"的错误,而这套代码在另一地方部署又没有问题.一直找不到错误原因 ...
- JedisCluster 链接redis集群
先贴代码: <!-- redis客户端 --><dependency> <groupId>redis.clients</groupId> <a ...
- Redis 一二事 - 在spring中使用jedis 连接调试单机redis以及集群redis
Redis真是好,其中的键值用起来真心强大啊有木有, 之前的文章讲过搭建了redis集群 那么咋们该如何调用单机版的redis以及集群版的redis来使用缓存服务呢? 先讲讲单机版的,单机版redis ...
- redis单机连接池
一.配置文件 1. db.properties配置文件#IP地址 redis.ip = 127.0.0.1 #端口号 redis.port= #最大连接数 redis.max.total= #最大空闲 ...
- redis提示Could not get a resource from the pool(jedis连接池配置)
起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...
- 分布式应用下的Redis单机锁设计与实现
背景 最近写了一个定时任务,期望是同一时间只有一台机器运行即可.因为是应用是在集群环境下跑的,所以需要自己实现类一个简陋的Redis单机锁. 原理 主要是使用了Redis的SET NX特性,成功设置的 ...
- 面向接口编程实现不改代码实现Redis单机/集群之间的切换
开发中一般使用Redis单机,线上使用Redis集群,因此需要实现单机和集群之间的灵活切换 pom配置: <!-- Redis客户端 --> <dependency> < ...
随机推荐
- Java 将Maven项目打成可执行jar包
一.用maven-shade-plugin打包 在pom.xml文件中加入如下信息,利用Maven的maven-shade-plugin插件进行打包. <build> <plugin ...
- H. A Cache Simulator
Cache memories have been used widely in current microprocessor systems. In this problem, you are ask ...
- HDUST-1245 Interpreter(模拟)
1245: Problem E: Interpreter 时间限制: 1 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Problem E: Inte ...
- vue.js的v-bind
v-bind v-bind 主要用于属性绑定, html中的标签内: <div class="control-group"> <label class=&quo ...
- div css 布局对seo 影响 布局原则
一.代码精简 使用DIV+CSS布局,页面代码精简,这一点相信对XHTML有所了解的都知道.代码精简所带来的直接好处有两点:一是提高蜘蛛爬行效率,能在最短的时间内爬完整个页面,这样对收录质量有一定好处 ...
- initlocation - 创建一个从属的 PostgreSQL数据库存储区
SYNOPSIS initlocation directory DESCRIPTION 描述 initlocation 创建一个新的PostgreSQL从属数据库存储区.参阅 CREATE DATAB ...
- zabbix-agent安装遇到的坑
问题: libc.so.6(GLIBC_2.14)(64bit) is needed by zabbix-agent-3.4.11-1.el7.x86_64 原因: 系统环境是 centos6 ,下载 ...
- 右则css 小浮条
<!--右边浮动--> <div class="indexfu"> <div class="indexfu2" id=" ...
- 隐马尔可夫模型中基于比例因子的前向算法(java实现)
直接上干货哈,其他子算法,后续补上. System.out.print ...
- Tableau Dashboard
Dashboard仪表盘,用来展示多个图表,并展示之间的联动,分析数据.