获取远程redis服务器上的值

来源:互联网 发布:落樱神斧华盛顿知乎 编辑:程序博客网 时间:2024/04/30 04:43
环境:
两台虚拟机,ip分别为:192.168.2.100 、192.168.2.101
100 为 主,101为从。
redis 安装目录 /usr/local/redis-3.2.0  , redis-server,redis-cli 在 /usr/local/redis-3.2.0/src下
100 机器上有个 key为name ,value 为 11111的值。


遇到的问题:

一、100 直接使用 redis-server 启动 采用默认的配置文件
1、在 101上 通过 redis-cli -h 192.168.2.100 -p 6379 连接成功后,使用而 get name 出现

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

可以通过在 100 机器的redis-cli 命令中 使用 CONFIG SET protected-mode no 后,在执行 get name 就可以获取值。但在100重启后就不行了。


二、100通过 $ /usr/local/redis-3.2.0# src/redis-server ./redis.conf 启动 redis ,不修改 redis.conf任何内容。
1、在 101上 使用 redis-cli -h 192.168.2.100 -p 6379 出现
Could not connect to Redis at 192.168.2.100:6379: Connection refused
注释掉 100上的 redis.conf 中的 bind 127.0.0.1 ,后可以连接。

2、可以连接后执行 get name 后出现上面1.1的问题。
修改100上的 redis.conf 中的  protected-mode,把 yes 改为 no,重启redis,后就可以获取到值了。
0 0