最近有段時間沒有寫博客了,今天抽出時間寫寫,以前開發的時候redis部署在Linux是其餘人搞得,我沒怎麼參與,因而閒着無聊在本地的虛擬機上安裝了個redis進行測試,沒想到在進行鏈接時報了下面這麼一個錯,fuck,Linux上的redis還真是麻煩,哪像windows上的redis這麼簡單一解壓完事
java
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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. at redis.clients.jedis.Protocol.processError(Protocol.java:127) at redis.clients.jedis.Protocol.process(Protocol.java:161) at redis.clients.jedis.Protocol.read(Protocol.java:215) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239) at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196) at com.example.redis.JedisTest.main(JedisTest.java:24)
1.修改redis.conf配置文件,將綁定的ip地址端口號給註釋見下圖
redis
2.因爲Linux上的redis處於安全保護模式,這就讓你沒法從虛擬機外部去輕鬆創建鏈接,這裏就有兩種解決方法,一種是在redis.conf中設置保護模式爲no,見下圖
windows
3.另一種方式是加上安全認證,即redis默認是沒有密碼的能夠直接登陸,這裏加上密碼,配置見下圖
安全
4.好吧,此時你覺得輕鬆解決問題了,因而再次在Linux啓動redis服務器後,在外部鏈接仍是報錯,真是too young too native,起初我覺得是配置沒有生效,由於明明配置都寫好了,因而殺掉redis的相關進程重啓服務,結果發現仍是沒卵用。最後研究發現問題所在:以前啓動redis-server並無指定配置文件,而Linux上的redis比較操蛋的一點就是若是你不指定配置文件去啓動,那麼你作的修改就沒有用,會讀取默認配置(PS:至於這個默認配置在哪我也不清楚),因而用下面這種方式啓動就可使修改的配置文件生效,至於config rewrite命令我測試了並無什麼卵用。
服務器
5.再次測試,在windows上進行jedis鏈接測試,出現下面pong(),惱人的錯誤終於消失了,比起windows版本的redis還真是讓人龜毛啊,若是配置了密碼認證,調用Jedis的auth方法輸入密碼便可
6. 解決了這個問題就能夠進行各類有趣的測試了哈哈ide