Databases 20 min read

How to Install and Build a Redis Cluster on CentOS: Step‑by‑Step Guide

This article explains what Redis Cluster is, how it partitions data and provides redundancy, and walks through installing Redis on CentOS, configuring multiple nodes, and creating a functional cluster using both manual commands and the built‑in cluster management tool.

Programmer DD
Programmer DD
Programmer DD
How to Install and Build a Redis Cluster on CentOS: Step‑by‑Step Guide

Redis Cluster Overview

Redis Cluster, introduced in Redis 3.0, is a decentralized distributed storage solution composed of multiple interconnected nodes. Clients can connect to any node to access key‑value pairs, and the cluster automatically redirects requests to the node holding the requested key.

The cluster forms a mesh where each node maintains TCP connections to every other node, resulting in N‑1 inbound and outbound connections per node.

Redis Cluster provides two main functions:

Data Partitioning – User data is distributed across nodes using 16,384 hash slots. Keys are hashed with CRC16, the result modulo 16384 determines the slot, and slots are evenly mapped to nodes.

Data Redundancy – Each master node must have at least one slave. If a master fails, its slaves request votes from other masters; the elected slave becomes the new master and takes over the failed master's slots.

For detailed implementation, refer to the official Redis Cluster tutorial and specification.

Download & Install Redis

Experiment environment: CentOS Linux release 7.4.1708, Redis version 5.0.3

Install a single‑node Redis if not already present: cd /usr/local Download and extract the source package:

wget http://download.redis.io/releases/redis-5.0.3.tar.gz
 tar -zxvf redis-5.0.3.tar.gz

Compile and install:

cd redis-5.0.3
 make && make install

If compilation fails due to missing GCC, install it and rebuild:

yum -y install gcc
 make distclean
 make && make install

Successful installation places binaries in /usr/local/bin (e.g., redis-server, redis-cli).

Build a Redis Cluster

A functional cluster requires at least three master nodes, each with a slave, for a total of six nodes.

In a test environment we simulate the six nodes on a single machine using different ports.

Manual Setup

Start Nodes

Create directories for each node’s configuration:

mkdir /usr/local/redis-cluster
 cd /usr/local/redis-cluster
 mkdir -p 7001 7002 7003 8001 8002 8003

Copy the default redis.conf into each directory and edit the relevant parameters (example for node A):

bind 192.168.83.128
port 7001
pidfile /var/run/redis_7001.pid
daemonize yes
cluster-enabled yes
cluster-node-timeout 15000
cluster-config-file nodes-7001.conf

Start all six nodes:

/usr/local/bin/redis-server /usr/local/redis-cluster/7001/redis.conf
/usr/local/bin/redis-server /usr/local/redis-cluster/7002/redis.conf
/usr/local/bin/redis-server /usr/local/redis-cluster/7003/redis.conf
/usr/local/bin/redis-server /usr/local/redis-cluster/8001/redis.conf
/usr/local/bin/redis-server /usr/local/redis-cluster/8002/redis.conf
/usr/local/bin/redis-server /usr/local/redis-cluster/8003/redis.conf

Verify the processes are running with ps -ef|grep redis.

Node Handshake

Connect the nodes using cluster meet commands (executed from node A):

cluster meet 127.0.0.1 7002
cluster meet 127.0.0.1 7003
cluster meet 127.0.0.1 8001
cluster meet 127.0.0.1 8002
cluster meet 127.0.0.1 8003

After the commands, each node can reach the others, forming a full mesh.

Assign Slots

Allocate the 16,384 hash slots evenly among the three masters:

/usr/local/bin/redis-cli -p 7001 cluster addslots {0..5461}
/usr/local/bin/redis-cli -p 7002 cluster addslots {5462..10922}
/usr/local/bin/redis-cli -p 7003 cluster addslots {10923..16383}

Check the cluster state; it should report cluster_state:ok.

Configure Replication

Assign each slave to its master using cluster replicate with the master’s node‑id:

/usr/local/bin/redis-cli -p 8001 cluster replicate 61e8c4ed8d1ff2a765a4dd2c3d300d8121d26e12
/usr/local/bin/redis-cli -p 8002 cluster replicate 1b4b3741945d7fed472a1324aaaa6acaa1843ccb
/usr/local/bin/redis-cli -p 8003 cluster replicate 19147f56e679767bcebb8653262ff7f56ca072a8

The cluster is now fully operational with masters and slaves.

Automatic Setup

Redis 5.0+ includes the --cluster option in redis-cli. After starting the six nodes, run:

/usr/local/bin/redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 --cluster-replicas 1

The tool allocates slots, creates replicas, and finalizes the cluster in a single command.

All 16,384 slots are covered and the cluster reports OK .
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseredisClusterInstallation
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.