欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Redis3.2开启远程访问详细步骤

程序员文章站 2022-04-06 19:18:30
redis默认只允许本地访问,要使redis可以远程访问可以修改redis.conf  打开redis.conf文件在network部分有说明 ###...

redis默认只允许本地访问,要使redis可以远程访问可以修改redis.conf
 打开redis.conf文件在network部分有说明

################################## 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

使redis可以远程访问只要注释掉redis.conf配置文件中的 bind 127.0.0.1 即可以使所有的ip访问redis

若是想指定多个ip访问,但并不是全部的ip访问,可以bind多个ip

注意

在redis3.2之后,redis增加了protected-mode,在这个模式下,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下

(error) 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.

解决方法是修改原protected-mode yes为protected-mode no

保存配置文件重启redis即可