溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題

發(fā)布時間:2021-07-01 10:48:53 來源:億速云 閱讀:226 作者:chen 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!

  最近有段時間沒有寫博客了,今天抽出時間寫寫,之前開發(fā)的時候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)

  經(jīng)過我英語八級的翻譯,上面一共提供了四種解決方案,但是綜合考慮為了簡單起見只需要執(zhí)行以下幾步即可:

  
 ?。?修改redis.conf配置文件,將綁定的ip地址端口號給注釋見下圖
  如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題

 ?。?由于Linux上的redis處于安全保護模式,這就讓你無法從虛擬機外部去輕松建立連接,這里就有兩種解決方法,一種是在redis.conf中設(shè)置保護模式為no,見下圖
  如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題

  4.好吧,此時你以為輕松解決問題了,于是再次在Linux啟動redis服務(wù)器后,在外部連接還是報錯,真是too young too native,起初我以為是配置沒有生效,因為明明配置都寫好了,于是殺掉redis的相關(guān)進程重啟服務(wù),結(jié)果發(fā)現(xiàn)還是沒卵用。最后研究發(fā)現(xiàn)問題所在:之前啟動redis-server并沒有指定配置文件,而Linux上的redis比較操蛋的一點就是如果你不指定配置文件去啟動,那么你做的修改就沒有用,會讀取默認配置(PS:至于這個默認配置在哪我也不清楚),于是用下面這種方式啟動就可以使修改的配置文件生效,至于config rewrite命令我測試了并沒有什么卵用。
  如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題
  
   6. 解決了這個問題就可以進行各種有趣的測試了哈哈

“如何解決Jedis連接Linux上的redis出現(xiàn) DENIED Redis is running in protected mode問題”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI