环境说明
windows win7 32位
虚拟机VMware
镜像: CentOS 7
-- 安装
CentOS7 安装redis
sudo yum install gcc
mkdir src
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
tar zvxf redis-4.0.1.tar.gz
cd redis-4.0.1
make && make install
测试CentOS上安装是否成功
cd src/
redis-server
redis-cli
127.0.0.1:6379>ping
PONG
配置为windows可访问
1。防火墙增加6379访问
firewall-cmd --zone=public --add-port=6379/tcp --permanent #永久增加6379端口访问
firewal-cmd --reload #重启防火墙
sudo iptables -L -n |grep 6379 #检查防火墙规则列表是否添加成功
2. 修改redis配置开启网络可访问
redis为了用户安装redis后的安全,默认开启保护模式,且绑定IP地址为回环地址,该方式仅允许安装redis的本机进行访问,我们需要在虚拟机外的windows上进行连接就需要开启网络所有连接。
修改redis.conf
注释掉 bind 127.0.0.1
关闭保护模式
protected-mode no
以上情况未修改,且未开启密码的情况下会在windows上连接时出错 :
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions:
1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
3.在windows上测试是否可连接
确保windows和虚拟机可以互相 ping通
下载安装 redis desktop manager
配置后点 test Connection 可以看到是否可成功访问;
以上为windows连接 虚拟机中redis的教程,祝你好运。