Redis ConnectionException

JAVA 远程链接Redis服务失败,错误信息如下:

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

at redis.clients.util.Pool.getResource(Pool.java:50)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99)
at cn.crxy.offline6.javase.day20161115.RedisTemplateTest.jedisPool(RedisTemplateTest.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:164)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:82)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1641)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:85)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:48)
... 29 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:158)
... 36 more

问题排查步骤如下:

1、保证 java程序端与 redis服务端相互ping 通

a) 本地 DOS 去 ping远程服务器IP

b) 远程服务器ping 本地IP

2、修改Redis服务器配置文件 (我这里是 make install 安装)

vi /etc/redis.conf

其中有两处 bing 127.0.0.1 全部用“#”注释掉

3、重启Redis-server

先查看当前Redis 进程

退出redis-cli,也可以kill redis-cli 进程

停止服务:redis-server shutdown

开启服务:redis-server /etc/redis.conf

4、测试

可以先在本地DOS下进行连接访问,首先要进入本地Redis安装目录下

如果测试通过,就可以进行java程序连接了

时间: 2024-10-27 06:29:58

Redis ConnectionException的相关文章

laravel redis Error while reading line from the server.

代码运行一段时间后,会报下面的错误. [Predis\Connection\ConnectionException] Error while reading line from the server. [tcp://127.0.0.1:6379] 最初的怀疑是连接数过多,导致连接不上服务器,出现上述错误.查看进程,发现大量redis状态为TIME_WAIT的tcp连接. 首先考虑的是,减少TIME_WAIT的进程,保持随时可以连接到服务器.所以想到的减少TIME_WAIT状态的进程,将进程快速回

Laravel中Redis的使用

安装 laravel中使用redis首先需要你通过 Composer 安装 predis/predis 包: composer require predis/predis 配置 redis的配置文件是:config/database.php 'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PA

laravel使用redis报错

当你使用redis时,也许会报这个错误: (1/1) ConnectionException   ??????????????????????????? [tcp://127.0.0.1:6379]   in AbstractConnection.php (line 155)   at AbstractConnection->onConnectionError('???????????????????????????', 10061)   in StreamConnection.php (lin

Redis+keepalived实现双机热备

一. 简介 安装使用centos 5.6(64) Master 192.168.2.235 Slave 192.168.2.236 Vip 192.168.2.200 编译环境 yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-devel 当 Master 与 Slave 均运作正常时, Master负责服务,Slave负责Standby: 当 Master 挂掉,Slave 正常时, Slave接管服务,同时关闭主从

Python操作数据库(mysql redis)

一.python操作mysql数据库: 数据库信息:(例如211.149.218.16   szz  123456) 操作mysql用pymysql模块 #操作其他数据库,就安装相应的模块 import  pymysql ip='211.149.218.16' port=3306 passwd='123456' user='root' db='szz' conn=pymysql.connect(host=ip,user=user,port=port,passwd=passwd,db=db,cha

Redis在Linux中安装使用

一.安装$ wget http://download.redis.io/releases/redis-x.x.x.tar.gz $ tar xzf redis-x.x.x.tar.gz $ cd redis-x.x.x $ make sudo cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-check-rdb redis-trib.rb redis-sentinel redis-server /usr/loca

redis 学习 四 队列

<?php /** * redis实战 * * 利用列表list实现简单队列 * * @example php cache.php */ header('content-type:text/html;chaeset=utf-8'); $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); // 进队列 $userId = mt_rand(000000, 999999); $redis->rpush('QUEUE_NAME',j

Redis实战(三)Redis主从复制

从架构 1.主从架构图 2.通过命令 mkdir redisCluster创建redis集群文件夹 3.通过命令mkdir 6380   mkdir 6381   mkdir 6382在redisCluster文件夹下创建三个文件夹 4.通过以下命令将redis.conf分别拷贝到6380.6381. 6382文件夹下 cp /usr/local/redis/redis-3.0.2/redis.conf  ./6380 cp /usr/local/redis/redis-3.0.2/redis.

Redis Cluster集群部署搭建

在Oracle的路上走了许多年,换换感觉,尝试一下新的知识,也是一个不错的感觉.Redis,一个超轻量化的内存数据库,只做一小块数据库功能实现,却非常优秀的一个产品.今天,就分享一下安装Redis集群的过程. 搭建redis集群,建议至少需要准备3台服务器,共搭建6个节点,3个master,3个slave,并且要求3个master节点不能全部跑到同一台服务器上,保证节点安全,3台服务器的配置相同,使用redistest账号搭建,对应的端口是7000/7001/7002端口 我的集群分配如下,每个