Install and configure Redis Sentinel
Overview
Redis Sentinel is designed to provide high availability for Redis. The following instructions show you how to install Redis Sentinel on RHEL and Debian based systems.
Considerations
-
Redis Server must be installed and configured. If you have not, see Redis Installation for RHEL or Debian.
-
On RPM-based distributions, Sentinel is part of the Redis installation package.
-
On Debian-based distributions, a separate package needs to be installed.
-
Install the same version of redis-sentinel that you installed for Redis.
Redis Sentinel for HA Considerations
For a high availability configuration, three or more nodes are used to run Redis Server and Redis Sentinel Server. One node will run the Master Redis instance; the other nodes will run the replica Redis instances.
The Master Redis instance replicates its in-memory database to the other Slave Redis instances. The Redis Sentinel instances coordinate among themselves to determine which node runs the Master Redis Server instance and to coordinate failover.
Step 1: Install Sentinel
RHEL and CentOS
If you have already installed Redis, then redis-sentinel will already be installed. See Redis installation
The configuration for Sentinel is found in /etc/redis/sentinel/sentinel.conf
Debian
Debian requires Sentinel to be installed after Redis is installed. See Redis installation for Debian if you have not installed Redis.
Make sure that you install the same version of redis-sentinel that you installed for Redis. If you haven’t installed Redis, you will need to see the instructions on setting up the package repository for Redis Open Source. Once that has been done, select a version to install and install redis-sentinel.
Run the following command to install Sentinel:
apt install redis-sentinel
Step 2: Configure Sentinel
For each Sentinel instance, the configuration should be the same. Each Sentinel is configured to point to the (initial) master Redis server. They will then automatically find the replicas and the other sentinel instances.
Redis configuration considerations
-
Comment out the line for the bind 127.0.0.1 directive. This will cause the Redis Server to bind to all interfaces so the Redis Server can be accessed externally. Alternately, the bind directive can be set to one or more specific interfaces.
-
On Redis 8+ then you must set a password (using requirepass).
-
Choose a node to be the initial Master Redis instance. On that node, keep the replicaof directive commented out. On the slave nodes, uncomment the replicaof directive, changing the IP address to the IP address of the node that will run the initial Master Redis instance.
-
To configure Redis with a password so that clients, like PiServer and PiCache, use that password to communicate with Redis, the requirepass directive must be uncommented and set to the desired password and the masterauth directive also uncommented and set to the same password. The protected-mode directive must be either commented or set to yes.
# You can require sentinel itself to have a password:
requirepass "mysentinelpassword"
# Configure the password to connect to Redis:
sentinel auth-pass mymaster mypassword
# Specify the master redis server to connect to. The slaves will be found automatically.
sentinel monitor mymaster 10.1.10.1 6379 2
RHEL and CentOS configuration file
The configuration for Sentinel is found in /etc/redis/sentinel/sentinel.conf
Debian configuration file
The configuration for Sentinel can be found in /etc/redis/sentinel.conf
Step 3: Configure piserver.yml
The Redis configuration for each PiServer should be set to point to the sentinel servers rather than an individual redis server.
Disable the stand-alone option when you enable Sentinel.
For example:
redis:
# Standalone Redis server
#standalone:
# host: localhost
# port: 6379
# Sentinel HA Redis server
sentinel:
servers:
- { host: "redis-server-1", port: 26379 }
- { host: "redis-server-2", port: 26379 }
- { host: "redis-server-3", port: 26379 }
masterId: mymaster
Step 4: Start and enable Sentinel
Once Sentinel has been configured, use the following to start and enable the service:
sudo systemctl start redis-sentinel
sudo systemctl enable redis-sentinel
Step 5: Check roles
Once all the redis instances are running, you can check each Redis server to see if it is the master or a slave by running the following on each host:
redis-cli --pass mypassword info | grep role