Redis外网无法连接的问题

在服务器上,安装了redis且启动,使用默认的6379端口,但是外网无法连接,telnet ip 6379不通。

首先看云服务器安全组规则,6379是否允许访问。

保险起见同时在服务器上关闭了防火墙和iptables服务

systemctl stop firewalld
service iptables stop

查看防火墙和iptables状态

systemctl status firewalld
service iptables status

确认是关闭的,但是telnet ip 6379仍是不通。

继续排查:

netstat -ano |grep :6379
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      off (0.00/0/0)

找到问题了,redis服务配置有问题,只能使用127.0.0.1端口访问

解决:

# 编辑配置文件
vi redis.conf
#注释绑定机器网卡的ip和关闭保护模式,允许外部网络访问
# bind 127.0.0.1
protected-mode no
# 允许后台运行
daemonize yes

重新启动:

src/redis-server redis.conf

再次测试,telnet已通,使用java代码连接,操作正常。

其他的外网无法访问的情况可以使用同样的方法排查。 

posted @ 2020-11-07 12:29  以战止殇  阅读(1716)  评论(0编辑  收藏  举报