How to Install Redis Cluster: A Step-by-Step Guide
Redis is a powerful in-memory data store widely used for caching, real-time analytics, and messaging. Installing a Redis Cluster enhances Redis with distributed data storage and high availability. This tutorial will guide you through installing a Redis Cluster from scratch, covering prerequisites, installation, cluster creation, and basic troubleshooting tips.
Prerequisites
- Operating System: Linux distribution (Ubuntu, CentOS, etc.) or compatible Unix-like OS
- Redis Version: Redis 3.0 or higher (cluster mode introduced in 3.0+)
- Basic Linux command line knowledge
- At least 3 machines or at least 6 Redis instances on a single machine for a functional cluster with replicas
- Ports 6379-6385 open (one port per Redis instance) for cluster communication
- TCP networking enabled between nodes
Step 1: Download and Install Redis
First, install Redis on all machines that will run nodes for the cluster. You can install a stable Redis version from source or package manager. For the latest stable Redis (recommended), install from source:
sudo apt update
sudo apt install build-essential tcl
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
make
sudo make install
This installs the redis-server and redis-cli binaries globally.
Step 2: Prepare Redis Instances
For a cluster, you need multiple Redis instances, each listening on different ports.
- Create separate directories for each instance, e.g.,
/etc/redis/7000,/etc/redis/7001, etc. - Copy a base Redis config file into each directory and customize:
mkdir -p /etc/redis/7000
cp redis-stable/redis.conf /etc/redis/7000/
Edit each redis.conf to set:
port 7000(or whichever port you assign)cluster-enabled yescluster-config-file nodes-7000.confcluster-node-timeout 5000appendonly yesfor data persistence (optional but recommended)daemonize yesto run as background service
Step 3: Start Redis Instances
Start each Redis instance with its own config:
redis-server /etc/redis/7000/redis.conf
redis-server /etc/redis/7001/redis.conf
redis-server /etc/redis/7002/redis.conf
# Repeat for all instances
Step 4: Create the Cluster
Use redis-cli to create the cluster. You must specify the IP/hostname and port of all master and replica nodes.
redis-cli --cluster create \
192.168.1.10:7000 192.168.1.11:7001 192.168.1.12:7002 \
192.168.1.10:7003 192.168.1.11:7004 192.168.1.12:7005 \
--cluster-replicas 1
This command will assign slots across masters and replicas. Confirm the prompt by typing yes.
Step 5: Verify the Cluster
Run the following command to check cluster nodes and status:
redis-cli -c -p 7000 cluster nodes
You should see nodes with their IDs, roles (master/slave), and slot assignments.
Troubleshooting Tips
- Ports not open: Ensure firewall rules allow communication on all Redis ports.
- Cluster creation errors: Check that all nodes can reach each other via ping/netcat and have compatible Redis versions.
- Data loss concerns: Use
appendonly yesin config for persistence and backups. - Timeouts: Increase
cluster-node-timeoutif nodes are slow to respond.
Summary Checklist
- Install Redis 3.0 or higher on each machine
- Configure each Redis node with cluster mode enabled
- Start Redis instances on unique ports
- Run
redis-cli --cluster createwith all node addresses - Verify cluster is healthy with
cluster nodes - Configure persistence and backups to protect data
Redis Cluster provides scalable and highly available Redis databases for your applications. For more on installing specialized databases, see our guide on <a href="/
