Redis replication and availability

Published on Author admin

Redis replication and availability

Redis replication and availability

Redis Replication and availability can be achieved by using sentinel servers. Sentinel is available in redis starting with 2.8 version.

Firs of all we need redis. You can download it from the official web-site – http://redis.io or install it from the repo in your OS. I will use Debian in this article.

1. Installation:


BE CAREFUL!!!
If your are using in your DEBAIN 8 non-default path to store your redis database (dump.rdb) you MUST add in /lib/systemd/system/redis-server.service next line(where path is your data-path)

and than run:

 

2. Server Configuration.

2.1. Master

After the installation is complete we need to edit configs: First, we will set up the master node.

Starting redis-server:

2.2. Slave
To run slave, just append to the master config(do not forget to change the interface) line for replication:

WARNING:
It is very important to keep ip address order. First comes the ip used for replication/production. Otherwise, you will get an error:
Unable to connect to MASTER: Invalid argument

Starting redis-server:

So, we have master-slave set up. To provide failover redis uses Sentinel. Sentinel monitor the state of the redis. If the server goes down it switches the node. All the changes log to sentinel configuration file.

3. Sentinel Configuration:

Sentinel runs on 26379 port. Config file for redis-sentinel will be sentinel.conf:

In this file, we specify the ip address of the master server sentinel to monitor.

Starting sentinel-server:

or:

Redis replication and availability: How it works.
Redis replication and availability

To change the master:

Sentinel keeps the information about the nodes being used in the cluster. So, if you want it to forget deleted nodes we need to run in the sentinel console(redis-cli -p 26379) on each node with interval at least 30 seconds:


BE CAREFUL!!!

If your are using in your DEBAIN 8 non-default path to store your redis database (dump.rdb) you MUST add in /lib/systemd/system/redis-server.service next line(where path is your data-path)

and than run:

 

This will fix next error:

Links:

Thats all 🙂