1、錯誤原因
Redis搭建好后一般都是使用編程語言進行連接調用,默認Redis的設置是不允許外界訪問的,外界telnet請求Redis服務器的時候會有如下提示:
-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.
這說明目前處在保護模式上,查看Redis的注釋可以了解,連接Redis只能通過本地(127.0.0.1)來連接,而不能使用網絡IP(192.168.1.x)來連接,如果需要請修改配置文件redis.conf
2、解決方案
進入Redis目錄打開Redis.conf配置文件
1>注釋掉bind #bind 127.0.0.1 2>默認不是守護進程方式運行,這里可以修改 daemonize no 3>禁用保護模式 protected-mode no
啟動Redis並指明配置文件
redis-server ../redis.conf
OK,通過外網telnet一下Redis服務器看看是否通了,在編程語言中連接Redis也就可以了
3、附錄
用一個外部客戶端RedisStudio來訪問查看Redis的數據