How-to Install a Redis Cluster on Ubuntu

Introduction

Redis is an in-memory data storage that is used by the CoreOne Suite. For supported versions see: Next-Gen Workflows - RedisUNDEFINED

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 (Cluster)

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:

sudo su

Create a Folder in /etc/redis in which Redis will be installed:

mkdir /etc/redis

Download Redis and unzipp the package

https://download.redis.io/releases/redis-6.2.6.tar.gz can also be downloaded on windows and copied to your linux instance.

wget https://download.redis.io/releases/redis-6.2.6.tar.gz tar xzf redis-6.2.6.tar.gz

This will create the folder /Files in /etc/redis.

Navigate with ‘cd’ to the folder /redis-6.2.6

Redis needs gcc, make and tcl. Those can be installed with the following command:

Check if the local firewall is active:

Open the needed Ports on the firewall:

Since we installed ‘make’, we have to exexute the File in etc/redis/redis-6.2.6/makefile

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.

We will create on VM01 the following config-Files →node1.conf / node4.conf . Those will be used to start redis.

Create config-file 1 & 4

If Vim is not installed yet, use the command “apt install vim” to install it.

Create the config-Files in the folder /etc/redis - to navigate there, use the following command:

Copy the following text to the config file:

Copy the following text to the config file:

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.

We will create on VM02 the following config-Files →node2.conf / node5.conf . Those will be used to start redis.

Create config-file 2 & 5

Create the config-Files in the folder /etc/redis - to navigate there, use the following command:

Copy the following text to the config file:

Copy the following text to the config file:

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.

We will create on VM03 the following config-Files →node3.conf / node6.conf . Those will be used to start redis.

Create config-file 3 & 6

Create the config-Files in the folder /etc/redis - to navigate there, use the following command:

Copy the following text:

Copy the following text:

Step 6 - Start Redis

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

To do this, navigate to the folder /etc/redis and execute the following commands:

Server

Instanz

Befehl

Server

Instanz

Befehl

HA1 (192.168.17.134)

Node 01 - Port 7001

Node 04 - Port 7004

HA 2 (192.168.17.135)

Node 02 - Port 7002

Node 05 - Port 7005

HA 3 (192.168.17.136)

Node 03 - Port 7003

Node 06 - Port 7006

Step 7 - Connect Redis

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

Server

Instanz

Befehl

Server

Instanz

Befehl

HA1 (192.168.17.134)

Node 01 - Port 7001

Node 04 - Port 7004

HA 2 (192.168.17.135)

Node 02 - Port 7002

Node 05 - Port 7005

HA 3 (192.168.17.136)

Node 03 - Port 7003

Node 06 - Port 7006

Step 8 - Configure Redis Cluster

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

Navigate to /etc/redis

Check the config and confirm with: Y

Step 9 - Redis-CLI

Open Redis-CLI:

ping

The different nodes can be pinged:

info

Shows all information on the cluster

cluster nodes

Shows all nodes and if they are master or slave.

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:

Shutdown the instance

On the masters 7001 and 7002 we will get the following message:

 

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 we start the Slave 7004, who is now a Master, the server will still be described as Slave.

 

Message after restart:

 

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

Message:

Check the cluster nodes:

 

© ITSENSE AG. Alle Rechte vorbehalten. ITSENSE und CoreOne sind eingetragene Marken der ITSENSE AG.