e7lT2P
e7lT2P

Reputation: 1931

How to start certain number of nodes in Redis cluster

To create and start a cluster in Redis, I use create-cluster.sh file inside

/redis-3.04/utils/create-cluster

With the use of this I can create as many nodes I want by changing the:

Settings

PORT=30000 
TIMEOUT=2000 
NODES=10 
REPLICAS=1.

I wonder if I can create for example 10 nodes (5 masters with 5 slaves) in the beginning but start only 4 masters and 4 slaves (meet and join).

Thanks in advance.

Upvotes: 0

Views: 867

Answers (1)

Sohi
Sohi

Reputation: 424

Yes. You can add more nodes if load increase on your existing cluster .

Basic Steps are :

  1. Start new redis instances - Let's say you want to add 2 more master and there slaves (Total 4 redis instances)

  2. Then using redis-trib utility do following :

    redis-trib.rb add-node <new master node:port> <any existing master> e.g. ./redis-trib.rb add-node 192.168.1.16:7000 192.168.1.15:7000

  3. After this new node will be assigned an id . Note that id and run following command to add slave to node that we added in prev step

    /redis-trib.rb add-node --slave --master-id <master-node-id> <new-node> <master-node> ./redis-trib.rb add-node --slave --master-id 6f9db976c3792e06f9cd252aec7cf262037bea4a 192.168.1.17:7000 192.168.1.16:7000 where 6f9db976c3792e06f9cd252aec7cf262037bea4a is id of 192.168.1.16:7000.

  4. Using similar steps you can add 1 more master-slave pair .

  5. Since these node do not contains any slots to serve, you have move some of the slots from existing masters to new masters .( Re-Sharding)

  6. To that you can run following command/Resharding steps :

    6.1 ./redis-trib.rb reshard <any-master-ip>:<master-port>

    6.2 It will ask : How many slots do you want to move (from 1 to 16384)? => Enter number of slots you want to move

    6.3 Then it will ask : What is the receiving node ID?

    6.4 Enter node id to which slots need to be moved . (new masters)

    6.5 It will prompt : 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: (enter source node id or all)

    6.6 Then it will prompt info saying Moving slot n to node node-id like

    Moving slot 10960 from 37d10f18f349a6a5682c791bff90e0188ae35e49 Moving slot 10961 from 37d10f18f349a6a5682c791bff90e0188ae35e49 Moving slot 10962 from 37d10f18f349a6a5682c791bff90e0188ae35e49

    6.7 It will ask : Do you want to proceed with the proposed reshard plan (yes/no)? Type Yes and enter and you are done .

Note : If data is large it might take some time to reshard.

Few Commands :

  1. To know all nodes in cluster and cluster nodes with node ids:

    redis-cli -h node-ip -p node-port cluster nodes

    e.g. redis-cli -h 127.0.0.1 -p 7000 cluster nodes

  2. To know all slots in cluster :

    redis-cli -h 127.0.0.1 -p 7000 cluster slots

Ref : https://redis.io/commands/cluster-nodes

Hope this will help .

Upvotes: 1

Related Questions