Introduction

Redis replication allows data from a Redis master server to be replicated to one or more slave servers. This setup improves data availability, supports read scaling, and provides redundancy in case of server failures. This guide explains how to install Redis and configure a master-slave replication environment.

Prerequisites

  • Root or sudo access to both Redis servers
  • Two Linux servers (Master and Slave)
  • Network connectivity between the servers
  • GCC and Make packages installed
  • Port 6379 open between the servers

Implementation

1. Install Linux dependencies GCC and Make(On Redis Server)

sudo yum -y install gcc make

 

2. Download, Untar and Make Redis 3.0

wget http://<Download the latest file from the redis official site>
tar xzf redis-3.3.0-rc3.tar.gz
cd redis-3.0.0-rc3
make

 

3. Create Directories and Copy Redis Files

sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
sudo cp redis.conf /etc/redis

 

4. Configure Redis.Conf (Use any editor)

sudo vim /etc/redis/redis.conf

daemonize yes
bind  0.0.0.0
dir /var/lib/redis
pidfile /var/run/redis.pid
port 6379
dir /var/lib/redis
logfile “/var/log/redis.log”

5. Download init Script

wget 

https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server

 

6. Move and Configure Redis-Server

Note: The redis-server to be moved below is the one downloaded in 5 above.

sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
sudo nano /etc/init.d/redis-server
redis="/usr/local/bin/redis-server"

 

7. Auto-Enable Redis-Server

sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on

 

8. Start Redis Server

sudo service redis-server start


9. (On Redis Slave Server)

Follow the steps from 1 to 6 except step 4, for the step 4 use any editor(vim)
and specify the settings under the /etc/redis/redis.conf file -
daemonize yes
slaveof <hostname or IPaddress> 6379
pidfile /var/run/redis.pid
port 6379


10. Auto-Enable Redis-Server

sudo chkconfig --add redi-server && sudo chkconfig --level 345 redis-server on

 

11. Start Redis Server

sudo service redis-server start

Conclusion

Configuring Redis in a master-slave setup provides data replication between servers, improving availability and supporting read scalability. After configuring both the master and slave servers, verify that replication is functioning correctly to ensure data is synchronized across the Redis environment.

Leave a Reply