Wednesday, August 29, 2012

Configure Redis Master-Slave Relationship

Configure Redis Master-Slave Relationship

Before configure master slave relationship, make sure your redis version on both servers are  the same, the first time I tried to install M-S relationship, redis on my server1 is version 2.2.12 and on my server2 is version 2.4.4, and it failed , it failed because of 
(1)
"Can't handle RDB format version 2"
(2)
[19171] 05 May 18:05:50 * SLAVE OF 127.0.0.1:6379 enabled (user request)
[19171] 05 May 18:05:51 * Connecting to MASTER...
[19171] 05 May 18:05:51 * MASTER <-> SLAVE sync started: SYNC sent
[19171] 05 May 18:05:51 - Accepted 127.0.0.1:45202
[19171] 05 May 18:05:51 # MASTER aborted replication with an error: ERR Can't SYNC while not connected with my master


so in order to make life easier, please make sure redis version is >= version 2.4.4(because it works on my servers)

You can find Redis Installation instruction on my previous tutorial, we will skip it this time.


1. Locate your redis configuration file.
Redis configuration file is located in "/etc/redis/redis.conf", but the location of redis.conf is depend on how you specify it during redis installation.

2. In Slave server, add 3 lines to redis.conf
slaveof 6379
masterauth password_you_want 
requirepass same_password

3. In Master host, add 2 lines to redis.conf
masterauth password_you_want
requirepass same_password

4. Restart redis servers for both Master and Slave 
# /sbin/service redis-server restart

Now, master-slave should work and the databases is synchronized.

To remove the m-s relationship comment out the above modified lines and restart redis on both server.

No comments:

Post a Comment