在idea上部署springboot项目连接服务器上的redis时
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to *****:6379
使用的是阿里云服务器
下面是排错步骤:
查看yml文件中的ip,端口,密码和服务器能对应的上吗
yml文件配置如下
spring:
redis:
host: ****
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 100ms
和linux上部署的一致
.查看linux防火墙是否关闭
systemctl status firewalld查看防火墙状态
systemctl stop firewalld关闭防火墙
查看阿里云安全组
这里我不演示了,我的已经放行了
linux中redis是否允许外网ip访问
whereis redis #找到redis目录
cd /usr/local/redis (目录根据上面指令返回结果) #进入该目录
vim redis.conf #在该目录下修改bind
将bind的127.0.0.1改为0.0.0.0
然后重启redis
在redis-cli中使用shutdown命令再重新执行redis -server
设置redis密码
按理来说应该能连上了但是还是报错连接不到
这里我用cmd输入
telnet ***(服务器ip) 6379
查看看是否能连接到redis端口
发现能连接到redis,但是返回这样的信息
大概就是服务器端redis没有设置密码
继续操作redis.conf文件
找到
# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
requirepass 123456
# New users are initialized with restrictive permissions by default, via the
将requirepass **** 打开,并重新设置密码
由于文件太大不方便查找,可以在vim的正常模式下输入
/requirepass(要查找的字符串)
重启redis-server
redis-server redis.conf
然后就OK了