解决使用jedis连接是报DENIED Redis is running in protected mode错误
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.
1. 错误原因:由于redis的保护模式开启了,并且没有绑定ip地址,没有密码认证
2. 解决方案
方案一:
1) 使用 设置CONFIG SET protected-mode no
步骤:
1. 在redis本机上打开redis-cli工具,并连接
2. 在其中输入CONFIG SET protected-mode no即可
缺点:
该种方式只是短暂性有效,如果redisServer重新启动后还是不能正常链接
方案二:
1)编辑redis配置文件,将保护模式关闭
步骤:
由于我是直接使用redis-server 命令启动的,所以说其服务是按照其默认设置进行启动,修改/usr/local/etc/redis.conf
如果没有请从下载的redis中复制一个redis.conf到这里,
将bind 后面绑定的ip后面加入你本机外网的ip
bind 127.0.0.1 192.168.21.4
然后保存,再使用redis-server /usr/local/etc/redis.conf启动
问题:
1.redis-cli不能直接使用,必须输入绑定的ip+d端口号才能正常使用
2.不安全
2). 将redis.conf中安全模式关闭
将该保护模式改为no
再试
缺点:1.保护模式关闭后不安全
3)设置密码访问模式
在redis.conf中加入一行密码设置
require 你的密码
保存,再重新启动redis客户端
以上四种方式解决该错误都可以,但是根据上面的优缺点,
选择第四种方式最佳,安全性最高