Question: How can you set up a Redis cluster with 2 nodes?
Answer
Setting up a Redis cluster with two nodes involves the following steps:
- Install Redis: You need to install Redis on each node. Use your OS package manager, or download and compile Redis from source.
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make
- Configure each Redis instance for clustering: Modify the
redis.conf
file for each instance. Set thecluster-enabled
option toyes
, specify acluster-config-file
, and provide acluster-node-timeout
.
# redis.conf cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes
- Start the Redis instances: Start each Redis instance using their specific
redis.conf
files.
src/redis-server /path/to/redis.conf
- Create the Cluster: Use the
redis-cli
utility to create the cluster. Consider the IP addresses are192.168.1.1
and192.168.1.2
and they are both running Redis on port7000
.
redis-cli --cluster create 192.168.1.1:7000 192.168.1.2:7000
- Follow the prompts: The
redis-cli
utility will propose a configuration. Accept it.
Please note that Redis cluster requires at least three master nodes for robust failover and distributed storage. A cluster with only two nodes does not guarantee high availability. It's better to use a setup with at least three nodes if you want high availability and partition tolerance.
Was this content helpful?
Other Common Redis Questions (and Answers)
- What is the default port used by Redis?
- How to start Redis server?
- Is Redis persistent?
- How fast is Redis?
- How to install Redis on Mac?
- How to check if Redis is running?
- How to restart Redis?
- Does Redis persist data?
- How to install Redis on Ubuntu?
- How to stop Redis server?
- How to see Redis version?
- Does Redis have tables?
White Paper
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost