关于Jedis链接Linux上的redis出现 DENIED Redis is running in protected mode问题的解决方案

  最近有段时间没有写博客了,今天抽出时间写写,以前开发的时候redis部署在Linux是其余人搞得,我没怎么参与,因而闲着无聊在本地的虚拟机上安装了个redis进行测试,没想到在进行链接时报了下面这么一个错,fuck,Linux上的redis还真是麻烦,哪像windows上的redis这么简单一解压完事
  java

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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.
    at redis.clients.jedis.Protocol.processError(Protocol.java:127)
    at redis.clients.jedis.Protocol.process(Protocol.java:161)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196)
    at com.example.redis.JedisTest.main(JedisTest.java:24)
  通过我英语八级的翻译,上面一共提供了四种解决方案,可是综合考虑为了简单起见只须要执行如下几步便可:

  
  1.修改redis.conf配置文件,将绑定的ip地址端口号给注释见下图
  这里写图片描述redis

  2.因为Linux上的redis处于安全保护模式,这就让你没法从虚拟机外部去轻松创建链接,这里就有两种解决方法,一种是在redis.conf中设置保护模式为no,见下图
  这里写图片描述windows

  3.另一种方式是加上安全认证,即redis默认是没有密码的能够直接登陆,这里加上密码,配置见下图
  这里写图片描述安全

  4.好吧,此时你觉得轻松解决问题了,因而再次在Linux启动redis服务器后,在外部链接仍是报错,真是too young too native,起初我觉得是配置没有生效,由于明明配置都写好了,因而杀掉redis的相关进程重启服务,结果发现仍是没卵用。最后研究发现问题所在:以前启动redis-server并无指定配置文件,而Linux上的redis比较操蛋的一点就是若是你不指定配置文件去启动,那么你作的修改就没有用,会读取默认配置(PS:至于这个默认配置在哪我也不清楚),因而用下面这种方式启动就可使修改的配置文件生效,至于config rewrite命令我测试了并无什么卵用。
  这里写图片描述服务器

  5.再次测试,在windows上进行jedis链接测试,出现下面pong(),恼人的错误终于消失了,比起windows版本的redis还真是让人龟毛啊,若是配置了密码认证,调用Jedis的auth方法输入密码便可
   这里写图片描述
  
   6. 解决了这个问题就能够进行各类有趣的测试了哈哈ide

相关文章
相关标签/搜索