Header RSS Feed
 
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

How to do a Redis Master Slave switch/failover
Thursday - Apr 24th 2014 - by - (0 comments)

Redis is a very fast key-value database server with master/slave capabilities, a little bit like the typical MySQL master/slave setups.

Given a scenario with one master and one slave, whereas all connections go to the master (by DNS entry, or whatever way was chosen), the following steps explain how to do a master/slave switch.

  • redis01 (Master): 192.168.50.11
  • redis02 (Slave): 192.168.50.12

If redis01 is broken and/or down, redis02, the current slave, needs to be made to the new master. First let's check for the current replication setup on redis02:

root@redis02 ~ # redis-cli info
[...]
# Replication
role:slave
master_host:192.168.50.11
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
master_link_down_since_seconds:244
slave_priority:100
slave_read_only:1
connected_slaves:0
[...]

Let's tell redis02 to become a master server:

root@redis02 ~ # redis-cli
redis 127.0.0.1:6379> slaveof no one
OK

Verify with info again:

redis 127.0.0.1:6379> info
[...]
# Replication
role:master
connected_slaves:0

redis02 can now be used as new master server with up to date data.

After a while, when redis01 was fixed, it can be connected as slave to redis01 to sync the new data:

root@redis01 ~ # redis-cli
redis 127.0.0.1:6379> slaveof 192.168.50.12 6379

On redis02 (the new master) the new slave connection can be seen in the replication info:

root@redis02 ~ # redis-cli info
[...]
# Replication
role:master
connected_slaves:1
slave0:192.168.50.11,6379,online

 

 

Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Nagios Plugins nagios plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

7668 Days
until Death of Computers
Why?