Redis连接问题解决汇总

Redis连接失败常见解决方案

1. 检查Redis命令行是否可以正常连接

使用命令行客户端,输入:

redis-cli -h 虚拟机ip地址 -p 6379 -a redis访问密码

如若连接成功,输入ping,看控制台是否返回PONG

此步骤若正常,则代表虚拟机可正常连接

2. Redis命令行无法正常连接

1)未打开Redis6379端口

以CentOS7下开启redis6379端口为例:

  • 查看防火墙
systemctl status firewalld

此处若报错Unit not found,请向后看2)

  • 开启端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
  • 重启防火墙:
systemctl restart firewalld.service
  • 再次查看端口状态
firewall-cmd --list-ports

2)Centos7启动防火墙时Failed to start firewall.service: Unit not found.

问题原因:未安装防火墙

依次输入以下命令:

yum install firewalld
systemctl unmask firewalld
systemctl enable firewalld
systemctl start firewalld

其他命令:

systemctl start firewalld.service //开启防火墙
systemctl stop firewalld.service //关闭防火墙
systemctl enable firewalld.service //设置开机自动启动
systemctl disable firewalld.service //设置关闭开机制动启动
firewall-cmd --reload //在不改变状态的条件下重新加载防火墙

3)超时问题:Job for redis.service failed because a timeout was exceeded. See "systemctl status redis.service" and "journalctl -xe" for details.

解决办法:将redis.service中的Type=forking配置删除即可。

4)本地redis.conf配置文件问题

find / -name “redis.conf” 查找redis.conf文件并进行以下修改:

1.bind 127.0.0.1 修改为 bind 0.0.0.0
127.0.0.1  	表示只允许本地访问,无法远程连接
0.0.0.0     表示任何ip都可以访问

2.protected-mode yes 改为 protected-mode no
yes			  保护模式,只允许本地链接
no			  保护模式关闭

3.daemonize yes 改为 daemonize no 
yes 代表开启守护进程模式。此时是单进程多线程的模式,redis将在后台运行。
no 当前界面将进入redis的命令行界面,exit强制退出或者关闭连接工具都会导致redis进程退出

3. Redis客户端可正常连接,RESP无法正常连接

关闭虚拟机防火墙

systemctl stop firewalld

再次查看防火墙状态,应处于inactive状态

systemctl status firewalld

此处注意:防火墙可能只是暂时关闭,若设置了关闭依旧连接不上,请设置永久关闭防火墙

sudo systemctl disable firewalld
posted @   爪娃侠  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示