出现错误:
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
解决问题:
关闭Redis
打开redis-cli, 输入
shutdown
看到
退出成功
修改配置文件
找到redis的配置文件,一般在/usr/local/redis/目录下,使用vim打开配置文件
sudo vim redis.conf #根据文件名自行输入
然后输入密码
搜索需要修改的配置,“ / ”为搜索
/protected-mode
输入i 然后将protected-mode yes 修改为 protected-mode no
同理修改requirepass *******这里“ * ”作为密码
然后注释掉bind
保存配置文件
点击ESC键后输入
:wq!
关闭虚拟机的防火墙
systemctl stop firewalld.service
重启Redis
使用指定配置文件启动redis
./bin/redis-server redis.conf
连接远程redis
redis-cli -h 你的Redis所在主机的ip地址 -p 端口 -a 密码