redis解決(DENIED Redis is running in protected mode because prote)


早上一個應用日誌打印報錯信息:redis

wKiom1g-cNXwSl0FAAAlafexExk279.png


在應用上telnet端口和ping都沒有問題,爲何還獲取不到值呢。網絡

先安裝一個redis客戶端進行測試:yum -y install rediside

redis-cli -h 192.168.32.12 -p 6887oop

而後就報錯了:測試

(error) DENIED Redis is running in protected mode because protected mode is……ui


後來就查看配置發現redis.conf 該行也是註釋的:this

# requirepass foobared
spa


繼續排查發現和一個參數配置有關係:3d


連接redis 時只能經過本地localhost (127.0.0.1)這個來連接,而不能用網絡ip(192.168..)這個連接,問題然若是用網絡ip 連接會報如下的錯誤:
(error) 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 lookback 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 --portected-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.
是說處於保護模式,只能本地連接,咱們須要修改配置文件../redis.conf

1)打開配置文件把下面對應的註釋掉
# bind 127.0.0.1

2)Redis默認不是以守護進程的方式運行,能夠經過該配置項修改,使用yes啓用守護進程,設置爲no
daemonize no

3)保護模式
protected-mode no

rest

報錯處理

1、

在對應配置conf文件中去掉註釋,把yes改成no

#protected-mode yes
protected-mode no


重啓redis(注意有數據時慎重啓)

kill -9 進程號

redis-cli -h 192.168.32.12 -p 6887 shutdown


2、添加認證,設置密碼

# requirepass foobared

requirepass redis123456


驗證

再次用Java程序創建鏈接池,沒有報錯,且能夠對redis server進行數據正常處理。程序報錯日誌再也不顯示

問題解決

相關文章
相關標籤/搜索