DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Techniques for Chaos Testing Your Redis Cluster
  • How To Manage Redis Cluster Topology With Command Line
  • OpenShift Container Platform 4.11 Cluster Setup
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot

Trending

  • Infrastructure as Code (IaC) Beyond the Basics
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • Designing for Sustainability: The Rise of Green Software
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Quickly Create and Easily Configure a Local Redis Cluster

How to Quickly Create and Easily Configure a Local Redis Cluster

This tutorial talks about how to quickly create and easily configure a local Redis cluster for testing or troubleshooting with minimal modifications and more control.

By 
Rahul Chaturvedi user avatar
Rahul Chaturvedi
·
May. 24, 24 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
4.6K Views

Join the DZone community and get the full member experience.

Join For Free

Context

Do you crave hands-on experience with Redis clusters? Perhaps you're eager to learn its intricacies or conduct targeted testing and troubleshooting. A local Redis cluster empowers you with that very control. By setting it up on your own machine, you gain the freedom to experiment, validate concepts, and delve deeper into its functionality. This guide will equip you with the knowledge to quickly create and manage a Redis cluster on your local machine, paving the way for a productive and insightful learning journey.

Install Redis

The first step would be to install a Redis server locally. Later cluster creation commands will use Redis instances as building blocks and combine them into a cluster.

Mac

The easiest way would be to install using Homebrew. Use the following command to install Redis on your Macbook.

Shell
 
brew install redis


Linux

Use the following command to install.

Shell
 
sudo apt update 
sudo apt install redis-server


From the Source

If you need a specific version then you can use this method of installation. For this, you can use the following steps:

  • Download the latest Redis source code from the official website.
  • Unpack the downloaded archive.
  • Navigate to the extracted directory in your terminal.
  • Run the following commands:
Shell
 
make
sudo make install


Create Cluster

One Time Steps

  • Clone the git repository 
  • Go to the directory where you cloned the repository
  • Then go to the following directory
Shell
 
cd <path to local redis repository>/redis/utils/create-cluster


  • Modify create-cluster with the path to your Redis-server
Shell
 
vi create-cluster


Replace BIN_PATH="$SCRIPT_DIR/../../src/" with BIN_PATH="/usr/local/bin/"

Steps to Create/Start/Stop/Clean Cluster

These steps are used whenever you need to use a Redis Cluster.

Start the Redis Instances

Shell
 
./create-cluster start


Create the Cluster 

Shell
 
echo "yes" | ./create-cluster create


Tip

You can create an alias and add it to the shell configuration files (~/.bashrc or ~./zshrc)

Example:

Shell
 
open ~/.zshrc


Add the following to this file.

Shell
 
alias cluster_start="./create-cluster start && echo "yes" | ./create-cluster create"


Open a new terminal and run the following.

Shell
 
source ~/.zshrc


Now you use “cluster_start” in the command line and it will start and create the cluster for you.

Stop the Cluster

Shell
 
./create-cluster stop


Clean Up 

Clears previous cluster data for a fresh start.

Shell
 
./create-cluster clean


Tip

Similarly, you can create an alias as below to stop the cluster and clean the cluster data files.

Shell
 
alias cluster_stop="./create-cluster stop && ./create-cluster clean”


How To Create the Cluster With a Custom Number of Nodes by Default

By default cluster-create script creates 6 nodes with 3 primaries and 3 replicas. For some special testing or troubleshooting if you need to change the number of nodes you can modify the script instead of manually adding nodes.

Shell
 
vi create-cluster


Edit the following to the desired number of nodes for the cluster.

NODES=6

Also, by default, it creates 1 replica for a primary. You can change that as well by changing the value in the same script (create-cluster) to the desired value.

REPLICAS=1

Create Cluster With Custom Configuration

Redis provides various options to customize the configuration to configure Redis servers the way you want. All those are present in the redis.conf file. In order to customize those with the desired options follow these steps:

Edit the redis.conf With Desired Configurations

Shell
 
cd <path to local redis repository>/redis/redis.conf


Edit the create-cluster Script

Shell
 
vi create-cluster


Modify the command in the start and restart options of the script to add the following 

../../redis.conf

Before Modification

Shell
 
$BIN_PATH/redis-server --port $PORT --protected-mode $PROTECTED_MODE --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --appenddirname appendonlydir-${PORT} --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes ${ADDITIONAL_OPTIONS}


After Modification

Shell
 
$BIN_PATH/redis-server ../../redis.conf --port $PORT --protected-mode $PROTECTED_MODE --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --appenddirname appendonlydir-${PORT} --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes ${ADDITIONAL_OPTIONS}


For reference please see the snippet below after modification in the start option:

snippet

References

GitHub Redis

Redis.git

cluster Redis (company) Linux (operating system)

Opinions expressed by DZone contributors are their own.

Related

  • Techniques for Chaos Testing Your Redis Cluster
  • How To Manage Redis Cluster Topology With Command Line
  • OpenShift Container Platform 4.11 Cluster Setup
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: