阿里云服务器远程连接redis

阿里云服务器远程连接redis

原因分析:
1)机器之间网络无法联通
2)ip和端口号不正确
3)虚拟机中防火墙的原因(可能性较大)
4)redis.conf 中bind 127.0.0.1 未用#注释掉

首先可能是云服务器的redis的6379端口无法访问,先在cmd中输入命令 telnet 127.0.0.1 6379。
然后出现报错说你的talnet的命令不存在。

-bash: telnet: command not found

然后需要安装telnet命令

  yum list telnet*              列出telnet相关的安装包
    yum install telnet-server          安装telnet服务
    yum install telnet.*           安装telnet客户端

之后再次

telnet 127.0.0.1 6379 

看看可不可以访问redis-server 机器的6379端口,如果不能访问,需要在远程机器关掉防火墙或者添加允许通过

1)使用root用户登录,vi /etc/sysconfig/iptables,添加如图所以一行
在这里插入图片描述
然后重启防火墙

systemctl restart iptables

再次报错

Redirecting to /bin/systemctl restart iptables.service

我们需要下载防火墙相关指令
1,安装systemctl:

yum install iptables-services

2,设置开机启动:

systemctl enable iptables.service

3.然后就可以执行重启等防火墙命令了

systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables

防火墙检查完后,如果还是出现上述问题,说明redis还有地方需要配置,redis默认是只有本机可以访问的,想要远程访问需要修改redis.conf配置文件。
进入redis.conf目录,并使用vim命令打开,找到bind那行修改后,wq保存退出,重启redis-server。
在这里插入图片描述
bind 后加的是允许访问的ip
bind 127.0.0.1代表只有本机可以访问,可以将允许访问的ip加入,也可以直接注释掉这一行,这样所有机器都可以访问。

解决上述问题后出现的新问题:DENIED Redis is running in protected mode

报错信息很长,但是主要是说redis开启了protected mode,这也是Redis3.2加入的新特性,开启保护模式的redis只允许本机登录,同样设置在配置文件redis.conf中,如图

在这里插入图片描述
这里原来是yes代表开启了保护模式,后面可以填密码也可以填no代表关闭,我们这里选择关闭保护模式,wq保存退出后再重启redis-server。

之后连接成功后是这样的

wangkongming@Vostro ~ $ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

如何退出呢?

ctrl+],然后再按q就可以了。

猜你喜欢

转载自blog.csdn.net/qq_43458555/article/details/108228936