我正在使用 Redis 3.2 ,在从不同的机器连接到哨兵时,我收到以下错误:
Trying X.X.X.X...
Connected to X.X.X.X.
Escape character is '^]'.
-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.
Connection closed by foreign host.
somene能帮我解决这个问题吗?
答案 0 :(得分:12)
从redis 3.2开始,默认情况下为Sentinel,无法从localhost以外的接口访问。
使用'bind'指令绑定到网络接口列表,或者通过将保护模式添加到此配置文件中来禁用带有“protected-mode no”的保护模式。
例如,您可以使用以下其中一项:
bind 127.0.0.1 192.168.1.1
protected-mode no
答案 1 :(得分:4)
测试时,您可以尝试
redis-server --protected-mode no
这会将Redis保护模式设置为no。
从文档建议的步骤开始。
1)只需禁用发送命令' CONFIG SET的保护模式 保护模式没有'通过连接到Redis从loopback接口 来自服务器正在运行的同一主机,但是确保Redis是 如果您这样做,则无法从互联网上公开访问。使用CONFIG REWRITE 使这一变化永久化。
2)或者您可以通过编辑禁用保护模式 Redis配置文件,并将protected mode选项设置为 ' no',然后重新启动服务器。
3)如果您手动启动服务器进行测试,请重新启动它 使用' - 保护模式否'选项。
4)设置绑定地址或验证密码。注意:您只 需要执行上述操作之一才能启动服务器 接受来自外部的联系。