Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Running Redis with Sentinel for High Availability on Linux

Tech May 16 1

Launching Redis with Sentinel on Linux

Redis is a popular in‑memory data store used for caching and improving application performance. To maintain uptime and automatically handle failures, the Sentinel system provides monitoring, notification, and automatic failover for Redis instances. This article explains how to configure and start Redis together with Sentinel on a Linux system.

What Is Sentinel?

Sentinel is a distributed system that watches over your Redis master and replicas. It detects when the master goes down, elects a new master from the available replicas, and reconfigures the other replicas to follow the new master. This process ensures the Redis service remains available without manual intervention.

Setting Up Redis and Sentinel

1. Install Redis

Use your distribution’s package manager. For Debian/Ubuntu systems:

sudo apt update
sudo apt install redis-server
2. Configure the Redis Master and Replicas

Edit the Redis configuration file (typically /etc/redis/redis.conf). For a replica instance, add the line pointing to the master:

replicaof 192.168.1.100 6379

Replace the IP and port with your actual master details.

3. Prepare a Sentinel Configuration

Create a dedicated Sentinel config file (e.g., /etc/redis/sentinel.conf) with atleast the following:

sentinel monitor mymaster 192.168.1.100 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000

Here mymaster is a logical name, 192.168.1.100 and 6379 point to the master, and 2 is the quorum (number of sentinels that must agree the master is down).

4. Start the Redis Instances

First launch the master and then any replicas (make sure the replica config includes the replicaof directive). Use:

redis-server /path/to/redis.conf

To start the Sentinel process, run:

redis-server /path/to/sentinel.conf --sentinel

Or alternatively:

redis-sentinel /path/to/sentinel.conf
5. Verify Sentinel Operation

Connect to the Sentinel port (default 26379) and check its state:

redis-cli -p 26379
SENTINEL masters

You should see details about the monitored master and its replicas.

Automation with a Shell Script

Below is a simple script that starts Redis and Sentinel in the correct order:

#!/bin/bash
MASTER_CFG="/etc/redis/redis-master.conf"
SENTINEL_CFG="/etc/redis/sentinel.conf"

echo "Starting Redis master..."
redis-server "$MASTER_CFG"

echo "Starting Redis Sentinel..."
redis-sentinel "$SENTINEL_CFG"

Make the script executable and run it.

Important Considerations

  • Run at least three Sentinel instances to avoid a split‑brain scenario.
  • Sentinel itself does not require authentication by default; secure it with requirepass and sentinel auth-pass when needed.
  • Always test failover behaviour in a non‑production environment first.

By following these steps you can build a resilient Redis deployment on Linux that automatically recovers from master failures using Sentinel.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.