java連接redis時出現故障時的解決方法


報錯信息:

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.

翻譯后:

DENIED Redis正在保護模式下運行,因為已啟用保護模式,未指定綁定地址,未向客戶端請求身份驗證密碼。在此模式下,只能從環回接口接受連接。如果要從外部計算機連接到Redis,可以采用以下解決方案之一:1)通過從服務器運行的同一主機連接到Redis,從環回接口發送命令“CONFIG SET protected mode no”,即可禁用受保護模式,然而,若你們這樣做的話,請確保Redis不能從互聯網上公開訪問。使用“配置重寫”將此更改永久化。2) 或者,您可以通過編輯Redis配置文件,將受保護模式選項設置為“否”,然后重新啟動服務器來禁用受保護模式。3) 如果只是為了測試而手動啟動服務器,請使用“--protectedmodeno”選項重新啟動服務器。4) 設置綁定地址或身份驗證密碼。注意:您只需要執行上述操作之一,服務器就可以開始接受來自外部的連接。

第一個設置:

  1. 在redis的安裝目錄中,進入redis.conf配置文件 vim redis.conf

  2. 注釋掉如圖所示的這一行,我這里已經注釋過了

 

 

  1. 如圖所示的這一行,配置改成yes,我這里已經改過了

 

 

  1. 如圖所示的配置改為no,我這里已經改過了

 

 

  1. 之后保存,退出vim

  2. 啟動redis服務,進入redis-cli中執行 config set protected-mode "no"

 

 

注意:完成配置后,需要重新指定其配置文件,在redis安裝目錄下執行:redis-server & ./redis.cli

第二個設置

  • 關閉防火牆,其命令為:systemctl stop firewalld

  • 或者放行redis的端口6379,

    其命令為:firewall-cmd --permanent --add-port=6379/tcp

    firewall-cmd --reload





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM