redis解决(DENIED Redis is running in protected mode because prote)
早上一個(gè)應(yīng)用日志打印報(bào)錯(cuò)信息:
?
在應(yīng)用上telnet端口和ping都沒有問題,為什么還獲取不到值呢。
先安裝一個(gè)redis客戶端進(jìn)行測(cè)試:yum -y install redis
redis-cli -h 192.168.32.12 -p 6887
然后就報(bào)錯(cuò)了:
(error) DENIED Redis is running in protected mode because protected mode is……
?
后來就查看配置發(fā)現(xiàn)redis.conf 該行也是注釋的:
# requirepass foobared
?
繼續(xù)排查發(fā)現(xiàn)和一個(gè)參數(shù)配置有關(guān)系:
?
鏈接redis 時(shí)只能通過本地localhost (127.0.0.1)這個(gè)來鏈接,而不能用網(wǎng)絡(luò)ip(192.168..)這個(gè)鏈接,問題然如果用網(wǎng)絡(luò)ip 鏈接會(huì)報(bào)以下的錯(cuò)誤:
(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.
是說處于保護(hù)模式,只能本地鏈接,我們需要修改配置文件../redis.conf
1)打開配置文件把下面對(duì)應(yīng)的注釋掉
# bind 127.0.0.1?
2)Redis默認(rèn)不是以守護(hù)進(jìn)程的方式運(yùn)行,可以通過該配置項(xiàng)修改,使用yes啟用守護(hù)進(jìn)程,設(shè)置為no
daemonize no
3)保護(hù)模式
protected-mode no?
?
報(bào)錯(cuò)處理:
一、
在對(duì)應(yīng)配置conf文件中去掉注釋,把yes改為no
#protected-mode yes
protected-mode no
?
重啟redis(注意有數(shù)據(jù)時(shí)慎重啟)
kill -9 進(jìn)程號(hào)
redis-cli -h 192.168.32.12 -p 6887 shutdown
?
二、添加認(rèn)證,設(shè)置密碼
# requirepass foobared
requirepass redis123456
?
驗(yàn)證
再次用Java程序建立連接池,沒有報(bào)錯(cuò),且可以對(duì)redis server進(jìn)行數(shù)據(jù)正常處理。程序報(bào)錯(cuò)日志不再顯示
問題解決
?
linux下查看redis是否正常運(yùn)行
make
make PREFIX=/usr/local/redis install
mkdir /etc/redis/
cp redis.conf /etc/redis/
?
打開redis.conf文件修改daemonize yes即可在后臺(tái)運(yùn)行
vim /etc/redis/redis.conf
?
?
使用配置文件啟動(dòng)redis服務(wù)
./redis-server /etc/redis/redis.conf
?
?
如何查看redis服務(wù)正常啟動(dòng)?
使用ps查看或netstat
?
ps aux | grep redis-server?
-------------------------------------
總結(jié)
以上是生活随笔為你收集整理的redis解决(DENIED Redis is running in protected mode because prote)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信息学奥赛一本通高手训练1682:最小字
- 下一篇: MySQL ORDER BY 1 DES