Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Introducation

Redis is an in-memory data storage that is used by the CoreOne Suite. This how-to gives you a brief overview on how to install and configure a Redis-Cluster a redis cluster on Ubuntu.

Table of Contents

...

Step 1 - Check your prerequisits

  • Redis has to be installed on a Linux OS (Ubuntu, Redhat, Centos, etc.).

  • To install Redis, at least 3 instances are needed. The instances can be distributed across different servers, or concentrated on one (best practice will be shown in the examples below).

  • If the servers for Redis are in different network-zones, the servers must be able to communicate with eachother.

  • The following Firewall-Ports must be open:

    • 6379

    • 16384

    • 16379

    • 7001 (Cluster)

    • 7002 (Cluster)

    • 7003 (Cluster)

    • 7004 (Cluster)

    • 7006 (FCluster)

Example

In our example we got 3 virtual Ubuntu-Servers.

Redis HA 1 (192.168.17.134)
Redis HA 2 (192.168.17.135)
Redis HA 3 (192.168.17.136)

On Redis HA1 is a Master Instance 7001 and a Slave Instance 7004
On Redis HA2 is a Master Instance 7002 and a Slave Instance 7005
On Redis HA3 is a Master Instance 7003 and a Slave Instance 7006

For the Master 7001 the Slave is 7006
For the Master 7002 the Slave is 7006
For the Master 7003 the Slave is 7004

...

Step 2 - Installation

General installation for all 3 servers:

Switch to root user:

Code Block
sudo su

...

Code Block
cd /etc/redis/redis-6.2.6/
sudo make test

Step 3 - Configuration VM 1

In our example we have multiple redis instanced on one server. This means we need multiple config-files on the server as well.

...

Code Block
port 7001
cluster-enabled yes
cluster-config-file cluster-node-1.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-1.aof
dbfilename dump-1.rdb
Info

vim: Save file ctrl+c | wq!
vim: Close file without saving ctrl+c | q!
vim: Search in file esc /search
vim: Edit File: i

Code Block
sudo vim node4.conf

Copy the following text to the config file:

Code Block
port 7004
cluster-enabled yes
cluster-config-file cluster-node-4.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-4.aof
dbfilename dump-4.rdb

Step 4 - Configuration VM 2

In our example we have multiple redis instanced on one server. This means we need multiple config-files on the server as well.

...

Code Block
port 7002
cluster-enabled yes
cluster-config-file cluster-node-2.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-2.aof
dbfilename dump-2.rdb
Info

vim: Save file ctrl+c | wq!
vim: Close file without saving ctrl+c | q!
vim: Search in file esc /search
vim: Edit File: i

Code Block
sudo vim node5.conf

Copy the following text to the config file:

Code Block
port 7005
cluster-enabled yes
cluster-config-file cluster-node-5.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-5.aof
dbfilename dump-5.rdb

Step 5 - Configuration VM 3

In our example we have multiple redis instanced on one server. This means we need multiple config-files on the server as well.

...

Code Block
port 7003
cluster-enabled yes
cluster-config-file cluster-node-3.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-3.aof
dbfilename dump-3.rdb
Info

vim: Save file ctrl+c | wq!
vim: Close file without saving ctrl+c | q!
vim: Search in file esc /search
vim: Edit File: i

Code Block
sudo vim node6.conf

Copy the following text:

Code Block
port 7006
cluster-enabled yes
cluster-config-file cluster-node-6.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-6.aof
dbfilename dump-6.rdb

Step 6 - Start Redis

We can start Redis now on each VM through the config-files we created.

...

Server

Instanz

Befehl

HA1 (192.168.17.134)

Node 01 - Port 7001

Node 04 - Port 7004

Code Block
./redis-6.2.6/src/redis-server node1.conf &
Code Block
./redis-6.2.6/src/redis-server node4.conf &

HA 2 (192.168.17.135)

Node 02 - Port 7002

Node 05 - Port 7005

Code Block
./redis-6.2.6/src/redis-server node2.conf &
Code Block
./redis-6.2.6/src/redis-server node5.conf &

HA 3 (192.168.17.136)

Node 03 - Port 7003

Node 06 - Port 7006

Code Block
./redis-6.2.6/src/redis-server node3.conf &
Code Block
./redis-6.2.6/src/redis-server node6.conf &

...

Step 7 - Connect Redis

We can now connect on each instace with the Redis-CLI

Server

Instanz

Befehl

HA1 (192.168.17.134)

Node 01 - Port 7001

Node 04 - Port 7004

Code Block
./redis-6.2.6/src/redis-cli -p 7001
./redis-6.2.6/src/redis-cli -p 7004

HA 2 (192.168.17.135)

Node 02 - Port 7002

Node 05 - Port 7005

Code Block
./redis-6.2.6/src/redis-cli -p 7002
./redis-6.2.6/src/redis-cli -p 7005

HA 3 (192.168.17.136)

Node 03 - Port 7003

Node 06 - Port 7006

Code Block
./redis-6.2.6/src/redis-cli -p 7003
./redis-6.2.6/src/redis-cli -p 7006

Step 8 - Configure Redis Cluster

Since the instaces are local at the moment, we need to connect them to the cluster.

...

Check the config and confirm with: Y

Step 9 - Redis-CLI

Open Redis-CLI:

Info

-p = Port -c = Cluster

Code Block
./redis-6.2.6/src/redis-cli -c -p 7001

ping

Code Block
ping

The different nodes can be pinged:

info

Code Block
info

Shows all information on the cluster

...

cluster nodes

Code Block
cluster nodes

Shows all nodes and if they are master or slave.

...

info replication

Code Block
info replication

Shows if the server is master or slave. Shows the depending slaves.

...

Step 10 - Failover

We will terminate Master 7003 for this example. This will prompt the Slave 7004 to become the new master:

...

On the masters 7001 and 7002 we will get the following message: Code Block2074:S 26 Apr 2022 13:56:22.765 # Error condition on socket for SYNC: Connection refused 2074:S 26 Apr 2022 13:56:23.773 * Connecting to MASTER 192.168.17.136:7003 2074:S 26 Apr 2022 13:56:23.773 * MASTER <-> REPLICA sync started 2074:S 26 Apr 2022 13:56:23.773 # Error condition on socket for SYNC: Connection refused 3904:M 26 Apr 2022 13:56:24.099 * FAIL message received from 9b989e13f6e83d661c072853f48d89d1a995f69c about 88ff5fc7513281e33e5397175cba7dbec2d01265 3904:M 26 Apr 2022 13:56:24.099 # Cluster state changed: fail 2074:S 26 Apr 2022 13:56:24.100 * FAIL message received from 9b989e13f6e83d661c072853f48d89d1a995f69c about 88ff5fc7513281e33e5397175cba7dbec2d01265 2074:S 26 Apr 2022 13:56:24.100 # Cluster state changed: fail 2074:S 26 Apr 2022 13:56:24.177 # Start of election delayed for 711 milliseconds (rank #0, offset 589126). 2074:S 26 Apr 2022 13:56:24.781 * Connecting to MASTER 192.168.17.136:7003 2074:S 26 Apr 2022 13:56:24.781 * MASTER <-> REPLICA sync started 2074:S 26 Apr 2022 13:56:24.781 # Error condition on socket for SYNC: Connection refused 2074:S 26 Apr 2022 13:56:24.983 # Starting a failover election for epoch 28. 3904:M 26 Apr 2022 13:56:24.984 # Failover auth granted to cdfafbc0721ba7774a6e9412e51e7369bd150c1a for epoch 28 2074:S 26 Apr 2022 13:56:25.006 # Failover election won: I'm the new master. 2074:S 26 Apr 2022 13:56:25.006 # configEpoch set to 28 after successful failover 2074:M 26 Apr 2022 13:56:25.006 * Discarding previously cached master state. 2074:M 26 Apr 2022 13:56:25.006 # Setting secondary replication ID to ddd94fd4c80c068c06c03fc5113ce9f33cbbe780, valid up to offset: 589127. New replication ID is 897d8ffc57482c31a6d37db92136073b713e813e 2074:M 26 Apr 2022 13:56:25.006 # Cluster state changed: ok 3904:M 26 Apr 2022 13:56:25.024 # Cluster state changed: ok

We can now check with the Redis-CLI. With the command “Cluster nodes”, we can see, Slave 7004 is now a Master.
We can also see that Master 7003 can’t be reached.

...

If you want the 7003 as Master again, use the following command:

Code Block
./redis-6.2.6/src/redis-cli -c -p 7003
cluster failover

Message:

Code Block
127.0.0.1:7003> 17830:S 26 Apr 2022 14:07:57.685 # Received replication offset for paused master manual failover: 589308
17830:S 26 Apr 2022 14:07:57.685 # All master replication stream processed, manual failover can start.
7830:S 26 Apr 2022 14:07:57.685 # Start of election delayed for 0 milliseconds (rank #0, offset 589308).
17830:S 26 Apr 2022 14:07:57.685 # Starting a failover election for epoch 29.
17830:S 26 Apr 2022 14:07:57.686 # Currently unable to failover: Waiting for votes, but majority still not reached.
17830:S 26 Apr 2022 14:07:57.686 # Failover election won: I'm the new master.
17830:S 26 Apr 2022 14:07:57.686 # configEpoch set to 29 after successful failover
17830:M 26 Apr 2022 14:07:57.686 # Connection with master lost.
17830:M 26 Apr 2022 14:07:57.686 * Caching the disconnected master state.
17830:M 26 Apr 2022 14:07:57.686 * Discarding previously cached master state.
17830:M 26 Apr 2022 14:07:57.686 # Setting secondary replication ID to 897d8ffc57482c31a6d37db92136073b713e813e, valid up to offset: 589309. New replication ID is 17e90a8ddf3d4fd645d4ec162267629a4109ea9f

...