如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题

发布时间:2021-07-01 10:48:53 作者:chen
来源:亿速云 阅读:222

本篇内容介绍了“如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

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

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地址端口号给注释见下图
  如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题

  2.由于Linux上的redis处于安全保护模式,这就让你无法从虚拟机外部去轻松建立连接,这里就有两种解决方法,一种是在redis.conf中设置保护模式为no,见下图
  如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题

  4.好吧,此时你以为轻松解决问题了,于是再次在Linux启动redis服务器后,在外部连接还是报错,真是too young too native,起初我以为是配置没有生效,因为明明配置都写好了,于是杀掉redis的相关进程重启服务,结果发现还是没卵用。最后研究发现问题所在:之前启动redis-server并没有指定配置文件,而Linux上的redis比较操蛋的一点就是如果你不指定配置文件去启动,那么你做的修改就没有用,会读取默认配置(PS:至于这个默认配置在哪我也不清楚),于是用下面这种方式启动就可以使修改的配置文件生效,至于config rewrite命令我测试了并没有什么卵用。
  如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题
  
   6. 解决了这个问题就可以进行各种有趣的测试了哈哈

“如何解决Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. centOS下安装Redis
  2. Redis知识点

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

redis linux jedis

上一篇:spring cloud中FeignClientFactoryBean的原理和作用是什么

下一篇:微服务中eureka+zuul的基本部署教程

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》