Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How To Setup A Redis Server Cluster on Red Hat

June 9, 2017
David Kittell
Related topics:
Developer Tools
Related products:
Developer Tools

Share:

    So, you’ve been told you need to build a Redis Server Cluster. First, if you don’t know what Redis is you are probably thinking, “What is this weird named thing and what do I need to do”. This guide will walk you through both in a way that will hopefully be easy to follow and be easy to repeat in the future.

    While you can have more than three servers in a Redis cluster for the sake of simplicity, we will cover setting up a three server Redis cluster. In our three servers cluster, we will have two Redis servers with one Redis Sentinel with HAProxy to assist the Sentinel.

    Much of this guide will work with a tested code stored in GitLab (https://gitlab.com/Kittell-Projects/RedHat/Redis) to make it easier to build the cluster. While this code is tested, it is suggested to build in a development environment first.

    What is Redis?

    In short, Redis is three or more server operational database cluster that is used for various tasks.

    Retrieved June 1, 2017, from https://redis.com/company/
    Redis, a database benchmarked (https://redislabs.com/cbc-2015-15-nosql-benchmark) as the world’s fastest, reduces application complexity, simplifies development, accelerates time to market and provides unprecedented flexibility to developers with its visionary data structures and modules.

    Retrieved June 1, 2017, from https://redis.io/
    Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, and sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

    Who Owns Redis?

    While there is an enterprise option, Redis is open source. What this means is that you can use it for free in your projects or you can pay for premium service and support.

    • Redis.IO (the Open Source option) is run by Salvatore Sanfilippo with the help of sponsors.
    • RedisLabs.com (the Enterprise option) is run by Co-Founders Ofer Bengal (CEO) and Yiftach Shoolman (CTO) with Salvatore Sanfilippo as lead open source developer.

    GitLab Scripts

    If you are new to automation scripts and Git repositories this may seem a bit weird or uneasy to trust a script, for those that would like to see the scripts and what they do before you run them please follow these links:

    • Base Template - https://gitlab.com/Kittell-Projects/RedHat/BaseTemplate/raw/master/Base.sh
      This script will run on each of the servers to validate Red Hat subscription and install basic tools.
    • Setup Banner - https://gitlab.com/Kittell-Projects/RedHat/BaseTemplate/raw/master/setup-banner.sh
      This script will optionally run on each of the servers to setup SSH login banners.
    • Node Configuration - https://gitlab.com/Kittell-Projects/RedHat/Redis/raw/master/NodeConfiguration.sh
      This script will run on each of the servers to define the Redis Node.
    • Redis Setup - https://gitlab.com/Kittell-Projects/RedHat/Redis/raw/master/Redis.sh
      This script will first call to Base, then the Node Configuration and finish with node specific setup.

    Setup Redis

    Some Assumptions:

    • User has root permission or is root
    • Servers are properly registered with Red Hat

    Steps

    1. Get three servers setup with Red Hat 7.3 or newer. If you have not setup Red Hat before please refer to the installation guide (https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/index) to get started.
      1. In this guide, we will concentrate mostly in terminal shell/bash scripting of the cluster so you do not need the graphical user interface (GUI).
      2. Each server should have a static IP, it is typically best if you assign them in the installation process if you can but if not you can run this first script to get your network adapter and IP address.

        #Get Network Adapter and IP address
        ifconfig | grep inet -B1 | grep -v inet6

        Example:
        In this example, the network adapter you would choose to use is eth zero; depending on the configuration it could be eth(number) or en(number).

        eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
                inet 10.211.55.6  netmask 255.255.255.0  broadcast 10.211.55.255
        --
        lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
                inet 127.0.0.1  netmask 255.0.0.0
        --
        
      3. This script will set a static IP address, make sure you run the above script though to get the correct adapter.

        #Set Static IP address
        sudo ifconfig eth0 10.40.20.20 netmask 255.255.255.0
        sudo route add default gw 10.40.20.1
        
    2. On each server run this script.

      sh -c "$(curl -s "https://gitlab.com/Kittell-Projects/RedHat/Redis/raw/master/Redis.sh")"

      This script will:

      • First check the Red Hat server is properly registered with Red Hat; if the server is not registered, the script will assist in the registration.
      • Enable additional official Yum Repositories
      • Create a Yum Cache
      • Run a Yum Update
      • Verify the time zone is setup on the server to your desired setting, if it is not the script will assist in the setting.
        NOTE: The script looks specifically for the "tz database" format as defined on https://access.redhat.com/documentation/en-us/red_hat_virtualization/4.4
      • Install basic tools
      • Optionally set SSH banner text
      • Install needed Redis components on a node-specific configuration
      • Reboot the specific server

    Once you have ran the script on all three servers your Redis Cluster is built and ready for your project.

    Note: Just in case you are not familiar with Redis, your application that uses Redis should connect to node 3 as that will do the work to determine which server the work needs to go to.

    HAProxy - Manage Redis

    Redis - HAProxy ExampleWhen the scripts are done on all three servers, you should be able to go to the HAProxy site to get a status and run management tasks.

    • HAProxy can be reached at http://(node3IP):9000/haproxy_stats
    • Default credentials:
      • Username: admin
      • Password: passwordhere

    Useful Scripts

    1. You can test the cluster on node1 and node2 with the script below.

      config="/opt/redis/node.conf"
      declare netadapter="$(grep "nodeAdapter" "$config" | awk -F'=' '{print $2}')"
      declare ip=$(/sbin/ip -o -4 addr list $netadapter | awk '{print $4}' | cut -d/ -f1)
      redis-benchmark -h $ip -q -n 1000 -c 10 -P 5 # Test Redis
      

      Example:

      redis-benchmark -h $ip -q -n 1000 -c 10 -P 5 # Test Redis
      PING_INLINE: 333333.34 requests per second
      PING_BULK: 499999.97 requests per second
      SET: 999999.94 requests per second
      GET: 499999.97 requests per second
      INCR: 499999.97 requests per second
      LPUSH: 499999.97 requests per second
      RPUSH: 499999.97 requests per second
      LPOP: 499999.97 requests per second
      RPOP: 499999.97 requests per second
      SADD: 499999.97 requests per second
      SPOP: 499999.97 requests per second
      LPUSH (needed to benchmark LRANGE): 499999.97 requests per second
      LRANGE_100 (first 100 elements): 499999.97 requests per second
      LRANGE_300 (first 300 elements): 499999.97 requests per second
      LRANGE_500 (first 450 elements): 999999.94 requests per second
      LRANGE_600 (first 600 elements): 999999.94 requests per second
      MSET (10 keys): 333333.34 requests per second
    2. Connect to Redis

      redis-cli -h 10.211.55.9 # Change IP/Node as necessary
    3. Configure/Reconfigure Slave (Once connected to Redis)

      slaveof noone # Run on the master node
      slaveof 10.211.55.9 # Slave of Node 1, change IP and node as necessary

    Take advantage of your Red Hat Developers membership and download RHEL today at no cost.

    Last updated: May 31, 2024

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue