redisクラスタredisクラスタ:手動と自動
手動で作成:
環境の説明:1台の機械が6つのノードを起動し、3つのメインノード、3つのスレーブノードを起動します.インストール:tar -zxvf redis-3.2.10.tar.gz
mv redis-3.2.10 /usr/local/redis
yum install gcc* tcl -y
make && make test
変更プロファイル:vi /usr/local/redis/redis.conf
** **
daemonize yes
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf . //
cluster-node-timeout 5000
mkdir /usr/local/cluster-test/ // ,
** /usr/local/cluster-test/ **
mkdir 7000
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
サービスの開始:./redis-server /usr/local/cluster-test/7000/redis.conf
./redis-server /usr/local/cluster-test/7001/redis.conf
./redis-server /usr/local/cluster-test/7002/redis.conf
./redis-server /usr/local/cluster-test/7003/redis.conf
./redis-server /usr/local/cluster-test/7004/redis.conf
./redis-server /usr/local/cluster-test/7005/redis.conf
netstat -anput | grep redis
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 7000
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7000
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7001
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7002
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7003
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7004
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7005
127.0.0.1:7000> CLUSTER NODES
127.0.0.1:7000> CLUSTER INFO . //cluter fail
3つのプライマリノードにスロットポイントを割り当てます.redis-cli -h 127.0.0.1 -p 7000 cluster addslots {0..5461}
redis-cli -h 127.0.0.1 -p 7001 cluster addslots {5462..10922}
redis-cli -h 127.0.0.1 -p 7002 cluster addslots {10923..16383}
ノード:[root@localhost src]# ./redis-cli -p 7003
127.0.0.1:7003> CLUSTER REPLICATE
8573 e 44492 c 6 ba 0713 e 36545202459974 cc 18 cf 7 [root@localhost src]# ./redis-cli -p 7004
127.0.0.1:7004> CLUSTER REPLICATE
59 d 75 c 9 a 0 b 599265 d 0 ac 123 cc 99 f 18050 df 5 afa 3 [root@localhost src]# ./redis-cli -p 7005
127.0.0.1:7005> CLUSTER REPLICATE
607 f 5472 bdd 9 f 581 ad 16 b 960424 ee 7 ba 18 fb 5 a 1 f [root@localhost src]# ./redis-cli -p 7000
127.0.0.1:7000> CLUSTER INFO
cluster_state:ok //
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:3
cluster_stats_messages_sent:7306
cluster_stats_messages_received:7306
自動作成:
環境の説明:1台の機械が6つのノードを起動し、3つのメインノード、3つのスレーブノードを起動します.インストール:tar -zxvf redis-3.2.10.tar.gz
mv redis-3.2.10 /usr/local/redis
yum install gcc* tcl -y
make && make test
変更プロファイル:vi /usr/local/redis/redis.conf
daemonize yes
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf . //
cluster-node-timeout 5000
appendonly yes
mkdir /usr/local/cluster-test/ // ,
mkdir 7000
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
サービスの開始:redis-server /usr/local/cluster-test/7000/redis.conf
redis-server /usr/local/cluster-test/7001/redis.conf
redis-server /usr/local/cluster-test/7002/redis.conf
redis-server /usr/local/cluster-test/7003/redis.conf
redis-server /usr/local/cluster-test/7004/redis.conf
redis-server /usr/local/cluster-test/7005/redis.conf
[root@localhost ~]#netstat -anput | grep redis
6個のノードを連結するクラスタを構成するために用いるコマンドがredis-tribである.rb、これは公式のrubyで書かれたredis clusterを操作するコマンドなので、あなたの機械にrubyをインストールする必要があります.まず、このコマンドを試してみましょう.[root@web3 7005]# yum -y install rpm-build openssl openssl-devel
[root@localhost ruby]# tar -zxvf ruby-2.3.1.tar.gz
[root@localhost ruby]#./configure --prefix=/usr/local/ruby
[root@localhost ruby]#make && make install
[root@localhost ruby]#ln -s /usr/local/ruby/bin/* /usr/local/bin/
[root@localhost ~]# ln /usr/local/redis/src/redis-trib.rb /usr/local/bin/
[root@localhost ~]#gem install redis-3.3.0.gem
新しいクラスタを作成するため、ここではcreateコマンドを使用します.--replicas 1パラメータは、プライマリノードごとにスレーブノードを作成することを示す.他のパラメータは、インスタンスのアドレスセットです.[root@localhost src]# 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
Creating clusterConnecting to node 127.0.0.1:7000: OKConnecting to node 127.0.0.1:7001: OKConnecting to node 127.0.0.1:7002: OKConnecting to node 127.0.0.1:7003: OKConnecting to node 127.0.0.1:7004: OKConnecting to node 127.0.0.1:7005: OKPerforming hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002Adding replica 127.0.0.1:7003 to 127.0.0.1:7000Adding replica 127.0.0.1:7004 to 127.0.0.1:7001Adding replica 127.0.0.1:7005 to 127.0.0.1:7002M: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000slots:0-5460 (5461 slots) masterM: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001slots:5461-10922 (5462 slots) masterM: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002slots:10923-16383 (5461 slots) masterS: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003replicates 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6cS: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005replicates dfa0754c7854a874a6ebd2613b86140ad97701fcCan I set the above configuration? (type 'yes' to accept): yesNodes configuration updatedAssign a different config epoch to each nodeSending CLUSTER MEET messages to join the clusterWaiting for the cluster to join...Performing Cluster Check (using node 127.0.0.1:7000)M: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000slots:0-5460 (5461 slots) masterM: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001slots:5461-10922 (5462 slots) masterM: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002slots:10923-16383 (5461 slots) masterM: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003slots: (0 slots) masterreplicates 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4M: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004slots: (0 slots) masterreplicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6cM: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005slots: (0 slots) masterreplicates dfa0754c7854a874a6ebd2613b86140ad97701fc[OK] All nodes agree about slots configuration.Check for open slots...Check slots coverage...[OK] All 16384 slots covered.Redis-tribはどのような構成をしたかを提示し、yesを入力して受け入れます.クラスタは構成され、追加されます.これは、インスタンスが相互に交流して起動することを意味します.テストクラスタの状態:[root@localhost ~]# gem list redis
には、3つのプライマリノード、3つのセカンダリノードが表示されます.各ノードが成功した接続状態である3つのプライマリノード〔M〕Yes:7000(3707 debcbe 7 be 66 d 4 a 1968 eaf 3 a 5 ffaf 4308 efa 4)7001(cb 5 c 04 b 6160 c 3 b 7 e 18 cad 5 d 49 d 8 e 2987 b 27 e 0 d 6 c)7002(dfa0754 c 7854 a 874 a 6 ebd 613 b 8614014097701 fc)3つのスレーノード〔S〕Yes:7003(d 237 fdcfbba 672 de 766 b 913 d 1186 cbcbcb 6 e 1761)b 913 d 1186 cebcbcb 6 e 1761)b 6 b 6 b 6 e 1761)3 3 3 3 3)3 3 3 3 3 3 3->70007004(4 b 4 aef 8 b 48 c 427 a 3 c 903518339 d 53 b 6447 c 58 b 93)->70005(30858 dbf 483 b 61 b 9838 d 5 c 1 f 853 a 60 beaa 4 e 7 afd)->7002テスト接続クラスタはさっきクラスタ構築に成功しました.redis clusterの特徴に従って、それは中心化され、各ノードは対等であるため、どのノードに接続してもデータを取得して設定することができます.試してみましょう.redis-cliはredisのデフォルトのクライアントツールで、起動時に-cパラメータを加えるとクラスタに接続できます.ノードポートの接続:[root@localhost 7000]# redis-trib.rb check 127.0.0.1:7000
127.0.0.1:7000>値の設定:127.0.0.1:7000>set my_name linux-> Redirected to slot [12803] located at 127.0.0.1:7002OK127.0.0.1:7002> get my_name"linux"127.0.0.1:7002>前述の理論知識では、keyを割り当てるときにCRC 16('my_name')%16384アルゴリズムを使用して、このkeyをどのノードに置くかを計算します.ここで12803 slotに割り当てると7002(10923-16383)というノードに割り当てられます.Redirected to slot[122803]located at 127.0.0.1:7002 redis clusterは、自身の7000ノードではなく7002ノードに直接ジャンプする方法を採用しています.7005というスレーブノードを接続します:[root@web3 7000]# redis-cli -c -p 7000
127.0.0.1:7005> get my_name
-> Redirected to slot [12803] located at 127.0.0.1:7002
"linux"
127.0.0.1:7002>
my_name , 7002 。
:
127.0.0.1:7002> set age 123
-> Redirected to slot [741] located at 127.0.0.1:7000
OK
127.0.0.1:7000> set height 565
-> Redirected to slot [8223] located at 127.0.0.1:7001
OK
127.0.0.1:7001> set sex 1
-> Redirected to slot [2584] located at 127.0.0.1:7000
OK
127.0.0.1:7000> set home china
-> Redirected to slot [10814] located at 127.0.0.1:7001
OK
127.0.0.1:7001> set city shanghai
-> Redirected to slot [11479] located at 127.0.0.1:7002
OK
127.0.0.1:7002> set citylocate shanghaipudong
OK
127.0.0.1:7001> set wsdwxzx hhh
-> Redirected to slot [15487] located at 127.0.0.1:7002
OK
127.0.0.1:7002> zadd erew 333 rrr
-> Redirected to slot [10576] located at 127.0.0.1:7001
(integer) 1
127.0.0.1:7000> zrange erew 0 -1
-> Redirected to slot [10576] located at 127.0.0.1:7001
1) "rrr"
127.0.0.1:7001>
128.~~~~
, 7000-7002 3 。
。3 [7000-7002] ,3
[7003-7005] [7000-7002] ,
[7003-7005] appendonly.aof 。 :
`[root@web3 7005]# cd /usr/local/cluster-test/7003`
`[root@web3 7003]# vi appendonly.aof`
*2
$6
SELECT
$1
0
*3
$3
set
$3
age
$3
123
*3
$3
set
$3
sex
$1
1
*3
$3
set
$3
job
$3
php
, 7000 ,7004,7005 。
, Master 。
`[root@web3 7003]# ps -ef|grep redis`
root 11380 1 0 07:37 ? 00:00:03 redis-server *:7000 [cluster]
root 11384 1 0 07:37 ? 00:00:03 redis-server *:7001 [cluster]
root 11388 1 0 07:37 ? 00:00:03 redis-server *:7002 [cluster]
root 11392 1 0 07:37 ? 00:00:03 redis-server *:7003 [cluster]
root 11396 1 0 07:37 ? 00:00:04 redis-server *:7004 [cluster]
root 11400 1 0 07:37 ? 00:00:03 redis-server *:7005 [cluster]
, ,7000 , ,7000 7003 ,
7003 Master :
`[root@web3 7003]# kill 11380`
`[root@web3 7003]# redis-trib.rb check 127.0.0.1:7000`
Connecting to node 127.0.0.1:7000: [ERR] Sorry, can't connect to node
127.0.0.1:7000
`[root@web3 7003]# redis-trib.rb check 127.0.0.1:7001`
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7001)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
, M , ,7003 7000 。
7000 :
`[root@web3 7003]# redis-cli -c -p 7001`
127.0.0.1:7001> get sex
Redirected to slot [2584] located at 127.0.0.1:7003
"1"
127.0.0.1:7003>
, 7003 。
7000 , ? ,7000
? : 7000 :
[root@web3 7003]# cd ../7000
[root@web3 7000]# ll
total 56
-rw-r--r-- 1 root root 114 Oct 17 08:16 appendonly.aof
-rw-r--r-- 1 root root 43 Oct 17 08:37 dump.rdb
-rw-r--r-- 1 root root 745 Oct 17 08:00 nodes.conf
-rw-r--r-- 1 root root 41550 Oct 17 07:37 redis.conf
[root@web3 7000]# redis-server redis.conf
, , :
redis-trib.rb check 127.0.0.1:7001
`[root@web3 7000]# redis-trib.rb check 127.0.0.1:7001`
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7001)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
,7000 , 7003 。
-----
de 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Performing Cluster Check (using node 127.0.0.1:7006)
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots: (0 slots) master
0 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)?
slot 7006 , :16384/4 = 4096, ,
, 4096 7006 。 4096:
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
, node ID ,7006 id
efc3131fbdc6cf929720e0e0f7136cae85657481 :
What is the receiving node ID? efc3131fbdc6cf929720e0e0f7136cae85657481
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:
, redis-trib (source node), ,
4096 , 7006 。
, redis-trib all ,
, , redis-trib
, 4096 , 7006 : Source node #1:all
, :
Moving slot 1359 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1360 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1361 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1362 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1363 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1364 from d2237fdcfbba672de766b913d1186cebcb6e1761
Do you want to proceed with the proposed reshard plan (yes/no)?
yes , redis-trib ,
7006 。
, :
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7000)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
7006: 0-1364,5461-6826,10923-12287 (4096 slots)
slot 7006 。 , , ,
?
[root@web3 7006]# redis-cli -c -p 7006
127.0.0.1:7006> keys *
1) "city"
2) "age"
3) "citylocate"
127.0.0.1:7006> get city
"shanghai"
, 。
7007 , 7006 7007, ,
。 , , :
[root@web3 7007]# redis-trib.rb add-node --slave 127.0.0.1:7007 127.0.0.1:7000
add-node --slave , , 。
,
。 ,redis-trib 7007
。
, , 7006, 7006 。 。
[root@web3 7007]# redis-trib.rb add-node --slave 127.0.0.1:7007 127.0.0.1:7000
...
...
[OK] All 16384 slots covered.
Automatically selected master 127.0.0.1:7006
Connecting to node 127.0.0.1:7007: OK
Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
Waiting for the cluster to join.
Configure node as replica of 127.0.0.1:7006.
[OK] New node added correctly.
, 7006 master 。 。 :
[root@web3 7007]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7000)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: 86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007
slots: (0 slots) slave
replicates efc3131fbdc6cf929720e0e0f7136cae85657481
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
,7007 7006 。
? 。 7008 。
redis-trib.rb add-node --slave --master-id
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7008 127.0.0.1:7000
--master-id node id。 7006 。
Configure node as replica of 127.0.0.1:7006.
[OK] New node added correctly.
7006 , 7006 , ,7006
2 , :
redis-cli -c -p 7008 cluster nodes |grep
efc3131fbdc6cf929720e0e0f7136cae85657481
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 slave
efc3131fbdc6cf929720e0e0f7136cae85657481 0 1445089507786 8 connected
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 master - 0 1445089508289
8 connected 0-1364 5461-6826 10923-12287
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 myself,slave
efc3131fbdc6cf929720e0e0f7136cae85657481 0 0 0 connected
, ,7007 7008 7006 。
, 7006 , 7007 7008 :
[root@web3 7008]# ps -ef|grep redis
root 11384 1 0 09:56 ? 00:00:16 redis-server *:7001 [cluster]
root 11388 1 0 09:56 ? 00:00:16 redis-server *:7002 [cluster]
root 11392 1 0 09:56 ? 00:00:16 redis-server *:7003 [cluster]
root 11396 1 0 09:56 ? 00:00:15 redis-server *:7004 [cluster]
root 11400 1 0 09:56 ? 00:00:15 redis-server *:7005 [cluster]
root 12100 1 0 11:01 ? 00:00:11 redis-server *:7000 [cluster]
root 12132 1 0 11:28 ? 00:00:11 redis-server *:7006 [cluster]
root 12202 1 0 13:14 ? 00:00:02 redis-server *:7007 [cluster]
root 12219 1 0 13:39 ? 00:00:00 redis-server *:7008 [cluster]
root 12239 8259 0 13:49 pts/0 00:00:00 grep redis
[root@web3 7008]# kill 12132
[root@web3 7008]# redis-cli -c -p 7008
127.0.0.1:7008> get ss5rtr
Redirected to slot [1188] located at 127.0.0.1:7007
"66"
127.0.0.1:7007> cluster nodes
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 master,fail -
1445089780668 1445089779963 8 disconnected
d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003 master - 0 1445089812195
7 connected 1365-5460
30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005 slave
dfa0754c7854a874a6ebd2613b86140ad97701fc 0 1445089813710 3 connected
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 myself,master - 0 0 10
connected 0-1364 5461-6826 10923-12287
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001 master - 0 1445089814214
2 connected 6827-10922
4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004 slave
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 0 1445089812701 2 connected
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 1445089814214 10 connected
3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000 slave
d2237fdcfbba672de766b913d1186cebcb6e1761 0 1445089813204 7 connected
dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002 master - 0 1445089813204
3 connected 12288-16383
127.0.0.1:7007>
7007 ,7008 7007 。 , 7006
, 7007 。
127.0.0.1:7008> cluster nodes
30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005 slave
dfa0754c7854a874a6ebd2613b86140ad97701fc 0 1445089986148 3 connected
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 master - 0
1445089986652 10 connected 0-1364 5461-6826 10923-12287
d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003 master - 0
1445089986148 7 connected 1365-5460
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001 master - 0
1445089987155 2 connected 6827-10922
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 1445089985644 10 connected
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 myself,slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 0 0 connected
dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002 master - 0
1445089986652 3 connected 12288-16383
4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004 slave
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 0 1445089987660 2 connected
3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000 slave
d2237fdcfbba672de766b913d1186cebcb6e1761 0 1445089985644 7 connected
127.0.0.1:7008>
,redis cluster , redistrib.rb :
redis-trib del-node 127.0.0.1:7000 ``
, node-id。 7007
:
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7000
86d05e7c2b197dc182b5e71069e791d033cf899e
Removing node 86d05e7c2b197dc182b5e71069e791d033cf899e from cluster
127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7002: OK
[ERR] Node 127.0.0.1:7007 is not empty! Reshard data away and try again.
, , 7007 , ,
。 , , :
redis-trib.rb reshard 127.0.0.1:7000
, , :
M: 86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
How many slots do you want to move (from 1 to 16384)?
, , 7007 4096 , 4096
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
, id , 7001 :
What is the receiving node ID? cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:
, 7001, 7007 ,
, 7007 id
Source node #1:86d05e7c2b197dc182b5e71069e791d033cf899e
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
ok, 。 7007 :
[root@web3 7006]# redis-cli -c -p 7007
127.0.0.1:7007> keys *
(empty list or set)
127.0.0.1:7007> cluster nodes
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 myself,master - 0 0 10
connected
, 。 :
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7000
86d05e7c2b197dc182b5e71069e791d033cf899e
Removing node 86d05e7c2b197dc182b5e71069e791d033cf899e from cluster
127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7002: OK
Sending CLUSTER FORGET messages to the cluster...
127.0.0.1:7006 as replica of 127.0.0.1:7001
127.0.0.1:7008 as replica of 127.0.0.1:7001
SHUTDOWN the node.
。
:7007 , 。
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7007
Connecting to node 127.0.0.1:7007: [ERR] Sorry, can't connect to node
127.0.0.1:7007
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7008
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7000: OK
>>> Performing Cluster Check (using node 127.0.0.1:7008)
S: 44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:0-1364,5461-12287 (8192 slots) master
3 additional replica(s)
S: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
7006 7008 7001 。
, , 7008
:
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7008
44321e7d619410dc4e0a8745366610a0d06d2395
Removing node 44321e7d619410dc4e0a8745366610a0d06d2395 from cluster
127.0.0.1:7005
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7003: OK
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7008
Connecting to node 127.0.0.1:7008: [ERR] Sorry, can't connect to node
127.0.0.1:7008
。
** **
daemonize yes
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf . //
cluster-node-timeout 5000
** /usr/local/cluster-test/ **
mkdir 7000
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
./redis-server /usr/local/cluster-test/7000/redis.conf
./redis-server /usr/local/cluster-test/7001/redis.conf
./redis-server /usr/local/cluster-test/7002/redis.conf
./redis-server /usr/local/cluster-test/7003/redis.conf
./redis-server /usr/local/cluster-test/7004/redis.conf
./redis-server /usr/local/cluster-test/7005/redis.conf
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7000
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7001
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7002
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7003
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7004
127.0.0.1:7000> CLUSTER MEET 127.0.0.1 7005
127.0.0.1:7000> CLUSTER NODES
127.0.0.1:7000> CLUSTER INFO . //cluter fail
redis-cli -h 127.0.0.1 -p 7000 cluster addslots {0..5461}
redis-cli -h 127.0.0.1 -p 7001 cluster addslots {5462..10922}
redis-cli -h 127.0.0.1 -p 7002 cluster addslots {10923..16383}
cluster_state:ok //
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:3
cluster_stats_messages_sent:7306
cluster_stats_messages_received:7306
環境の説明:1台の機械が6つのノードを起動し、3つのメインノード、3つのスレーブノードを起動します.インストール:
tar -zxvf redis-3.2.10.tar.gz
mv redis-3.2.10 /usr/local/redis
yum install gcc* tcl -y
make && make test
変更プロファイル:vi /usr/local/redis/redis.conf
daemonize yes
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf . //
cluster-node-timeout 5000
appendonly yes
mkdir /usr/local/cluster-test/ // ,
mkdir 7000
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
サービスの開始:
redis-server /usr/local/cluster-test/7000/redis.conf
redis-server /usr/local/cluster-test/7001/redis.conf
redis-server /usr/local/cluster-test/7002/redis.conf
redis-server /usr/local/cluster-test/7003/redis.conf
redis-server /usr/local/cluster-test/7004/redis.conf
redis-server /usr/local/cluster-test/7005/redis.conf
[root@localhost ~]#netstat -anput | grep redis
6個のノードを連結するクラスタを構成するために用いるコマンドがredis-tribである.rb、これは公式のrubyで書かれたredis clusterを操作するコマンドなので、あなたの機械にrubyをインストールする必要があります.まず、このコマンドを試してみましょう.[root@web3 7005]# yum -y install rpm-build openssl openssl-devel
[root@localhost ruby]# tar -zxvf ruby-2.3.1.tar.gz
[root@localhost ruby]#./configure --prefix=/usr/local/ruby
[root@localhost ruby]#make && make install
[root@localhost ruby]#ln -s /usr/local/ruby/bin/* /usr/local/bin/
[root@localhost ~]# ln /usr/local/redis/src/redis-trib.rb /usr/local/bin/
[root@localhost ~]#gem install redis-3.3.0.gem
新しいクラスタを作成するため、ここではcreateコマンドを使用します.--replicas 1パラメータは、プライマリノードごとにスレーブノードを作成することを示す.他のパラメータは、インスタンスのアドレスセットです.[root@localhost src]# 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
Creating clusterConnecting to node 127.0.0.1:7000: OKConnecting to node 127.0.0.1:7001: OKConnecting to node 127.0.0.1:7002: OKConnecting to node 127.0.0.1:7003: OKConnecting to node 127.0.0.1:7004: OKConnecting to node 127.0.0.1:7005: OKPerforming hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002Adding replica 127.0.0.1:7003 to 127.0.0.1:7000Adding replica 127.0.0.1:7004 to 127.0.0.1:7001Adding replica 127.0.0.1:7005 to 127.0.0.1:7002M: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000slots:0-5460 (5461 slots) masterM: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001slots:5461-10922 (5462 slots) masterM: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002slots:10923-16383 (5461 slots) masterS: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003replicates 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6cS: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005replicates dfa0754c7854a874a6ebd2613b86140ad97701fcCan I set the above configuration? (type 'yes' to accept): yesNodes configuration updatedAssign a different config epoch to each nodeSending CLUSTER MEET messages to join the clusterWaiting for the cluster to join...Performing Cluster Check (using node 127.0.0.1:7000)M: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000slots:0-5460 (5461 slots) masterM: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001slots:5461-10922 (5462 slots) masterM: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002slots:10923-16383 (5461 slots) masterM: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003slots: (0 slots) masterreplicates 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4M: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004slots: (0 slots) masterreplicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6cM: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005slots: (0 slots) masterreplicates dfa0754c7854a874a6ebd2613b86140ad97701fc[OK] All nodes agree about slots configuration.Check for open slots...Check slots coverage...[OK] All 16384 slots covered.Redis-tribはどのような構成をしたかを提示し、yesを入力して受け入れます.クラスタは構成され、追加されます.これは、インスタンスが相互に交流して起動することを意味します.テストクラスタの状態:
[root@localhost ~]# gem list redis
には、3つのプライマリノード、3つのセカンダリノードが表示されます.各ノードが成功した接続状態である3つのプライマリノード〔M〕Yes:7000(3707 debcbe 7 be 66 d 4 a 1968 eaf 3 a 5 ffaf 4308 efa 4)7001(cb 5 c 04 b 6160 c 3 b 7 e 18 cad 5 d 49 d 8 e 2987 b 27 e 0 d 6 c)7002(dfa0754 c 7854 a 874 a 6 ebd 613 b 8614014097701 fc)3つのスレーノード〔S〕Yes:7003(d 237 fdcfbba 672 de 766 b 913 d 1186 cbcbcb 6 e 1761)b 913 d 1186 cebcbcb 6 e 1761)b 6 b 6 b 6 e 1761)3 3 3 3 3)3 3 3 3 3 3 3->70007004(4 b 4 aef 8 b 48 c 427 a 3 c 903518339 d 53 b 6447 c 58 b 93)->70005(30858 dbf 483 b 61 b 9838 d 5 c 1 f 853 a 60 beaa 4 e 7 afd)->7002テスト接続クラスタはさっきクラスタ構築に成功しました.redis clusterの特徴に従って、それは中心化され、各ノードは対等であるため、どのノードに接続してもデータを取得して設定することができます.試してみましょう.redis-cliはredisのデフォルトのクライアントツールで、起動時に-cパラメータを加えるとクラスタに接続できます.ノードポートの接続:[root@localhost 7000]# redis-trib.rb check 127.0.0.1:7000
127.0.0.1:7000>値の設定:127.0.0.1:7000>set my_name linux-> Redirected to slot [12803] located at 127.0.0.1:7002OK127.0.0.1:7002> get my_name"linux"127.0.0.1:7002>前述の理論知識では、keyを割り当てるときにCRC 16('my_name')%16384アルゴリズムを使用して、このkeyをどのノードに置くかを計算します.ここで12803 slotに割り当てると7002(10923-16383)というノードに割り当てられます.Redirected to slot[122803]located at 127.0.0.1:7002 redis clusterは、自身の7000ノードではなく7002ノードに直接ジャンプする方法を採用しています.7005というスレーブノードを接続します:[root@web3 7000]# redis-cli -c -p 7000
127.0.0.1:7005> get my_name
-> Redirected to slot [12803] located at 127.0.0.1:7002
"linux"
127.0.0.1:7002>
my_name , 7002 。
:
127.0.0.1:7002> set age 123
-> Redirected to slot [741] located at 127.0.0.1:7000
OK
127.0.0.1:7000> set height 565
-> Redirected to slot [8223] located at 127.0.0.1:7001
OK
127.0.0.1:7001> set sex 1
-> Redirected to slot [2584] located at 127.0.0.1:7000
OK
127.0.0.1:7000> set home china
-> Redirected to slot [10814] located at 127.0.0.1:7001
OK
127.0.0.1:7001> set city shanghai
-> Redirected to slot [11479] located at 127.0.0.1:7002
OK
127.0.0.1:7002> set citylocate shanghaipudong
OK
127.0.0.1:7001> set wsdwxzx hhh
-> Redirected to slot [15487] located at 127.0.0.1:7002
OK
127.0.0.1:7002> zadd erew 333 rrr
-> Redirected to slot [10576] located at 127.0.0.1:7001
(integer) 1
127.0.0.1:7000> zrange erew 0 -1
-> Redirected to slot [10576] located at 127.0.0.1:7001
1) "rrr"
127.0.0.1:7001>
128.~~~~
, 7000-7002 3 。
。3 [7000-7002] ,3
[7003-7005] [7000-7002] ,
[7003-7005] appendonly.aof 。 :
`[root@web3 7005]# cd /usr/local/cluster-test/7003`
`[root@web3 7003]# vi appendonly.aof`
*2
$6
SELECT
$1
0
*3
$3
set
$3
age
$3
123
*3
$3
set
$3
sex
$1
1
*3
$3
set
$3
job
$3
php
, 7000 ,7004,7005 。
, Master 。
`[root@web3 7003]# ps -ef|grep redis`
root 11380 1 0 07:37 ? 00:00:03 redis-server *:7000 [cluster]
root 11384 1 0 07:37 ? 00:00:03 redis-server *:7001 [cluster]
root 11388 1 0 07:37 ? 00:00:03 redis-server *:7002 [cluster]
root 11392 1 0 07:37 ? 00:00:03 redis-server *:7003 [cluster]
root 11396 1 0 07:37 ? 00:00:04 redis-server *:7004 [cluster]
root 11400 1 0 07:37 ? 00:00:03 redis-server *:7005 [cluster]
, ,7000 , ,7000 7003 ,
7003 Master :
`[root@web3 7003]# kill 11380`
`[root@web3 7003]# redis-trib.rb check 127.0.0.1:7000`
Connecting to node 127.0.0.1:7000: [ERR] Sorry, can't connect to node
127.0.0.1:7000
`[root@web3 7003]# redis-trib.rb check 127.0.0.1:7001`
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7001)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
, M , ,7003 7000 。
7000 :
`[root@web3 7003]# redis-cli -c -p 7001`
127.0.0.1:7001> get sex
Redirected to slot [2584] located at 127.0.0.1:7003
"1"
127.0.0.1:7003>
, 7003 。
7000 , ? ,7000
? : 7000 :
[root@web3 7003]# cd ../7000
[root@web3 7000]# ll
total 56
-rw-r--r-- 1 root root 114 Oct 17 08:16 appendonly.aof
-rw-r--r-- 1 root root 43 Oct 17 08:37 dump.rdb
-rw-r--r-- 1 root root 745 Oct 17 08:00 nodes.conf
-rw-r--r-- 1 root root 41550 Oct 17 07:37 redis.conf
[root@web3 7000]# redis-server redis.conf
, , :
redis-trib.rb check 127.0.0.1:7001
`[root@web3 7000]# redis-trib.rb check 127.0.0.1:7001`
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7001)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
,7000 , 7003 。
-----
de 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Performing Cluster Check (using node 127.0.0.1:7006)
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots: (0 slots) master
0 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)?
slot 7006 , :16384/4 = 4096, ,
, 4096 7006 。 4096:
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
, node ID ,7006 id
efc3131fbdc6cf929720e0e0f7136cae85657481 :
What is the receiving node ID? efc3131fbdc6cf929720e0e0f7136cae85657481
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:
, redis-trib (source node), ,
4096 , 7006 。
, redis-trib all ,
, , redis-trib
, 4096 , 7006 : Source node #1:all
, :
Moving slot 1359 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1360 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1361 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1362 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1363 from d2237fdcfbba672de766b913d1186cebcb6e1761
Moving slot 1364 from d2237fdcfbba672de766b913d1186cebcb6e1761
Do you want to proceed with the proposed reshard plan (yes/no)?
yes , redis-trib ,
7006 。
, :
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7000)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
7006: 0-1364,5461-6826,10923-12287 (4096 slots)
slot 7006 。 , , ,
?
[root@web3 7006]# redis-cli -c -p 7006
127.0.0.1:7006> keys *
1) "city"
2) "age"
3) "citylocate"
127.0.0.1:7006> get city
"shanghai"
, 。
7007 , 7006 7007, ,
。 , , :
[root@web3 7007]# redis-trib.rb add-node --slave 127.0.0.1:7007 127.0.0.1:7000
add-node --slave , , 。
,
。 ,redis-trib 7007
。
, , 7006, 7006 。 。
[root@web3 7007]# redis-trib.rb add-node --slave 127.0.0.1:7007 127.0.0.1:7000
...
...
[OK] All 16384 slots covered.
Automatically selected master 127.0.0.1:7006
Connecting to node 127.0.0.1:7007: OK
Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
Waiting for the cluster to join.
Configure node as replica of 127.0.0.1:7006.
[OK] New node added correctly.
, 7006 master 。 。 :
[root@web3 7007]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7002: OK
Performing Cluster Check (using node 127.0.0.1:7000)
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
M: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: 86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007
slots: (0 slots) slave
replicates efc3131fbdc6cf929720e0e0f7136cae85657481
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
,7007 7006 。
? 。 7008 。
redis-trib.rb add-node --slave --master-id
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7008 127.0.0.1:7000
--master-id node id。 7006 。
Configure node as replica of 127.0.0.1:7006.
[OK] New node added correctly.
7006 , 7006 , ,7006
2 , :
redis-cli -c -p 7008 cluster nodes |grep
efc3131fbdc6cf929720e0e0f7136cae85657481
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 slave
efc3131fbdc6cf929720e0e0f7136cae85657481 0 1445089507786 8 connected
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 master - 0 1445089508289
8 connected 0-1364 5461-6826 10923-12287
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 myself,slave
efc3131fbdc6cf929720e0e0f7136cae85657481 0 0 0 connected
, ,7007 7008 7006 。
, 7006 , 7007 7008 :
[root@web3 7008]# ps -ef|grep redis
root 11384 1 0 09:56 ? 00:00:16 redis-server *:7001 [cluster]
root 11388 1 0 09:56 ? 00:00:16 redis-server *:7002 [cluster]
root 11392 1 0 09:56 ? 00:00:16 redis-server *:7003 [cluster]
root 11396 1 0 09:56 ? 00:00:15 redis-server *:7004 [cluster]
root 11400 1 0 09:56 ? 00:00:15 redis-server *:7005 [cluster]
root 12100 1 0 11:01 ? 00:00:11 redis-server *:7000 [cluster]
root 12132 1 0 11:28 ? 00:00:11 redis-server *:7006 [cluster]
root 12202 1 0 13:14 ? 00:00:02 redis-server *:7007 [cluster]
root 12219 1 0 13:39 ? 00:00:00 redis-server *:7008 [cluster]
root 12239 8259 0 13:49 pts/0 00:00:00 grep redis
[root@web3 7008]# kill 12132
[root@web3 7008]# redis-cli -c -p 7008
127.0.0.1:7008> get ss5rtr
Redirected to slot [1188] located at 127.0.0.1:7007
"66"
127.0.0.1:7007> cluster nodes
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 master,fail -
1445089780668 1445089779963 8 disconnected
d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003 master - 0 1445089812195
7 connected 1365-5460
30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005 slave
dfa0754c7854a874a6ebd2613b86140ad97701fc 0 1445089813710 3 connected
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 myself,master - 0 0 10
connected 0-1364 5461-6826 10923-12287
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001 master - 0 1445089814214
2 connected 6827-10922
4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004 slave
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 0 1445089812701 2 connected
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 1445089814214 10 connected
3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000 slave
d2237fdcfbba672de766b913d1186cebcb6e1761 0 1445089813204 7 connected
dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002 master - 0 1445089813204
3 connected 12288-16383
127.0.0.1:7007>
7007 ,7008 7007 。 , 7006
, 7007 。
127.0.0.1:7008> cluster nodes
30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005 slave
dfa0754c7854a874a6ebd2613b86140ad97701fc 0 1445089986148 3 connected
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 master - 0
1445089986652 10 connected 0-1364 5461-6826 10923-12287
d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003 master - 0
1445089986148 7 connected 1365-5460
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001 master - 0
1445089987155 2 connected 6827-10922
efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006 slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 1445089985644 10 connected
44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008 myself,slave
86d05e7c2b197dc182b5e71069e791d033cf899e 0 0 0 connected
dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002 master - 0
1445089986652 3 connected 12288-16383
4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004 slave
cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 0 1445089987660 2 connected
3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000 slave
d2237fdcfbba672de766b913d1186cebcb6e1761 0 1445089985644 7 connected
127.0.0.1:7008>
,redis cluster , redistrib.rb :
redis-trib del-node 127.0.0.1:7000 ``
, node-id。 7007
:
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7000
86d05e7c2b197dc182b5e71069e791d033cf899e
Removing node 86d05e7c2b197dc182b5e71069e791d033cf899e from cluster
127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7002: OK
[ERR] Node 127.0.0.1:7007 is not empty! Reshard data away and try again.
, , 7007 , ,
。 , , :
redis-trib.rb reshard 127.0.0.1:7000
, , :
M: 86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
How many slots do you want to move (from 1 to 16384)?
, , 7007 4096 , 4096
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
, id , 7001 :
What is the receiving node ID? cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:
, 7001, 7007 ,
, 7007 id
Source node #1:86d05e7c2b197dc182b5e71069e791d033cf899e
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
ok, 。 7007 :
[root@web3 7006]# redis-cli -c -p 7007
127.0.0.1:7007> keys *
(empty list or set)
127.0.0.1:7007> cluster nodes
86d05e7c2b197dc182b5e71069e791d033cf899e 127.0.0.1:7007 myself,master - 0 0 10
connected
, 。 :
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7000
86d05e7c2b197dc182b5e71069e791d033cf899e
Removing node 86d05e7c2b197dc182b5e71069e791d033cf899e from cluster
127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7002: OK
Sending CLUSTER FORGET messages to the cluster...
127.0.0.1:7006 as replica of 127.0.0.1:7001
127.0.0.1:7008 as replica of 127.0.0.1:7001
SHUTDOWN the node.
。
:7007 , 。
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7007
Connecting to node 127.0.0.1:7007: [ERR] Sorry, can't connect to node
127.0.0.1:7007
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7008
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7000: OK
>>> Performing Cluster Check (using node 127.0.0.1:7008)
S: 44321e7d619410dc4e0a8745366610a0d06d2395 127.0.0.1:7008
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 30858dbf483b61b9838d5c1f853a60beaa4e7afd 127.0.0.1:7005
slots: (0 slots) slave
replicates dfa0754c7854a874a6ebd2613b86140ad97701fc
M: d2237fdcfbba672de766b913d1186cebcb6e1761 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c 127.0.0.1:7001
slots:0-1364,5461-12287 (8192 slots) master
3 additional replica(s)
S: efc3131fbdc6cf929720e0e0f7136cae85657481 127.0.0.1:7006
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
M: dfa0754c7854a874a6ebd2613b86140ad97701fc 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 4b4aef8b48c427a3c903518339d53b6447c58b93 127.0.0.1:7004
slots: (0 slots) slave
replicates cb5c04b6160c3b7e18cad5d49d8e2987b27e0d6c
S: 3707debcbe7be66d4a1968eaf3a5ffaf4308efa4 127.0.0.1:7000
slots: (0 slots) slave
replicates d2237fdcfbba672de766b913d1186cebcb6e1761
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
7006 7008 7001 。
, , 7008
:
[root@web3 7006]# redis-trib.rb del-node 127.0.0.1:7008
44321e7d619410dc4e0a8745366610a0d06d2395
Removing node 44321e7d619410dc4e0a8745366610a0d06d2395 from cluster
127.0.0.1:7005
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7003: OK
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@web3 7006]# redis-trib.rb check 127.0.0.1:7008
Connecting to node 127.0.0.1:7008: [ERR] Sorry, can't connect to node
127.0.0.1:7008
。