Home / Linux / How to Setup Redis For High Availability with Sentinel in CentOS 8

How to Setup Redis For High Availability with Sentinel in CentOS 8

How to Setup Redis For High Availability with Sentinel in CentOS 8

Redis supplies excessive availability through Redis Sentinel distributed system. Sentinel helps to monitor Redis situations, detect failures and can do roles switches mechanically thus enabling a Redis deployment to resist any form of failures.

It options monitoring of Redis situations (grasp and replicas), helps notification of different providers/processes or the system administrator through a script, computerized failover to promote a reproduction to a grasp when the grasp goes down and supplies configuration for purchasers to uncover the present grasp providing a specific service.

This article demonstrates how to arrange Redis for prime availability with Redis Sentinel in CentOS 8, together with configuring sentinels, checking the setup standing and testing a Sentinel failover.

Prerequisite:

  1. How To Setup Redis Replication (with Cluster-Mode Disabled) in CentOS 8 – Part 1

Test Environment Setup

Master Server and Sentinel1: 10.42.zero.247
Redis Replica1 and Sentinel2: 10.42.zero.21
Redis Replica2 and Sentinelthree: 10.42.zero.34
Redis Sentinel Setup Logical DiagramRedis Sentinel Setup Logical Diagram

Redis Sentinel Setup Logical Diagram

According to the Redis Sentinel documentation, one wants a minimum of three Sentinel situations for a strong deployment. Considering our arrange above, if the grasp fails, Sentinels2 and Sentinelthree will agree concerning the failure and can be ready to authorize a failover, making shopper operations ready to proceed.

Step 1: Starting and Enabling Redis Sentinel Service

1. On CentOS 8, the Redis Sentinel service is put in alongside the Redis server (which we already did in the Redis Replication Setup).

To begin the Redis sentinel service and allow it to mechanically begin at system boot, use the next systemctl instructions. Also, affirm that it’s up and operating by checking its standing (do that on all of the nodes):

# systemctl begin redis-sentinel
# systemctl allow redis-sentinel
# systemctl standing redis-sentinel
Start Redis Sentinel ServiceStart Redis Sentinel Service

Start Redis Sentinel Service

Step 2: Configuring Redis Sentinel on All Redis Nodes

2. In this part, we clarify how to configure Sentinel on all our nodes. The Sentinel service has an analogous configuration format because the Redis server. To configure it, use the /and so forth/redis-sentinel.conf self-documented configuration file.

First, create a backup of the unique file and open it for enhancing.

# cp /and so forth/redis-sentinel.conf /and so forth/redis-sentinel.conf.orig
# vi /and so forth/redis-sentinel.conf

three. By default, Sentinel listens on port 26379, confirm this on all of the situations. Note that you’ve to depart the bind parameter commented out (or set to zero.zero.zero.zero).

port 26379
Set Sentinel Listen Interface and PortSet Sentinel Listen Interface and Port

Set Sentinel Listen Interface and Port

four. Next, inform Sentinel to monitor our grasp, and to take into account it in the “Objectively Down” state provided that a minimum of 2 quorum sentinels agree. You can change “mymaster” with a customized title.

#On Master Server and Sentinel1
sentinel monitor mymaster 127.zero.zero.1 6379 2

#On Replica1 and Sentinel2
sentinel monitor mymaster 10.42.zero.247 6379 2

#On Replica1 and Sentinelthree
sentinel monitor mymaster 10.42.zero.247 6379 2
Set Redis Master to MonitorSet Redis Master to Monitor

Set Redis Master to Monitor

Important: The sentinel monitor assertion MUST be positioned earlier than the sentinel auth-pass assertion to keep away from the error “No such grasp with the desired title.” when restarting the sentinel service.

5. If the Redis grasp to monitor has a password set (in our case the grasp has), present the password in order that Sentinel occasion can authenticate with the protected occasion.

 
sentinel auth-pass mymaster [email protected]
Set Master Auth PasswordSet Master Auth Password

Set Master Auth Password

6. Then set the variety of milliseconds the grasp (or any connected duplicate or sentinel) must be unreachable to take into account it in the “Subjectively Down” state.

The following configuration implies that the grasp can be thought of failing as quickly as we don’t obtain any reply from our pings inside 5 seconds (1 second is equal to 1000 milliseconds).

sentinel down-after-milliseconds mymaster 5000
Set Down Time for MasterSet Down Time for Master

Set Down Time for Master

7. Next, set the failover timeout in milliseconds which defines many issues (learn the documentation of the parameter in the configuration file).

sentinel failover-timeout mymaster 180000
Set Fail Over TimeoutSet Fail Over Timeout

Set Fail Over Timeout

8. Then set the variety of replicas that may be reconfigured to use the brand new grasp after a failover on the similar time. Since we have now two replicas, we are going to set one duplicate as the opposite can be promoted to the brand new grasp.

sentinel parallel-syncs mymaster 1
Set Number of Parallel Sync ReplicasSet Number of Parallel Sync Replicas

Set Number of Parallel Sync Replicas

Note that the configuration recordsdata on Redis Replica1 and Sentinel2, and Reddis Replica1 and Sentinel2 must be equivalent.

9. Next, restart the Sentinel providers on all nodes to apply the current adjustments.

# systemctl restart redis-sentinel

10. Next, open port 26379 in the firewall on all nodes to allow the Sentinel situations to begin speaking, obtain connections from the opposite Sentinel situations, utilizing the firewall-cmd.

# firewall-cmd --zone=public --permanent --add-port=26379/tcp
# firewall-cmd --reload

11. All the replicas can be mechanically found. Importantly, Sentinel will replace the configuration mechanically with further details about replicas. You can affirm this by opening the Sentinel configuration file for every occasion and look by it.

For instance, if you take a look at the tip of the grasp’s configuration file, you need to see the known-sentinels and known-replica statements as proven in the next screenshot.

Auto Generated Config in MasterAuto Generated Config in Master

Auto Generated Config in Master

It’s must be the identical case on replica1 and replica2.

Auto Generated Config in Replica1Auto Generated Config in Replica1

Auto Generated Config in Replica1

Auto Generated Config in Replica2Auto Generated Config in Replica2

Auto Generated Config in Replica2

Note that the Sentinel configuration can also be rewritten/up to date each time a reproduction is promoted to grasp standing throughout a failover and each time a brand new Sentinel is found in the setup.

Step three: Check the Redis Sentinel Setup Status

12. Now examine the Sentinel standing/data on the grasp, utilizing the data sentinel command as follows.

# redis-cli -p 26379 data sentinel

From the output of the command as seen in the next screenshot, we have now two replicas/slaves and three sentinels.

Check Sentinel Info on MasterCheck Sentinel Info on Master

Check Sentinel Info on Master

13. To reveals detailed details about the grasp (known as mymaster), use the sentinel grasp command.

# redis-cli -p 26379 sentinel grasp mymaster
Show Detailed Info About Sentinel MasterShow Detailed Info About Sentinel Master

Show Detailed Info About Sentinel Master

14. To reveals detailed details about the slaves and sentinels, use the sentinel slaves command and sentinel sentinels command respectively.

# redis-cli -p 26379 sentinel slaves mymaster
# redis-cli -p 26379 sentinel sentinels mymaster

15. Next, ask the deal with of the grasp by title from the slave situations utilizing the sentinel get-master-addr-by-name command as follows.

The output must be the IP deal with and port of the present grasp occasion:

# redis-cli -p 26379 sentinel get-master-addr-by-name mymaster
Get the Address of Master by Name on SlavesGet the Address of Master by Name on Slaves

Get the Address of Master by Name on Slaves

Step four: Test the Sentinel Failover

16. Finally, let’s take a look at computerized failover in our Sentinel setup. On the Redis/Sentinel grasp, make the Redis grasp (operating on port 6379) to sleep for 60 seconds. Then question the deal with of the present grasp on the replicas/slaves as follows.

# redis-cli -p 6379
127.zero.zero.1:6379> AUTH [email protected]
127.zero.zero.1:6379>  debug sleep 60
# redis-cli -p 26379 sentinel get-master-addr-by-name mymaster
# redis-cli -p 26379 sentinel get-master-addr-by-name mymaster

From the output for the question, the brand new grasp is now duplicate/slave2 with IP deal with 10.42.zero.34 as seen in the next screenshot.

Test Redis Sentinel FailoverTest Redis Sentinel Failover

Test Redis Sentinel Failover

You can get extra data from the Redis Sentinel documentation. But if in case you have any ideas to share or queries, the suggestions kind under is your gateway to us.

In the following and final a part of this collection, we are going to take a look at how to arrange a Redis Cluster in CentOS 8. It can be an impartial article from the primary two.

About Agent

Check Also

Google Anthos Update Aims at AWS, Puts Azure in Crosshairs

Google Anthos Update Aims at AWS, Puts Azure in Crosshairs Google …

Leave a Reply

Your email address will not be published. Required fields are marked *