springboot整合redis报错:链接失败; Unable to connect to Redis
springboot整合redis报错:链接失败;org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
一般这种报错的原因要么是没有开放虚拟机的6379的端口号,要么是因为redis的配置文件没有修改。现在我们来一个一个排除解决这些问题。
开放6379端口号
1,开启防火墙
systemctl start firewalld
2,开放指定端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
3,重启防火墙
firewall-cmd --reload
修改redis的配置文件redis.conf
vim /usr/local/bin/myredisconfig/redis.conf
进入redis的编辑将 bind 127.0.0.1 注释,将 protected-mode 改为 no:
默认情况bind 127.0.0.1只能接受本机的访问请求,注释掉则意味着无限制接受任何ip地址的访问, 生产环境肯定要写你应用服务器的地址;如果开启了 protected-mode,那么在没有设定 bind ip 且没有设密 码的情况下,Redis 只允许接受本机的响应。
关闭redis
redis-cli -h 127.0.0.1 -p 6379 shutdown
启动redis
redis-server myredisconfig/redis.conf
redis-server myredisconfig/redis.conf
现在再运行项目就成功啦