关于springboot连接redis的报错
错误信息2022-05-15 12:00:02.420 ERROR 8364 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request p
·
错误信息
2022-05-15 12:00:02.420 ERROR 8364 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.28.12/<unresolved>:6379] with root cause
io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.28.12:6379
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ~[netty-transport-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-transport-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.63.Final.jar:4.1.63.Final]
at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
错误的可能原因:
① linux上的redis服务未正常开启。
② linux防火墙未开放6379端口。
③ redis连接信息有误。
解决方案
查看linux上的redis配置文件:
1.将bind 127.0.0.1 注释掉。取消redis的连接限制。
2.将redis配置中的protected-mode 改为no
3.开启redis服务的后台运行:daemonized 改为yes。
4.检查防火墙的运行状态和端口开放情况:
#查看防火墙状态
systemctl status firewalld
#可选择关闭防火墙
systemctl disable firewalld
#也可选择开启对应的6379端口
systemctl-cmd --zone=public --add-port=6379/tcp --permanent
#查看已开启端口
firewall-cmd --zone=public --list-ports
获取到linux上的ip地址:
ifconfig -a
拿到ip地址在springboot项目中配置即可:
redis:
host: 192.168.28.***
port: 6379
database: 0
使用redis连接成功!
更多推荐
已为社区贡献2条内容
所有评论(0)