redis關閉保護模式


1. set key出現的報錯

在192.168.56.57客戶端登錄192.168.56.56的redis服務器時,報錯如下:  
[root@localhost src]# ./redis-cli -h  192.168.56.56  -p  6379 -a  "aabbcc"  
192.168.56.56:6379> ping  
Error: Connection reset by peer  
  
   
再telnet一下192.168.56.56的redis服務器的6379端口,提示redis服務有保護模式,需要解除  
[root@localhost src]# telnet 192.168.56.56  6379  
Trying 192.168.56.56...  
Connected to 192.168.56.56.  
Escape character is '^]'.  
  
-DENIED Redis is running in protected modebecause protected mode is enabled, no bind address was specified, noauthentication password is requested to clients.   
In this mode connections areonly accepted from the loopback interface. If you want to connect from externalcomputers to Redis you may adopt one of the following   
solutions: 1) Justdisable protected mode sending the command 'CONFIG SET protected-mode no' fromthe loopback interface by connecting to Redis from the same host   
the server isrunning, however MAKE SURE Redis is not publicly accessible from internet ifyou do so. Use CONFIG REWRITE to make this change permanent.   
2) Alternativelyyou can just disable the protected mode by editing the Redis configurationfile, and setting the protected mode option to 'no', and then restarting theserver.   
3) If you started the server manually just for testing, restart it withthe '--protected-mode no' option.   
4) Setup a bind address or an authenticationpassword. NOTE: You only need to do one of the above things in order for theserver to start accepting connections from the outside.  
Connection closed by foreign host.  

2. 原因是redis的保護模式

默認redis需要設置管理員賬號密碼,開啟了保護模式

所以如果第一次使用沒有設置管理員,就會出現報錯,關閉保護模式即可

3. 解決方法

方法一:

修改redis的守護進程為no ,不啟用  
127.0.0.1:6379> config set daemonize "no"  
OK  
  
修改redis的保護模式為no,不啟用  
127.0.0.1:6379> config set protected-mode "no"  
OK  

方法二:推薦

修改配置文件

1) 綁定IP地址,看業務開放
bind 0.0.0.0

2)Redis默認不是以守護進程的方式運行,可以通過該配置項修改,使用yes啟用守護進程,設置為no

daemonize no

3)保護模式

protected-mode no 

3. 啟動加載配置文件

/usr/local/redis/bin/redis-server  /usr/local/redis/conf/redis6379.conf
# 檢查啟動狀態命令
ps -ef|grep redis |grep 6379

 


免責聲明!

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



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