1. 程式人生 > >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

解決的過程

由於百度得到的答案基本都是說把“bind 127.0.0.1”註釋掉就可以了,根據配置檔案的描述,也確實是要註釋掉才可以被其他機器訪問到,配置完重啟,通過其他機器的redis-cli客戶端進行連線,連線命令:redis-cli -h 172.16.8.200 -p 6379
意外的發現竟然連上了,於是隨表敲一個命令,比如info,出現瞭如下提示:
這裡寫圖片描述
通過閱讀提示,在配置檔案中找到protected-mode,並將其值改為no,重啟之後,問題解決了。