redis从3.2版本后增长了几个参数,其中 protected-mode参数注意的事项redis
protected-mode参数是为了禁止外网访问redis,若是启用了,则只可以经过lookback ip(127.0.0.1)访问Redis,若是外网访问redis,会报出异常:ide
(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.
配置方式:oop
redis实例的配置文件中禁用bind参数this
#bind
redis实例的配置文件中设置protected-mode参数为norest
protected-mode no
若是redis实例配置文件中禁用了bind参数,并将protected-mode设置为no后,外网访问redis依然报上述错误,由于 sentinel 实例的配置文件中须要增长参数 protected-mode nocode
sentinel实例的配置文件中增长参数server
protected-mode no