自己一直都是連本地redis,直接上localhost,沒毛病。心血來潮連個linux系統上的redis,就遇到了連線不了的問題
使用IDEA搭建SpringBoot將redis伺服器ip地址改為另一臺電腦時,出現錯誤,專案無法啟動,但是ping目標地址能ping通,通過本地電腦的redis進行連線
redis-cli -h 192.168.xx.xxx -p 6379
結果:由於目標計算機積極拒絕,無法連線
之前以為是防火牆的問題,就進行了下述操作,但並沒有用,不知道該操作影響到後面沒有就貼了上來
// 查詢埠是否開放
firewall-cmd --query-port=6379/tcp
// 開放埠
firewall-cmd --permanent --add-port=6379/tcp
// 重新啟動防火牆
firewall-cmd --reload
百度看到這篇貼文redis由於目標計算機積極拒絕,無法連線,瞭解到只要更改redis的組態檔redis.conf就可以解決這個問題,但是因為自己通過apt-get安裝的redis,不清楚這些檔案放哪了通過whereis redis.conf找到了對應的檔案目錄
在對應目錄使用sudo vim redis.conf命令開啟該檔案將bind127.0.0.1註釋掉,
通過redis-server /etc/redis/redis.conf重新啟動redis,嘗試連線,但發現並沒有用,還是拒絕連線,果斷重新啟動裝linux的那臺電腦,果然解決了這個問題,在本地電腦使用redis-cli連線也成功了,但是輸入命令無效,產生了下一個問題
可以連線但是命令不起作用,SpringBoot報錯
Caused by: io.lettuce.core.RedisConnectionException: 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.
通過提示將組態檔的protected-mode這個引數設為no就成功解決了,當然也是重新啟動了redis以及電腦。