This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Migrate Redis via Replication
P. Kieran Etienne edited this page May 30, 2017
·
6 revisions
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.
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.
ssh -p {port} {user}@{server}.{domain}.{extension}
sudo vim /etc/redis.conf
- Search for the line containing the text
# slaveof <masterip> <masterport>
- 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). - Restart the redis service:
sudo systemctl restart redis
- Finished! (replication seems to be nearly instantaneous)
- Compare file sizes between the source and target servers:
ls -l /var/lib/redis/dump.rdb
. - From any machine with redis-cli installed:
redis-cli -h {source machine fqdn/ip} -p 6379 info
- 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}
). - Also note the number of databases and keys under the
Keyspace
heading: (db{n}:keys={num}
). - From any machine with redis-cli installed:
redis-cli -h {target machine fqdn/ip} -p 6379 info
- 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
). - Also note the number of databases and keys under the
Keyspace
heading: (db{n}:keys={num}
). - Compare the number of databases and keys from the source and target servers.
- 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).