How to do a Redis Master Slave switch/failover

Written by - 0 comments

Published on - last updated on May 26th 2021 - Listed in Database Linux Redis


Note: This article was written in 2014. However it still applies to Redis versions up and including Redis 4.x. Redis 5.x uses another terminology (replicaof instead of slaveof).

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.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Observability   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder