SpringBoot无法连接redis
2021/9/6 19:10:44
本文主要是介绍SpringBoot无法连接redis,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
SpringBoot连接redis失败解决方法
- 这是报错信息
- 这是配置文件
- 这是依赖
- 解决方案:
- 总结:
在用springboot整合redis的过程中发现无法连接到redis,用了网上的解决流程并没有解决问题,最后发现原来是云服务器没有开放端口(光在虚拟机上开放6379端口不行)
这是报错信息
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 8.130.29.45:6379
这是配置文件
# Redis服务器地址 spring.redis.host=8.130.29.45 # Redis服务器连接端口 spring.redis.port=6379 # 连接超时时间(毫秒) spring.redis.timeout=5000
这是依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>
解决方案:
进入redis-config
1.修改 protected-mode yes 改为:protected-mode no(关闭保护模式)
2.注释掉 #bin 127.0.0.
3.后台启动daemonize 改为yes4.开启6379端口号
查看是否开启 firewall-cmd --zone=public --query-port=6379/tcp
[root@iZ0jlb0dvaeqvxytgqq4a8Z ~]# firewall-cmd --zone=public --query-port=6379/tcp yes
如果为no则打开
开启命令 [root@bogon bin]# firewall-cmd --zone=public --add-port=6379/tcp --permanent 重载 [root@bogon bin]# firewall-cmd --reload 重新查看 firewall-cmd --zone=public --query-port=6379/tcp
5.做完以上记得重启redis
重新测试
结果还是不尽人意,还是无法连接我们的公网ip
打开我们的阿里云服务器
发现原来我们虽然在虚拟机上开放了6379端口,但是在我们的云服务器上并没有开放6379端口
手动添加后重新测试
测试成功了~
总结:
要记得不光在虚拟机上开放端口,在我们的云服务器上也要开放6379端口
这篇关于SpringBoot无法连接redis的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-03万字长文聊聊Web3的组成架构
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?