redis集群環境搭建的錯誤
安裝redis集群需要版本號在3.0以上
redis-cluster安裝前需要安裝ruby環境
搭建集群需要使用到官方提供的ruby腳本。
需要安裝ruby的環境。
yum -y install ruby
yum -y install rubygems
redis集群管理工具redis-trib.rb
[root@bogon ~]# cd redis-3.0.0
[root@bogon redis-3.0.0]# cd src
[root@bogon src]# ll *.rb
-rwxrwxr-x.1 root root 48141 Apr 1 07:01 redis-trib.rb
腳本需要的ruby包:redis-3.0.0.gem
安裝 gem install redis-3.0.0.gem
[root@bogon ~]# gem install redis-3.0.0.gem
Successfully installed redis-3.0.0
1 gem installed
Installing ri documentation forredis-3.0.0...
Installing RDoc documentation forredis-3.0.0...
集群的搭建
需求,創建6臺redis服務器,虛擬機模擬端口號為7001-7006第二步:修改redis的配置文件
1、修改端口號 第三步:把創建集群的ruby腳本復制到redis-cluster目錄下。第五步:創建集群。
./redis-trib.rb create --replicas 1 192.168.25.153:7001 192.168.25.153:7002 192.168.25.153:7003 192.168.25.153:7004 192.168.25.153:7005 192.168.25.153:7006 |
解決方法:
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 fix127.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後正常。
錯誤三
[root@node01 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這個節點被幹掉了… 那麽
[root@node01 src]# ./redis-trib.rb fix 172.168.63.201:7001
修復完成後再用check命令檢查下是否正確
[root@node01 src]# ./redis-trib.rb check172.168.63.202:7000
只要輸入任意集群中節點即可,會自動檢查所有相關節點。可以查看相應的輸出看下是否是每個Master都有了slots,如果分布不均勻那可以使用下面的方式重新分配slot:
[root@node01 src]# ./redis-trib.rb reshard 172.168.63.201:7001
redis集群環境搭建的錯誤