当前位置:   article > 正文

Springboot非本地连接虚拟机的Redis失败_springboot lettuceconnectionfactory 判断是否连接失败

springboot lettuceconnectionfactory 判断是否连接失败

出现错误:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.44.129:6379

	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1534)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1442)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1228)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1211)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:975)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:360)
	at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:134)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:97)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:84)
	Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.44.129:6379
	at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
	at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
	at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:242)
	at io.lettuce.core.RedisClient.connect(RedisClient.java:206)
	at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115)
	at java.util.Optional.orElseGet(Optional.java:267)
	at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1440)
	... 75 more
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

解决问题:


关闭Redis
打开redis-cli, 输入

shutdown
  • 1

看到
在这里插入图片描述
退出成功


修改配置文件
找到redis的配置文件,一般在/usr/local/redis/目录下,使用vim打开配置文件

sudo vim redis.conf #根据文件名自行输入
  • 1

然后输入密码

搜索需要修改的配置,“ / ”为搜索

/protected-mode
  • 1

输入i 然后将protected-mode yes 修改为 protected-mode no

同理修改requirepass *******这里“ * ”作为密码
在这里插入图片描述

然后注释掉bind
在这里插入图片描述

保存配置文件
点击ESC键后输入

:wq!
  • 1

关闭虚拟机的防火墙

systemctl stop firewalld.service
  • 1

重启Redis
使用指定配置文件启动redis

./bin/redis-server redis.conf
  • 1


连接远程redis

redis-cli -h 你的Redis所在主机的ip地址 -p 端口 -a 密码
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/991490
推荐阅读
相关标签
  

闽ICP备14008679号