Redis3.2开启远程访问

本文介绍如何在Windows环境下配置Redis以支持远程访问。主要内容包括修改配置文件中的bind参数以允许外部连接,以及禁用protected-mode来确保非本地客户端可以成功连接。

环境

安装环境:win7系统
Redis版本:3.2.100
安装模式:msi文件安装

开启远程访问

Redis安装完之后,在服务中可以看到对应的Redis服务,打开属性,可以看到“可执行文件的路径”是:”D:\Program Files\Redis\redis-server.exe” –service-run “D:\Program Files\Redis\redis.windows-service.conf”
开启Redis远程访问的步骤如下:

  1. 打开redis.windows-service.conf
  2. 找到“bind 127.0.0.1”并在前面加#注释
  3. 找到“protected-mode yes”并改为“protected-mode no”

配置如下:

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

解决的过程

由于百度得到的答案基本都是说把“bind 127.0.0.1”注释掉就可以了,根据配置文件的描述,也确实是要注释掉才可以被其他机器访问到,配置完重启,通过其他机器的redis-cli客户端进行连接,连接命令:redis-cli -h 172.16.8.200 -p 6379
意外的发现竟然连上了,于是随表敲一个命令,比如info,出现了如下提示:
这里写图片描述
通过阅读提示,在配置文件中找到protected-mode,并将其值改为no,重启之后,问题解决了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值