Redis3.2开启远程访问

Redis3.2开启远程访问

环境

安装环境: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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

解决的过程

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

原文地址https://blog.csdn.net/u010956470/article/details/64440983