0

I've just set up a Redis cluster, which is working fine. The structure is the following:

Server 1 | Server 2 | Server 3
Master A | Master B | Master C
Slave  B | Slave  C | Slave A

Master A <-> Slave A
Master B <-> Slave B
Master C <-> Slave C

I'm wondering what's best practice to add a whole new server to this cluster.

Server 4
Master ?
Slave  ?

Of course, I can add new nodes via ./redis-trib.rb add-node. Is there a generic way?

Tobias Lorenz
  • 1,426
  • 11
  • 17

1 Answers1

1

You can use the CLUSTER MEET command to add a new node into a cluster. This command forces two nodes take each other as a trusted node, and the newly added node will be introduced to other nodes in the cluster by the gossip protocol.

The newly added node will be an empty master. In order to turn it into a slave of another master node. You can use the CLUSTER REPLICATE command.

In your case, you can do the following steps:

  1. Log in SLAVE-D
  2. Join SLAVE-D into the cluster by sending the MEET command: CLUSTER MEET MASTER-A-IP MATER-A-PORT.
  3. Join MASTER-D into the cluster by sending the MEET command: CLUSTER MEET MASTER-D-IP MATER-D-PORT
  4. Make SLAVE-D a slave of MASTER-D by sending the REPLICATE command: CLUSTER REPLICATE MASTER-D-node-id
for_stack
  • 21,012
  • 4
  • 35
  • 48
  • Thanks @for_stack. But shouldn't every master have at least one slave on another server? I know there's some logic for orphaned masters, so shouldn't it be better to assign the SLAVE-D to e.g. MASTER-A and let the replication logic do it's work? – Tobias Lorenz Feb 27 '18 at 07:47
  • OK, I some what misunderstand your question. If you want to ensure that each master's slave locates on another server, just randomly pick a slave between SLAVE-A, SLAVE-B and SLAVE-C, say, SLAVE-A, and use the **REPLICATE** command to make it a slave of MASTER-D. Then make SLAVE-D a slave of MASTER-A. – for_stack Feb 27 '18 at 09:38
  • Redis doesn't give you any command to ensure that master and slave are located on different machines. Since it has no idea whether two nodes are located on the same machine, especially when you deploy Redis with Docker. You have to do it manually. Even with redis-trib.rb, you have to specify the master node id of a newly added slave node. Otherwise, it will make it a slave of a master with least slaves. – for_stack Feb 27 '18 at 09:43