springboot整合redis报错:链接失败; Unable to connect to Redis
生活随笔
收集整理的這篇文章主要介紹了
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
現在再運行項目就成功啦
總結
以上是生活随笔為你收集整理的springboot整合redis报错:链接失败; Unable to connect to Redis的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 客户端Git的常用命令
- 下一篇: c语言正则表达式