redis集群创建错误的解决方法
作者:互联网
作为创建集群的新手很可能会出现创建集群错误的可能性,比如使用了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集群连接命令,应该就没问题了
命令在上面,回头瞅瞅。
标签:ParentRunner,java,创建,redis,集群,org,JedisClusterCommand,junit 来源: https://blog.csdn.net/weixin_46017976/article/details/109993165