redis叢集建立錯誤的解決方法
阿新 • • 發佈:2020-11-23
作為建立叢集的新手很可能會出現建立叢集錯誤的可能性,比如使用了127.0.0.1也就是localhost來建立叢集,回送地址會導致外網無法訪問,但叢集的作用大部分的情況就是要提供外網來訪問。此文提供解決方法。
什麼樣的情況就是建立叢集錯誤了呢?
redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException: No more cluster attempts left. at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:86) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124) at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:25) at redis.clients.jedis.JedisCluster.set(JedisCluster.java:143) at com.taozi.rest.jedis.JedisTest.testJedisCluster(JedisTest.java:72) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Process finished with exit code -1
出現這種情況就是連線不上叢集,我使用的是java程式碼。
那麼叢集是怎麼建立的?
上命令:
5版本以前的:
redis-trib.rb create --replicas 1 192.168.56.102:7001 192.168.56.102:7002 192.168.56.103:7003 192.168.56.103:7004 192.168.56.104:7005 192.168.56.104:7006
之後的:
redis-cli --cluster create 192.168.56.102:7001 192.168.56.102:7002 192.168.56.102:7003 192.168.56.102:7004 192.168.56.102:7005 192.168.56.102:7006 --cluster-replicas 1
但若之前用過這些節點建立叢集,那就會出現一種錯誤。
[ERR] Node xxx is not empty. Either the node already knows other no...
原因
生成了每個節點的配置檔案和db的備份檔案,所以才會產生這個錯誤。
解決方法
請按如下步驟操作:
1、刪除每個redis節點的備份檔案,資料庫檔案和叢集配置檔案
比如說我有7001~7006 6個節點,那麼每個節點中的appendonly.aof、dump.rdb、node_xxx.conf檔案都要被刪除
但我用的是redis6版本,所以沒有生成這些檔案,但謹慎起見還是去看看。
2、使用redis-cli -c -h -p登入每個redis節點,使用以下命令
flushdb
cluster reset
3、重啟所有的redis服務,再試試redis叢集連線命令,應該就沒問題了
命令在上面,回頭瞅瞅。