Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Migrate Redis via Replication

P. Kieran Etienne edited this page May 30, 2017 · 6 revisions

Syncing Data Between Servers

This method of syncing data will cover the process of replication which sets a master/slave relationship between source and target servers. For details on how to, instead, sync Redis data by copying the binary *.rdb file, see the "Migrating Redis" instructions on the Scholarsphere github wiki.

The Redis version being used for this set of instructions is 3.2.3. As of May, 30th 2017, this is the version that is being used on our (new) prod, stage, and qa environments.

Set up Redis for Replication

In order to replicate data from the source to the target server, a one line change must be made to the redis.conf file of the target server and the service on that same machine must be restarted. To perform these changes, follow the step-by-step instructions below.

  1. ssh -p {port} {user}@{server}.{domain}.{extension}
  2. sudo vim /etc/redis.conf
  3. Search for the line containing the text # slaveof <masterip> <masterport>
  4. Place the following line below the line listed above: slaveof {fqdn/ip} 6379 (where "fqdn/ip" is either the fqdn or ip address of the source server).
  5. Restart the redis service: sudo systemctl restart redis
  6. Finished! (replication seems to be nearly instantaneous)

Confirm Successful Replication

  1. Compare file sizes between the source and target servers: ls -l /var/lib/redis/dump.rdb.
  2. From any machine with redis-cli installed: redis-cli -h {source machine fqdn/ip} -p 6379 info
  3. Verify that under the # Replication section, the role is set to master (role:master), that there is one connected slave (connected_slaves:1), and that the appropriate ip is listed (slave0:ip={ip address}).
  4. Also note the number of databases and keys under the Keyspace heading: (db{n}:keys={num}).
  5. From any machine with redis-cli installed: redis-cli -h {target machine fqdn/ip} -p 6379 info
  6. Verify that under the # Replication section, the role is set to slave (role:slave) and that the master host, port, and link status have appropriate values (master_host:{fqdn}, master_port:6379, master_link_status:up).
  7. Also note the number of databases and keys under the Keyspace heading: (db{n}:keys={num}).
  8. Compare the number of databases and keys from the source and target servers.
  9. Scan either server (redis-cli -h {fqdn} -p 6379 --scan), then pick a few keys and check their value on both servers: redis-cli -h {source/target machine fqdn/ip} -p 6379 hgetall scholarsphere:events:{num}. The results should be the same. (This instruction only works for hash type keys).
Clone this wiki locally