Servers are combined into a Primary/Replica(s) cluster. One server acts as the main one and sends its data to the others. Read more about setting up and working with a PostgreSQL cluster in the official documentation: https://redis.io/topics/sentinel.
Instructions on installing and configuring Redis can be found on the official website: https://redis.io/download. The guide to Sentinel can be found in the documentation: https://redis.io/docs/management/sentinel/.
Basic information
начало внимание
You need at least 3 servers to create a Redis cluster.
конец внимание
In this example, 3 nodes with the following hostnames and IP addresses are used:
- redis-server1, 192.168.1.21
- redis-server2, 192.168.1.22
- redis-server3, 192.168.1.23
Step 1: Install Redis
- Add the Redis repositories:
sudo add-apt-repository ppa:redislabs/redis
- Install Redis and its dependencies:
sudo apt-get -y install redis redis-sentinel net-tools
Step 2: Configure Redis
To configure Redis, edit the /etc/redis/redis.conf file on each server:
sudo nano /etc/redis/redis.conf
- Make the servers available for all IP addresses of the server:
bind 0.0.0.0
In our case, the Redis service becomes available from all external addresses.
- Increase the maximum number of clients by changing the maxclients parameter to 20000. You also need to uncomment the line (delete the # character):
maxclients 20000
- Set the Redis password:
requirepass SecretPassword
- Specify a password for the primary node:
masterauth SecretPassword
- To configure a subordinate node, you need to specify the primary’s address and port:
replicaof redis-server1.your_domain 6379
- Restart all servers (first the primary, then the subordinates):
sudo systemctl restart redis-server
sudo systemctl enable redis-server
- Check the replication status:
sudo redis-cli -a SecretPassword info replication
Step 3: Configure Sentinel
To configure Sentinel, edit the /etc/redis/sentinel.conf file on each server.
начало внимание
For correct operation, don’t change the specified order of lines in the /etc/redis/sentinel.conf file.
конец внимание
- Make the servers available to all IP addresses of this server:
bind 0.0.0.0
In our case, this makes the Sentinel service available from all external addresses.
- Specify the primary’s address and port and set the quorum.
sentinel monitor mymaster 192.168.1.21 6379 2
- Set a password that will be used to access the primary:
sentinel auth-pass mymaster SecretPassword
- Set the timeout for considering the primary node inactive:
sentinel down-after-milliseconds mymaster 3000
- Set the timeout for changing a subordinate node’s role to primary if the primary node doesn’t respond:
sentinel failover-timeout mymaster 6000
- Restart all servers:
sudo systemctl restart redis-sentinel
sudo systemctl enable redis-sentinel
- Check the Sentinel’s status and check whether the quorum configuration is correct:
sudo redis-cli -p 26379 info sentinel
sudo redis-cli -p 26379 sentinel ckquorum mymaster
Step 4: Connect to ELMA365
To connect to the Redis cluster, run the following:
redis://:SecretPassword@redis-server1.your_domain:26379,redis-server2.your_domain:26379,redis-server3.your_domain:26379/0?masterName=mymaster
Found a typo? Highlight the text, press ctrl + enter and notify us