Adding Nodes to the Redis Cluster
For a node to be added as a replica of a master running as part of a cluster, the replica must be configured to run as part of the cluster too by configuring the following parameters in the redis.conf file:
cluster-enabled yes
bind: 0.0.0.0
cluster-config-file nodes.conf
Adding New Node as Replica
Adding a new node to the Redis cluster as a replica is fairly easy. If the future you decide to add a new node to an existing cluster as a replica of a specific master, you can do it using the redis-trib.rb ruby script. On the master node, run the following ruby script:
./redis-trib.rb add-node --slave new_nodes_ip:6379 master_node_ip:6379
Where new_nodes_ip is the ip of the replica you want to add, and master_node is the ip of the master node already running and part of a cluster. In the command above, we assume that the nodes are all running on default redis port of 6379, otherwise use appropriate ports according to your redis configuration file.
Adding Old Node as Replica
By old node, i mean a node that was part of the cluster before. For example, if a master node crashes and replaced by its slave during a fail over. The new promoted master might now have a slave now since the crashed old master is broken and need to be fixed (troubleshoot the problem and fix) before it can be added back to the cluster. This old master is an example of an old node we are talking about here in this section.
So to add an old node, which is known about by the cluster config, we can simply just run the command below on the master you want to replicate.. Just make sure that replica to be added is up and running:
redis-cli cluster nodes | grep myself
Copy the Unique ID, which would look something like this: 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e ...basically a bunch of letters and numbers.
Next, fire up the redis client command line too on the old node you want to add as a replica:
redis-cli
Finally, add the old node a replica of the desired master with Unique ID we copied from above command:
redis old_node_ip:6379> cluster replicate 6ch24c74aae0b56170ccb03a76b60cfe7dc1hgh
Thats it. All the other nodes in the cluster will automatically know about the new slave.
NOTE - Actually, a former cluster node which failed, when is finally back up and running again, will automatically be detected by the cluster and allowed to rejoin the cluster automatically. So the step just demonstrated above might not even be necessary if you are a person with patience. Only use this step above if for some weird reason the the old slave fails to join the cluster back.
Removing a Slave Node
To remove a slave node just use the del-node command of redis-trib:
./redis-trib del-node cluster_node_ip:6379 '<node-id>'
The first argument is just a random node in the cluster, the second argument is the ID of the node you want to remove [1]. The node id is the Unique ID e.g 6ch24c74aae0b56170ccb03a76b60cfe7dc1hgh
REFERENCES
[1] http://redis.io/topics/cluster-tutorial
No comments:
Post a Comment