Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Multi Node Deployment - Redis

Introduction

Redis is an in-memory data structure store, used as a database, cache, and message broker. In a multi-node Redis deployment, we distribute the data across multiple Redis instances to achieve high availability and scalability.

Prerequisites

Before starting with the multi-node deployment of Redis, ensure you have the following:

  • Basic understanding of Redis and its commands.
  • Multiple servers or virtual machines with Redis installed.
  • Access to the command line interface of each server.

Step 1: Installing Redis

First, install Redis on each server. You can do this by running the following commands:

sudo apt update

sudo apt install redis-server

Step 2: Configuring Redis Instances

Next, configure each Redis instance. Open the Redis configuration file /etc/redis/redis.conf on each server and make the following changes:

  • Set the bind parameter to the server's IP address.
  • Set the port parameter to the desired port number.
  • Enable Redis to run as a daemon by setting daemonize yes.

bind 192.168.1.100

port 6379

daemonize yes

Step 3: Setting Up Redis Cluster

To set up a Redis cluster, follow these steps:

  1. Create a directory for the cluster configuration on each server.
  2. Generate unique IDs for each node.
  3. Start each Redis instance with the cluster configuration.

mkdir -p /var/lib/redis

redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes

Step 4: Creating the Cluster

Use the redis-cli tool to create the cluster. Run the following command on one of the servers:

redis-cli --cluster create 192.168.1.100:6379 192.168.1.101:6379 192.168.1.102:6379 --cluster-replicas 1

This command will create a Redis cluster with three nodes and one replica for each master node.

Step 5: Verifying the Cluster

To verify the cluster, run the following command:

redis-cli -c -h 192.168.1.100 -p 6379 cluster info

You should see the cluster information, confirming that your multi-node Redis deployment is successful.

Conclusion

Congratulations! You have successfully deployed a multi-node Redis cluster. This setup will help you achieve high availability and scalability for your Redis-based applications.