redis-3.0.6 安裝叢集

深圳gg發表於2019-02-25

redis安裝包下載:
http://download.redis.io/releases/redis-3.0.6.tar.gz

安裝報錯1,需要下載tcl8.6.1-src.tar.gz
[root@node1 src]# make test
You need tcl 8.5 or newer in order to run the Redis test
安裝報錯2
*** [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl
在解壓目錄中修改 tests/integration/replication-psync.tcl,把 after 100 改成 after 500,這個引數貌似是等待的毫秒數
[root@localhost redis-3.2.3]# vim tests/integration/replication-psync.tcl
if (KaTeX parse error: Expected '}', got 'EOF' at end of input: …for {set j 0} {j < KaTeX parse error: Expected 'EOF', got '}' at position 12: duration*10}̲ {incr j} { …master dbsize] keys, SLAVE [$slave dbsize] keys"}

如下過程是部署在一臺機器上
1.準備節點
在/opt/redis-3.0.6在建data,conf,log目錄,分別修改每個redis例項的配置檔案
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
logfile “/opt/redis-3.0.6/log/redis-7000.log”
dbfilename dump7000.rdb
dir /opt/redis-3.0.6/data

./redis-server …/conf/redis-7000.conf &
./redis-server …/conf/redis-7001.conf &
./redis-server …/conf/redis-7002.conf &
./redis-server …/conf/redis-7003.conf &
./redis-server …/conf/redis-7004.conf &
./redis-server …/conf/redis-7005.conf &

2.安裝redis-trib.rb建立叢集
手工建立很複雜,如果節點多,那就更復雜,需要一個工具redis-trib.rb快速搭建。–replicas 1 是指定叢集中每個主節點配置幾個從節點
執行之前需要安裝https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
將gem ruby cp 到/usr/local/bin
安裝rubygem redis依賴:
http://rubygems.org/downloads/redis-3.3.0.gem
gem install -l redis-3.3.0.gem
gem list --check redis gem

建立叢集,最少6個節點,三主三從
redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
如果執行報錯,則需要刪除data目錄下面的資料檔案和node.conf。[ERR] Node 127.0.0.1:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

叢集完整性檢查,只需要給出叢集中任意一個節點的地址就可以完成整個叢集的檢查工作。
redis-trib.rb check 127.0.0.1:7000

叢集擴充套件叢集:
新建兩個節點
./redis-server …/conf/redis-7006.conf &
./redis-server …/conf/redis-7007.conf &
將節點加入到叢集
redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7000
遷移槽和資料
redis-trib.rb reshard 127.0.0.1:7000
檢查節點之間槽的均衡性
redis-trib.rb rebalance 127.0.0.1:7000
新增從節點
redis-cli -c -p 7007
cluster replicate master_id(89844a21fc7fb9cfdcd94f285ac307f3ef1d791f)

相關文章