Configure Redis Sentinel with SSL/TLS encryption and authentication for high availability

Advanced 45 min Apr 04, 2026 81 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up a production-grade Redis Sentinel cluster with SSL/TLS encryption, authentication, and automatic failover for high availability. This tutorial covers certificate generation, security configuration, and monitoring setup.

Prerequisites

  • Root or sudo access
  • At least 4GB RAM
  • Basic understanding of Redis
  • Network access between Redis instances
  • OpenSSL for certificate generation

What this solves

Redis Sentinel provides high availability for Redis deployments by monitoring master and replica instances, performing automatic failover when the master fails, and providing service discovery for clients. Without proper SSL/TLS encryption and authentication, Redis communications are vulnerable to interception and unauthorized access.

This tutorial configures a secure, production-ready Redis Sentinel cluster with SSL encryption for all communications, authentication mechanisms, and monitoring capabilities to ensure your Redis infrastructure remains highly available and secure.

Step-by-step configuration

Install Redis and required packages

Install Redis server and SSL tools needed for certificate generation and secure communications.

sudo apt update
sudo apt install -y redis-server openssl ca-certificates
sudo systemctl stop redis-server
sudo dnf update -y
sudo dnf install -y redis openssl ca-certificates
sudo systemctl stop redis

Create Redis user and directories

Create dedicated directories for Redis data, certificates, and configuration files with proper ownership and permissions.

sudo mkdir -p /etc/redis/{certs,conf.d}
sudo mkdir -p /var/lib/redis/{master,replica1,replica2,sentinel}
sudo mkdir -p /var/log/redis
sudo chown -R redis:redis /var/lib/redis /var/log/redis /etc/redis
sudo chmod 755 /var/lib/redis /var/log/redis
sudo chmod 750 /etc/redis

Generate SSL/TLS certificates

Create a Certificate Authority and generate SSL certificates for secure Redis communications between all components.

cd /etc/redis/certs

Generate CA private key

sudo openssl genrsa -out ca.key 4096

Generate CA certificate

sudo openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=Redis-CA"

Generate Redis server private key

sudo openssl genrsa -out redis.key 2048

Generate Redis server certificate signing request

sudo openssl req -new -key redis.key -out redis.csr -subj "/C=US/ST=State/L=City/O=Organization/CN=redis-server"

Generate Redis server certificate

sudo openssl x509 -req -in redis.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out redis.crt -days 365 -sha256

Generate DH parameters for forward secrecy

sudo openssl dhparam -out redis-dh.pem 2048

Set certificate permissions

Configure secure file permissions for SSL certificates, ensuring only Redis processes can access private keys.

sudo chown redis:redis /etc/redis/certs/*
sudo chmod 644 /etc/redis/certs/*.crt
sudo chmod 600 /etc/redis/certs/*.key
sudo chmod 644 /etc/redis/certs/*.pem
sudo rm /etc/redis/certs/*.csr
Never use chmod 777. Private keys must be readable only by the Redis user to prevent unauthorized access to your SSL certificates.

Configure Redis master instance

Set up the Redis master with SSL encryption, authentication, and security hardening.

port 0
tls-port 6380
tls-cert-file /etc/redis/certs/redis.crt
tls-key-file /etc/redis/certs/redis.key
tls-ca-cert-file /etc/redis/certs/ca.crt
tls-dh-params-file /etc/redis/certs/redis-dh.pem
tls-protocols "TLSv1.2 TLSv1.3"
tls-ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
tls-ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
tls-prefer-server-ciphers yes
tls-session-caching no
tls-session-cache-timeout 60

bind 127.0.0.1 203.0.113.10
protected-mode yes
requirepass "StrongMasterPassword123!"
masterauth "StrongMasterPassword123!"

tcp-keepalive 300
timeout 0
tcp-backlog 511

databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-master.rdb
dir /var/lib/redis/master

appendonly yes
appendfilename "appendonly-master.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 10000
slowlog-max-len 128

latency-monitor-threshold 100

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2
list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

stream-node-max-bytes 4096
stream-node-max-entries 100

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

client-query-buffer-limit 1gb
proto-max-bulk-len 512mb

hz 10

dynamic-hz yes

aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

logfile /var/log/redis/redis-master.log
loglevel notice
syslog-enabled yes
syslog-ident redis-master

maxmemory-policy allkeys-lru

Configure Redis replica instances

Set up Redis replica instances that will replicate data from the master with SSL encryption.

port 0
tls-port 6381
tls-cert-file /etc/redis/certs/redis.crt
tls-key-file /etc/redis/certs/redis.key
tls-ca-cert-file /etc/redis/certs/ca.crt
tls-dh-params-file /etc/redis/certs/redis-dh.pem
tls-protocols "TLSv1.2 TLSv1.3"
tls-ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
tls-ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
tls-prefer-server-ciphers yes
tls-session-caching no
tls-session-cache-timeout 60

bind 127.0.0.1 203.0.113.10
protected-mode yes
requirepass "StrongReplicaPassword123!"
masterauth "StrongMasterPassword123!"

replicaof 203.0.113.10 6380
replica-serve-stale-data yes
replica-read-only yes
replica-diskless-sync no
replica-diskless-sync-delay 5
replica-priority 90

tcp-keepalive 300
timeout 0
tcp-backlog 511

databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-replica1.rdb
dir /var/lib/redis/replica1

appendonly yes
appendfilename "appendonly-replica1.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 10000
slowlog-max-len 128

latency-monitor-threshold 100

logfile /var/log/redis/redis-replica1.log
loglevel notice
syslog-enabled yes
syslog-ident redis-replica1

maxmemory-policy allkeys-lru

Create second replica configuration

Configure the second Redis replica instance for additional redundancy.

port 0
tls-port 6382
tls-cert-file /etc/redis/certs/redis.crt
tls-key-file /etc/redis/certs/redis.key
tls-ca-cert-file /etc/redis/certs/ca.crt
tls-dh-params-file /etc/redis/certs/redis-dh.pem
tls-protocols "TLSv1.2 TLSv1.3"
tls-ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
tls-ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
tls-prefer-server-ciphers yes
tls-session-caching no
tls-session-cache-timeout 60

bind 127.0.0.1 203.0.113.10
protected-mode yes
requirepass "StrongReplicaPassword123!"
masterauth "StrongMasterPassword123!"

replicaof 203.0.113.10 6380
replica-serve-stale-data yes
replica-read-only yes
replica-diskless-sync no
replica-diskless-sync-delay 5
replica-priority 80

tcp-keepalive 300
timeout 0
tcp-backlog 511

databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-replica2.rdb
dir /var/lib/redis/replica2

appendonly yes
appendfilename "appendonly-replica2.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 10000
slowlog-max-len 128

latency-monitor-threshold 100

logfile /var/log/redis/redis-replica2.log
loglevel notice
syslog-enabled yes
syslog-ident redis-replica2

maxmemory-policy allkeys-lru

Configure Redis Sentinel instances

Set up Redis Sentinel with SSL encryption and authentication for monitoring and automatic failover.

port 0
tls-port 26380
tls-cert-file /etc/redis/certs/redis.crt
tls-key-file /etc/redis/certs/redis.key
tls-ca-cert-file /etc/redis/certs/ca.crt
tls-dh-params-file /etc/redis/certs/redis-dh.pem
tls-protocols "TLSv1.2 TLSv1.3"
tls-ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
tls-ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
tls-prefer-server-ciphers yes
tls-session-caching no

bind 127.0.0.1 203.0.113.10
protected-mode yes
requirepass "StrongSentinelPassword123!"

sentinel monitor mymaster 203.0.113.10 6380 2
sentinel auth-pass mymaster "StrongMasterPassword123!"
sentinel down-after-milliseconds mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
sentinel deny-scripts-reconfig yes

sentinel announce-ip 203.0.113.10
sentinel announce-port 26380

logfile /var/log/redis/sentinel1.log
loglevel notice
syslog-enabled yes
syslog-ident redis-sentinel1

dir /var/lib/redis/sentinel

Create additional Sentinel configurations

Configure two more Sentinel instances to form a quorum of three for reliable failover decisions.

sudo cp /etc/redis/sentinel1.conf /etc/redis/sentinel2.conf
sudo cp /etc/redis/sentinel1.conf /etc/redis/sentinel3.conf

sudo sed -i 's/tls-port 26380/tls-port 26381/' /etc/redis/sentinel2.conf
sudo sed -i 's/announce-port 26380/announce-port 26381/' /etc/redis/sentinel2.conf
sudo sed -i 's/sentinel1.log/sentinel2.log/' /etc/redis/sentinel2.conf
sudo sed -i 's/redis-sentinel1/redis-sentinel2/' /etc/redis/sentinel2.conf

sudo sed -i 's/tls-port 26380/tls-port 26382/' /etc/redis/sentinel3.conf
sudo sed -i 's/announce-port 26380/announce-port 26382/' /etc/redis/sentinel3.conf
sudo sed -i 's/sentinel1.log/sentinel3.log/' /etc/redis/sentinel3.conf
sudo sed -i 's/redis-sentinel1/redis-sentinel3/' /etc/redis/sentinel3.conf

Set configuration file permissions

Secure Redis configuration files with proper ownership and restricted access permissions.

sudo chown redis:redis /etc/redis/*.conf
sudo chmod 640 /etc/redis/*.conf

Create systemd service files

Create systemd service definitions for Redis master, replica, and Sentinel instances.

[Unit]
Description=Redis Master Server
After=network.target

[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis-master.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-master
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

Create replica service files

Set up systemd services for Redis replica instances.

sudo tee /etc/systemd/system/redis-replica1.service > /dev/null << 'EOF'
[Unit]
Description=Redis Replica 1 Server
After=network.target redis-master.service

[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis-replica1.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-replica1
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

sudo tee /etc/systemd/system/redis-replica2.service > /dev/null << 'EOF'
[Unit]
Description=Redis Replica 2 Server
After=network.target redis-master.service

[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis-replica2.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-replica2
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

Create Sentinel service files

Configure systemd services for Redis Sentinel instances.

sudo tee /etc/systemd/system/redis-sentinel1.service > /dev/null << 'EOF'
[Unit]
Description=Redis Sentinel 1
After=network.target redis-master.service redis-replica1.service redis-replica2.service

[Service]
Type=notify
ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel1.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-sentinel1
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

sudo tee /etc/systemd/system/redis-sentinel2.service > /dev/null << 'EOF'
[Unit]
Description=Redis Sentinel 2
After=network.target redis-master.service redis-replica1.service redis-replica2.service

[Service]
Type=notify
ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel2.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-sentinel2
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

sudo tee /etc/systemd/system/redis-sentinel3.service > /dev/null << 'EOF'
[Unit]
Description=Redis Sentinel 3
After=network.target redis-master.service redis-replica1.service redis-replica2.service

[Service]
Type=notify
ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel3.conf
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis-sentinel3
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
EOF

Start Redis services

Enable and start all Redis services in the correct order to establish replication and monitoring.

sudo systemctl daemon-reload

Start Redis master first

sudo systemctl enable --now redis-master sudo sleep 5

Start replicas

sudo systemctl enable --now redis-replica1 sudo systemctl enable --now redis-replica2 sudo sleep 5

Start Sentinel instances

sudo systemctl enable --now redis-sentinel1 sudo systemctl enable --now redis-sentinel2 sudo systemctl enable --now redis-sentinel3

Configure firewall rules

Open necessary ports for Redis and Sentinel communications while maintaining security.

sudo ufw allow from 203.0.113.0/24 to any port 6380 comment 'Redis Master SSL'
sudo ufw allow from 203.0.113.0/24 to any port 6381 comment 'Redis Replica 1 SSL'
sudo ufw allow from 203.0.113.0/24 to any port 6382 comment 'Redis Replica 2 SSL'
sudo ufw allow from 203.0.113.0/24 to any port 26380 comment 'Redis Sentinel 1 SSL'
sudo ufw allow from 203.0.113.0/24 to any port 26381 comment 'Redis Sentinel 2 SSL'
sudo ufw allow from 203.0.113.0/24 to any port 26382 comment 'Redis Sentinel 3 SSL'
sudo ufw reload
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="6380" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="6381" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="6382" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="26380" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="26381" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.0/24" port protocol="tcp" port="26382" accept'
sudo firewall-cmd --reload

Verify your setup

Test Redis Sentinel cluster functionality, SSL encryption, and authentication to ensure proper configuration.

# Check service status
sudo systemctl status redis-master redis-replica1 redis-replica2
sudo systemctl status redis-sentinel1 redis-sentinel2 redis-sentinel3

Test SSL connection to master

redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 6380 -a "StrongMasterPassword123!" ping

Check replication status

redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 6380 -a "StrongMasterPassword123!" info replication

Test Sentinel status

redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 26380 -a "StrongSentinelPassword123!" sentinel masters

Test write to master and read from replica

redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 6380 -a "StrongMasterPassword123!" set testkey "testvalue" redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 6381 -a "StrongReplicaPassword123!" get testkey

Test failover functionality

Verify automatic failover by simulating master failure and observing Sentinel behavior.

# Monitor Sentinel logs in separate terminal
sudo tail -f /var/log/redis/sentinel*.log &

Simulate master failure

sudo systemctl stop redis-master

Wait for failover (typically 5-10 seconds)

sleep 10

Check new master

redis-cli --tls --cert /etc/redis/certs/redis.crt --key /etc/redis/certs/redis.key --cacert /etc/redis/certs/ca.crt -p 26380 -a "StrongSentinelPassword123!" sentinel get-master-addr-by-name mymaster

Restart original master (it will become a replica)

sudo systemctl start redis-master

Common issues

SymptomCauseFix
SSL connection refusedCertificate permission issuesCheck sudo ls -la /etc/redis/certs/ and ensure redis user owns files
Authentication failuresMismatched passwordsVerify password consistency in all config files
Replication not workingMaster unreachableCheck firewall rules and bind addresses
Sentinel can't reach RedisWrong SSL configurationEnsure all instances use matching SSL settings
Failover not happeningInsufficient Sentinel quorumVerify at least 3 Sentinels are running and connected
Services won't startConfiguration syntax errorsCheck logs with sudo journalctl -u redis-master -f
High memory usageNo memory policy setConfigure maxmemory and eviction policy in config

Next steps

Automated install script

Run this to automate the entire setup

#redis #sentinel #ssl #tls #authentication #high-availability #failover #encryption #security #monitoring

Need help?

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.

Talk to an engineer