How to Build a Redis Cluster on a Single Linux Machine
This tutorial explains how to set up a six‑node Redis cluster (three masters and three slaves) on one Linux VM by creating separate directories and configuration files for each instance, installing Ruby tools, starting the instances, and using the redis‑trib.rb script to create and verify the cluster.
This article is the first part of a series introducing Redis clusters, focusing on the practical steps to build a simple cluster.
To create the most basic Redis cluster you need at least six nodes: three masters and three slaves. The three‑master design follows the common distributed‑system principle of having a majority for leader election.
To avoid the overhead of provisioning six separate machines, the guide adopts a “lazy” method: run six Redis instances on a single Linux virtual machine, each bound to a unique port and data directory, effectively simulating six separate hosts.
Step 1: Create separate directories for each of the six instances to store their data and configuration files.
Step 2: Copy the default redis.conf file six times and edit each copy so that the instances use different ports, enable AOF, enable cluster mode, and run as daemons.
Step 3: Install the Ruby runtime and required gems because the cluster creation will be performed with the redis-trib.rb script. The required packages are installed via yum install ruby, yum install rubygems, and gem install redis.
Step 4: Start all six Redis instances, which can be verified by checking that each instance is listening on its configured port.
Next, use the Ruby script to create the cluster. The command is:
[root@mydream121 bin]# ./redis-trib.rb create --replicas 1 192.168.99.121:8001 192.168.99.121:8002 192.168.99.121:8003 192.168.99.121:8004 192.168.99.121:8005 192.168.99.121:8006The --replicas 1 option means each master will have one slave, resulting in three master‑slave pairs ordered by the IP:PORT list.
The article also explains the concept of slots in Redis Cluster: each master owns a range of slots where data is stored, while slaves do not own slots and are read‑only replicas. This differs from the older Redis 1.x master‑slave model where data is fully replicated.
Step 5: Verify the cluster’s health using redis-cli cluster info and redis-cli cluster nodes, confirming that the masters and slaves are correctly assigned and that slot distribution is as expected.
With these steps completed, the Redis cluster is fully operational.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
