学习redis,今天遇到windows客户端无法链接linux上的服务的问题,查资料解决,过程如下。
linux上打开redis.conf文件,
1,将127.0.0.1这行给注释掉,(该行使其默认只有本机可以连接)
2,将protected-mod yes 修改为protected-mod no ,关闭保护模式,可以接受其他机器的访问。
3,关闭防火墙,我的linux是centos7,它的默认防火墙是firewalld,因为不熟悉,先将他换成centos6中的iptables,然后关闭防火墙,操作如下。
[root@d ~]# systemctl stop firewalld // 关闭firewalld服务
[root@d ~]# systemctl disable firewalld // 禁止开机启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@d ~]# yum install -y iptables-services // 安装iptables-service
[root@d ~]# systemctl enable iptables //让它开机启动
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@d ~]# systemctl start iptables 启动服务。
[root@d ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT // 添加一条规则
[root@d ~]# service iptables restart // 重启服务
至此,重启redis服务即可在windows上链接,命令如下。
D:\redis\redis-64.3.0.503>redis-cli.exe -h 192.168.0.106 -p 6379