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.
1. 錯誤原因:由於redis的保護模式開啟了,並且沒有繫結ip地址,沒有密碼認證
2. 解決方案
方案一:
1) 使用 設定CONFIG SET protected-mode no
步驟:
1. 在redis本機上開啟redis-cli工具,並連線
2. 在其中輸入CONFIG SET protected-mode no即可
缺點:
該種方式只是短暫性有效,如果redisServer重新啟動後還是不能正常連結
方案二:
1)編輯redis配置檔案,將保護模式關閉
步驟:
由於我是直接使用redis-server 命令啟動的,所以說其服務是按照其預設設定進行啟動,修改/usr/local/etc/redis.conf
如果沒有請從下載的redis中複製一個redis.conf到這裡,
將bind 後面繫結的ip後面加入你本機外網的ip
bind 127.0.0.1 192.168.21.4
然後儲存,再使用redis-server /usr/local/etc/redis.conf啟動
問題:
1.redis-cli不能直接使用,必須輸入繫結的ip+d埠號才能正常使用
2.不安全
2). 將redis.conf中安全模式關閉
將該保護模式改為no
再試
缺點:1.保護模式關閉後不安全
3)設定密碼訪問模式
在redis.conf中加入一行密碼設定
require 你的密碼
儲存,再重新啟動redis客戶端
以上四種方式解決該錯誤都可以,但是根據上面的優缺點,
選擇第四種方式最佳,安全性最高