连接 阿里云redis实例 开启保护模式被拒

连接报错信息

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.

问题发生背景

  • 安全组配置 6379: 已经配置,不存在网络拦截问题
  • 注释了bind选项;#bind 127.0.0.1
  • 保护模式开启protected-mode yes

解决方案:

  • 关闭保护模式 修改redis启动配置文件 protected-mode no
  • 不关闭保护模式,有两个方法,设置bind 绑定ip地址,或者设置登入验证密码

    • 修改bind 参数,让他绑定到一个网络端口bind 192.168.1.202,这个是阿里云ECS 实例的内网地址,记住这里不能设置为实例的外网地址。如果你设置外网地址redis实例都启不起来。这时阿里云实例上运行的redis实例就可以连接外部连接请求,但是这样也有一个不好的问题,就是ECS实例必须通过./redis-cli -h 192.168.1.202 -p 6379才能连接上redis实例,不能通过回环地址./redis-cli -h 127.0.0.1 -p 6379连接上去。一个bind 修改方式添加两个网络接口:bind 192.168.1.202 127.0.0.1 ,这样本地客户端通过/redis-cli -h 127.0.0.1 -p 6379访问,远程客户端通过redis-cli.exe -h 外网ip -p 6379连接。

    • 不设置bind 参数 ,redis监听所由网络接口请求 requirepass 123456 设置requirepass选项 就是给登入redis实例设置验证密码。这个方式也是可行的。

这两个方式二选一,随便哪个即可。我选择的bind参数,不设置密码。
也可以两个选项都设置,即设置监听的网络接口IP地址,也设置登入验证密码。

猜你喜欢

转载自blog.csdn.net/jq_ak47/article/details/80556069