1. 程式人生 > >Redis集群中刪除/修改節點(master、slave)(實驗)

Redis集群中刪除/修改節點(master、slave)(實驗)

redis集群刪除節點 redis集群移除master節點 redis集群移除slave節點 redis集群更改slave節點的隸屬

刪除一個slave節點:

# redis-trib.rb del-node 192.168.2.202:6380 e4dc23dc67418bf66c6c63655110612cb9516aff

// del-node host:port node-id

>>> Removing node e4dc23dc67418bf66c6c63655110612cb9516aff from cluster 192.168.2.202:6380

>>> Sending CLUSTER FORGET messages to the cluster...

>>> SHUTDOWN the node.

查看集群節點信息:

# redis-trib.rb check 192.168.2.100:6379 (確認slave節點已經刪除)

>>> Performing Cluster Check (using node 192.168.2.100:6379)

M: 098e7eb756b6047fde988ab3c0b7189e1724ecf5 192.168.2.100:6379

slots:333-5460 (5128 slots) master

1 additional replica(s)

S: 7119dec91b086ca8fe69f7878fa42b1accd75f0f 192.168.2.100:6380

slots: (0 slots) slave

replicates 5844b4272c39456b0fdf73e384ff8c479547de47


刪除一個master節點

先移除master身上的hash slot,再刪除master。

目前不能直接刪除slot,要把刪除的master的slot遷移到其他master節點上。

# redis-trib.rb reshard 192.168.2.100:6379 //slot遷移到2.100上

How many slots do you want to move (from 1 to 16384)? 1000

//遷移多少個slot?(要刪除的master節點上有多少個slot)

What is the receiving node ID? 098e7eb756b6047fde988ab3c0b7189e1724ecf5

//遷移到那個節點上,ID是多少?(slot遷移給誰,寫誰的ID)

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:8326ff0be199fa0d4db74f0ebcc58f27e65991b4

//被刪除的master的ID

Source node #2:done //表示結束

... ...

Do you want to proceed with the proposed reshard plan (yes/no)? yes

//是否滿意hash slot移動計劃?


把要刪除的master移除集群:

# redis-trib.rb del-node 192.168.2.100:6379 8326ff0be199fa0d4db74f0ebcc58f27e65991b4

//集群中任意節點的IP:端口、要刪除的master的ID

更改slave節點隸屬的master:


當前配置中,192.168.2.100:6380隸屬於192.168.2.200:6379

將192.168.2.100:6380的隸屬更改為192.168.2.100:6379

1、登錄方式指定要更改隸屬關系的IP、端口

2、更改隸屬關系時,直接指定新的master節點的ID

# redis-cli -c -h 192.168.2.100 -p 6380

> cluster nodes

5844b4272c39456b0fdf73e384ff8c479547de47 192.168.2.200:6379 master - 0 1527165062499 3 connected 5795-10922

2faf68564a70372cfc06c1afff197019cc6a39f3 192.168.2.201:6380 slave 3ff3a74f9dc41f8bc635ab845ad76bf77ffb0f69 0 1527165063511 6 connected

098e7eb756b6047fde988ab3c0b7189e1724ecf5 192.168.2.100:6379 master - 0 1527165060482 10 connected 0-5794 10923-11255

227f51028bbe827f27b4e40ed7a08fcc7d8df969 192.168.2.200:6380 slave 098e7eb756b6047fde988ab3c0b7189e1724ecf5 0 1527165059474 10 connected

7119dec91b086ca8fe69f7878fa42b1accd75f0f 192.168.2.100:6380 myself,slave 5844b4272c39456b0fdf73e384ff8c479547de47 0 0 2 connected

3ff3a74f9dc41f8bc635ab845ad76bf77ffb0f69 192.168.2.201:6379 master - 0 1527165058465 5 connected 11256-16383

192.168.2.100:6380>

192.168.2.100:6380> cluster replicate 098e7eb756b6047fde988ab3c0b7189e1724ecf5

OK


Redis集群中刪除/修改節點(master、slave)(實驗)