当前位置:   article > 正文

RedisConnectionException Redis链接异常处理 只能127本地访问分析

redisconnectionexception

redis在无密码,启动保护模式下,只能通过127.0.0.1访问,否则报以下错误11

  1. io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: /10.8.33.128:6379
  2. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  3. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
  4. at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
  5. at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
  6. at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:616)
  7. at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
  8. at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
  9. at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
  10. at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
  11. at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  12. at java.lang.Thread.run(Thread.java:748)
  13. Caused by: java.net.ConnectException: Connection refused: no further information
  14. ... 11 common frames omitted
  15. 2019-12-02 08:53:53.052 [DEBUG] [lettuce-nioEventLoop-6-1] io.lettuce.core.RedisChannelHandler - close()
  16. 2019-12-02 08:53:53.052 [DEBUG] [lettuce-nioEventLoop-6-1] io.lettuce.core.protocol.DefaultEndpoint - [unknown, epid=0x1] close()
  17. 2019-12-02 08:53:53.053 [DEBUG] [lettuce-nioEventLoop-6-1] io.lettuce.core.protocol.CommandHandler - [channel=0x90b73150, [id: 0x77cd9026] (inactive), chid=0x1] channelUnregistered()
  18. 2019-12-02 08:53:53.054 [ERROR] [Job-Thread-1] o.s.s.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
  19. org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 10.8.33.128:6379
  20. at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:966)
  21. at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:934)
  22. at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:786)
  23. at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:300)
  24. at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
  25. at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
  26. at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82)
  27. at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:211)
  28. at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
  29. at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
  30. at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:48)
  31. at com.bzl.face.common.util.RedisUtil.get(RedisUtil.java:43)
  32. at com.bzl.face.system.schedule.UdpInactiveTask.inactiveCheck(UdpInactiveTask.java:41)
  33. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  34. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  35. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  36. at java.lang.reflect.Method.invoke(Method.java:498)
  37. at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
  38. at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
  39. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  40. at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308)
  41. at java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
  42. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
  43. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
  44. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  45. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  46. at java.lang.Thread.run(Thread.java:748)
  47. Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 10.8.33.128:6379
  48. at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
  49. at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:233)
  50. at io.lettuce.core.RedisClient.connectStandalone(RedisClient.java:253)
  51. at io.lettuce.core.RedisClient.connect(RedisClient.java:202)
  52. at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:56)
  53. at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:959)
  54. ... 26 common frames omitted

查redis配置文件,“protected-mode yes”配置项上面的注释可得知以下:

  1. 1、当redis配置文件中绑定了bind 127.0.0.1时,表示只能通过绑定的地址访问的Redis,默认此项
  2. 2、当需要绑定多个ip时,用空格隔开
  3. 3、当不绑定时,表示可以任意ip访问;但此时若保护模式protected-mode yes开启了,就必须设置密码,否则也只能通过127.0.0.1访问

因此

  1. 1、bind 127.0.0.1 只能127.0.0.1访问
  2. 2、#bind 127.0.0.1 protected-mode yes #requirepass foobared 只能127.0.0.1访问
  3. 3、#bind 127.0.0.1 protected-mode yes requirepass 123456 可以任意ip访问
  4. 3、#bind 127.0.0.1 protected-mode no 可以任意ip访问

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号