Redis - Promoting a slave to master manually
Asked Answered
L

5

21

Suppose I have [Slave IP Address] which is the slave of [Master IP Address].

Now my master server has been shut down, and I need to set this slave to be master MANUALLY (WITHOUT using sentinel automatic failover, WITH redis command).

Is it possible doing this without restarting the redis service ? (and losing all the cached data)

Lammas answered 8/12, 2015 at 12:30 Comment(0)
C
35

use SLAVEOF NO ONE to promote a slave to master

http://redis.io/commands/slaveof

Clockwise answered 8/12, 2015 at 13:12 Comment(0)
H
2

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

Hairy answered 12/5, 2016 at 2:24 Comment(0)
N
2

As of Redis version 5.0.0 the SLAVEOF command is regarded as deprecated.

If a Redis server is already acting as replica, the command REPLICAOF NO ONE will turn off the replication, turning the Redis server into a MASTER.

Nunatak answered 3/12, 2022 at 13:33 Comment(0)
A
1

Is it possible doing this without restarting the redis service? (and losing all the cached data)


yes that's possible, you can use
SLAVEOF 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.

Augustina answered 8/6, 2019 at 4:32 Comment(1)
sentinel failover master-name has to be run in the Sentinel command promptKohlrabi
P
1

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 in fail state, also run cluster 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 use cluster failover force or cluster 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.

Pathan answered 2/9, 2021 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.