註:此文章內容有誤,正確請參考http://blog.csdn.net/hel12he/article/details/46911159
在設定檔redis.conf中,預設的bind 介面是127.0.0.1,也就是本地迴環地址。這樣的話,訪問redis服務只能通過原生用戶端串連,而無法通過遠端連線,
這樣可以避免將redis服務暴露於危險的網路環境中,防止一些不安全的人隨隨便便通過遠程
串連到redis服務。
如果bind選項為空白的話,那會接受所有來自於可用網路介面的串連。
例子:
比如有兩台redis伺服器,ip分別為:192.168.1.101和192.168.1.103,如何在101上通過redis-cli訪問103上的redis呢。在遠端連線103之前,先講下redis-cli的幾個關鍵參數:
用法:redis-cli [OPTIONS] [cmd [arg [arg ...]]]-h <主機ip>,預設是127.0.0.1
-p <連接埠>,預設是6379
-a <密碼>,如果redis加鎖,需要傳遞密碼
--help,顯示協助資訊
當在101上通過redis-cli訪問103上的redis時,首先要修改103上的redis.conf檔案,在bind下加一行:bind 192.168.1.101
這樣103上的redis服務就可以listen來自192.168.1.101的串連。
通過對rendis-cli用法介紹,在101上串連103應該很簡單: [plain] view plain cop [root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379 redis 192.168.1.103:6379>
官方文檔介紹:
Protected mode
Unfortunately many users fail to protect Redis instances from being accessed from external networks. Many instances are simply left exposed on the internet with public IPs. For this reasons since version 3.2.0, when Redis is executed with the default configuration (binding all the interfaces) and without any password in order to access it, it enters a special mode called proteced mode. In this mode Redis only replies to queries from the loopback interfaces, and reply to other clients connecting from other addresses with an error, explaining what is happening and how to configure Redis properly.