redis cache clustering with failover
Hi Techrunnr Readers, Today document deals with redis cache clustering with failover.
Redis is an open-source in-memory database project implementing a distributed, in-memory key-value store with optional durability. Redis is mainly used to store cache hence results in application performance. It is used as a message broker.
So setting up a standalone Redis server is a single point of failure. Standalone setup is ok for the Dev Environment but when we are moving to a production environment it’s highly recommended to have a High available system.
Redis supports clustering and automatic failover using an extra component called Redis Sentinel.
Redus uses 6379 and sentinel uses 26379 as the port numbers, so enable these ports in the firewall.
Now let’s see how to achieve this,
Let’s consider we have 3 servers where Redis and Redis Sentinel installed.
Use the following command to install both the services,
1. Add the repository
2. Update the System with the new repository
So after installing let’s move to the configuration part.
Redis Sentinel is one of the major parts of Redis cluster failover. It detects the cluster failover and brings backs to the stable state with any human intervention.
Sentinel detects the current master and master details sent to the client application. Sentinel always check which is the master node, if it detects any failure to master node, it does the failover operation.
Redis cluster with failover uses master-slave architecture, where the only primary server has read and write operation, and other servers(secondary) remains read-only.
Electing the new server is based upon the quorum results. Quarom is the number of sentinels that need to agree about the fact the master is not reachable. However, the quorum is only used to detect the failure. In order to actually perform a failover, one of the Sentinels needs to be elected leader for the failover and be authorized to proceed.
Consider the below image, here we have host2 as the master and other as slaves.
Here is the configuration to Redis cluster failover,
Where mymaster is the cluster name, monitor mymaster 172.17.0.117 6379 2 means sentinel will check the host2 redis master is available or not and the number of sentinels need to agree master is down is 2.
down-after-milliseconds mymaster 5000 defines after 5seconds the master node is down, then it moves to failover.
slaveof tells Redis cluster to make this particular server instance as a SLAVE instance of the given MASTER node.
Now, let’s start the Redis and Sentinel service,
Now if you check the replication status on master and slave as follows,
if you stop any Redis server, from the sentinel logs you can see master server got switched from node2 to node3.
Hope you all understood the Redis cluster with failover.
© 2018, Techrunnr. All rights reserved.