Master Redis Cluster Setup: From Basics to Scaling Nodes
Learn how to build and manage a Redis cluster on Linux, covering the rationale for clustering, hash slot mechanics, node configuration, adding/removing nodes, resharding, and integrating master‑slave replicas, with step‑by‑step commands and practical examples.
Why Use Redis Cluster
Cluster technology is essential for high‑performance website architectures. By sharding data across multiple servers, we reduce the load on any single node and improve response times under high concurrency.
Implementation Strategy
Since Redis 3.0, official support for Redis Cluster is available. Keys are distributed across nodes using hash slots: Redis computes a CRC16 hash of the key, takes the modulo 16384, and maps the resulting slot to a node. This design simplifies adding or removing nodes because slots can be reassigned without restarting the cluster.
Cluster Implementation
Create three directories (6000, 6100, 6200) under a redis_cluster folder, copy redis-server and redis.conf into each, and edit the configuration to set the appropriate port and enable clustering.
daemonize yes
port 6000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yesStart each instance with ./redis-server ./redis.conf, then create the cluster using the Ruby tool:
./redis-trib.rb create --replicas 0 127.0.0.1:6000 127.0.0.1:6100 127.0.0.1:6200If the redis-trib.rb script is missing, install Ruby and the Redis gem, then retry.
Cluster Changes
To add a new node (e.g., port 6300), create its directory, copy the binaries, adjust redis.conf, and start the instance. Then add it to the cluster:
./redis-trib.rb add-node 127.0.0.1:6300 127.0.0.1:6000After adding, assign hash slots to the new node using resharding: ./redis-trib.rb reshard 127.0.0.1:6300 Specify the number of slots to move (e.g., 1000) and the destination node ID. The CRC16 algorithm determines which keys map to the newly assigned slots.
How to Add a Slave to Each Master Node
Create a new instance on port 6400, configure it similarly, and add it as a slave:
./redis-trib.rb add-node --slave 127.0.0.1:6400 127.0.0.1:6000Note that slave nodes accept read commands only; attempts to write (e.g., SET) will return an error.
How to Delete a Node
Attempting to delete a node with data fails until the data is moved. Use resharding to migrate slots away from the node, then delete it:
./redis-trib.rb reshard 127.0.0.1:6000 # move slots to another node
./redis-trib.rb del-node 127.0.0.1:6000 <node-id>After successful deletion, the node no longer accepts connections.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
