Redis - Promoting a slave to master manually
Is it possible doing this without restarting the redis service? (and losing all the cached data)
yes that's possible, you can useSLAVEOF NO ONE
(without sentinel)
But it is recommended to use sentinel to avoid data loss.sentinel failover master-name
(with sentinel)
This will force the sentinel to switch master.
The new master will have all the data that was synchronized before the old-master shutdown.
Redis will automatically choose the best slave with max. data, that will reduce the amount of data we lose when switching master.
Below 2 options in step 3 have helped me to recover the cluster once a master node is down, compute was replaced or other not recoverable state.
- 1 .- First you need to connect to the slave node, use redis-cli, here a link how to do that: How to connect to remote Redis server?
- 2 .- Once connected to the slave node run the command
cluster nodes
to validate master node is infail state
, also runcluster info
to see the overall state of your cluster(this is always a good idea) - 3 .- Inside the slave node to be promoted run command:
cluster failover
, in rare cases when there is some serious issues with redis this command could fail, and you will need to usecluster failover force
orcluster failover takeover
, here more info abut the implications of those options: https://redis.io/commands/cluster-failover - 4 .- Run
cluster forged $old_master_id
in all your cluster nodes - 5 .- Add a new node with
cluster meet $new_node_IP $new_node_PORT
- 6 .- Subscribe your new node to your brand new master, login in to the new bode and run
cluster replicate $master_node_id
Steps 1-3 are required for the slave-master promotion and 4-5 are required to left all cluster in a healthy master-slave equilibrium.
use SLAVEOF NO ONE
to promote a slave to master
http://redis.io/commands/slaveof
it depends, if you are in a cluster you will be better using the fail over. You will need to use the force option in the command
http://redis.io/commands/cluster-failover