当前位置: 代码迷 >> 综合 >> redis异常解决:jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
  详细解决方案

redis异常解决:jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set

热度:77   发布时间:2023-12-10 16:48:58.0

项目中用到了redis做缓存服务器,今天一次重启后报出下面的异常,经过各种排查,定位原因如下,作记录以备忘。

异常如下:


redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
redis.clients.util.Pool.getResource(Pool.java:50)
redis.clients.jedis.JedisPool.getResource(JedisPool.java:88)
com.radiadesign.catalina.session.RedisSessionManager.acquireConnection(RedisSessionManager.java:107)
com.radiadesign.catalina.session.RedisSessionManager.loadSessionFromRedis(RedisSessionManager.java:388)
com.radiadesign.catalina.session.RedisSessionManager.findSession(RedisSessionManager.java:330)
org.apache.catalina.connector.Request.doGetSession(Request.java:2981)
org.apache.catalina.connector.Request.getSessionInternal(Request.java:2599)
com.radiadesign.catalina.session.RedisSessionHandlerValve.invoke(RedisSessionHandlerValve.java:28)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1739)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1698)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause

redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
redis.clients.jedis.Protocol.processError(Protocol.java:113)
redis.clients.jedis.Protocol.process(Protocol.java:138)
redis.clients.jedis.Protocol.read(Protocol.java:192)
redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:282)
redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:181)
redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:1930)
redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:71)
org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:819)
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:429)
org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:360)
redis.clients.util.Pool.getResource(Pool.java:48)
redis.clients.jedis.JedisPool.getResource(JedisPool.java:88)
com.radiadesign.catalina.session.RedisSessionManager.acquireConnection(RedisSessionManager.java:107)
com.radiadesign.catalina.session.RedisSessionManager.loadSessionFromRedis(RedisSessionManager.java:388)
com.radiadesign.catalina.session.RedisSessionManager.findSession(RedisSessionManager.java:330)
org.apache.catalina.connector.Request.doGetSession(Request.java:2981)
org.apache.catalina.connector.Request.getSessionInternal(Request.java:2599)
com.radiadesign.catalina.session.RedisSessionHandlerValve.invoke(RedisSessionHandlerValve.java:28)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1739)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1698)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)

问题原因看起来很清楚,就是这句: ERR Client sent AUTH, but no password is set

它的意思就是redis服务器没有设置密码,但客户端向其发送了AUTH请求,于是把程序中所有jedis发送授权的地方都去掉,可是发现异常还是存在!!简直无语了

最后想起在tomcat中还有同步session到redis的配置,这里还设置了password,而且即使是空“”也不行。把整个password干掉,重启,ok啦!

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
      <Manager className="com.radiadesign.catalina.session.RedisSessionManager"
               host="172.11.22.33" password="" port="6379" database="5" maxInactiveInterval="60" />

另外:关于redis的启动方式:

1、指定配置文件 $: ./redis-server /usr/local/redis.conf

2、不指定配置:$: ./redis-server &

不指定配置文件启动时采用默认配置,无密码

redis通过属性requirepass 设置访问密码,但没有设置该属性时,客户端向服务端发送AUTH请求,服务端就好返回异常:ERR Client sent AUTH, but no password is set

  相关解决方案