redis叢集環境的搭建和錯誤分析
解決方法:
1)、將需要新增的節點下aof、rdb等本地備份檔案刪除;
2)、同時將新Node的叢集配置檔案刪除,即:刪除你redis.conf裡面cluster-config-file所在的檔案;
3)、再次新增新節點如果還是報錯,則登入新Node,./redis-cli–h x –p對資料庫進行清除:
172.168.63.201:7001> flushdb #清空當前資料庫
錯誤二
redis.clients.jedis.exceptions.JedisClusterException:CLUSTERDOWN The cluster is down
at redis.clients.jedis.Protocol.processError(Protocol.java:115)
at redis.clients.jedis.Protocol.process(Protocol.java:142)
at redis.clients.jedis.Protocol.read(Protocol.java:196)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:288)
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:207)
at redis.clients.jedis.Connection.getBulkReply(Connection.java:196)
at redis.clients.jedis.Jedis.get(Jedis.java:98)
at JedisTest.testJedisPool(JedisTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
錯誤至今沒有找到什麼原因
使用redis-3.0.0目錄下src下的redis-trib.rb check 192.168.218.128:6379進行檢查和進行redis-trib.rb fix 127.0.0.1:6380進行修復時
The
folowing uncovered slots have no keys across the cluster:
./redis-trib.rb:412:in `fix_slots_coverage': undefined method `keys' for #<Array:0xb76ec21c> (NoMethodError)
from ./redis-trib.rb:354:in `check_slots_coverage'
from ./redis-trib.rb:333:in `check_cluster'
from ./redis-trib.rb:847:in `fix_cluster_cmd'
from ./redis-trib.rb:1373:in `send'
from ./redis-trib.rb:1373
在用check檢查叢集執行狀態時,遇到錯誤;最終我知道那裡錯了,是我把單機版的redis.conf配置檔案開啟了cluster-enable
所以總是提示CLUSTERDOWN The cluster is down的錯誤,修改單機版redis配置檔案,關閉cluster-enable後正常。
錯誤三
[[email protected] src]# ./redis-trib.rb check 172.168.63.202:7000
Connecting to node 172.168.63.202:7000: OK
Connecting to node 172.168.63.203:7000: OK
Connecting to node 172.168.63.201:7000: OK
>>> Performing Cluster Check(using node 172.168.63.202:7000)
M: 449de2d2a4b799ceb858501b5b78ab91504c72e0172.168.63.202:7000
slots: (0 slots) master
0additional replica(s)
M: db9d26b1d15889ad2950382f4f32639606f9a94b172.168.63.203:7000
slots: (0 slots) master
0additional replica(s)
M: f90924f71308eb434038fc8a5f481d3661324792172.168.63.201:7000
slots: (0 slots) master
0additional replica(s)
[OK] All nodes agree about slotsconfiguration.
>>> Check for open slots...
>>> Check slots coverage...
[ERR] Not all 16384 slots are covered by nodes.
原因:
這個往往是由於主node移除了,但是並沒有移除node上面的slot,從而導致了slot總數沒有達到16384,其實也就是slots分佈不正確。所以在刪除節點的時候一定要注意刪除的是否是Master主節點。
1)、官方是推薦使用redis-trib.rb fix 來修復叢集…. …. 通過cluster nodes看到7001這個節點被幹掉了… 那麼
[[email protected] src]# ./redis-trib.rb fix 172.168.63.201:7001
修復完成後再用check命令檢查下是否正確
[[email protected] src]# ./redis-trib.rb check172.168.63.202:7000
只要輸入任意叢集中節點即可,會自動檢查所有相關節點。可以檢視相應的輸出看下是否是每個Master都有了slots,如果分佈不均勻那可以使用下面的方式重新分配slot:
[[email protected] src]# ./redis-trib.rb reshard 172.168.63.201:7001