Databases 6 min read

Step-by-Step Guide to Setting Up Redis Master‑Slave Replication and Sentinel Cluster on CentOS 7

This tutorial walks through preparing three CentOS 7 servers, installing and compiling Redis 6.0.3, configuring master‑slave replication, setting up Sentinel for high availability, adjusting firewall and Redis configuration, and managing the services to achieve a fully functional Redis cluster.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Step-by-Step Guide to Setting Up Redis Master‑Slave Replication and Sentinel Cluster on CentOS 7

This guide explains how to build a Redis master‑slave replication and Sentinel cluster on three CentOS 7 machines, which improves performance and provides high‑availability for web applications.

1. Environment preparation : allocate three Linux servers (e.g., 192.168.1.101‑103) and ensure Redis 6.0.3 is available.

2. Install and compile Redis :

# cd /usr/local/src
# wget https://download.redis.io/releases/redis-6.0.3.tar.gz
# tar xzf redis-6.0.3.tar.gz
# cd redis-6.0.3
# make

If compilation fails, install the C++ compiler and clean previous builds:

# yum -y install gcc-c++
# make clean
# make

After a successful build, start the server:

# cd src
# ./redis-server ../redis.conf

3. Configure daemon and process management : daemonize yes Check the running process and stop it if necessary:

# ps -aux | grep redis
# kill -9 <pid>

4. Enable service at boot :

# mkdir /etc/redis
# cp /usr/local/src/redis-6.0.3/redis.conf /etc/redis/6379.conf
# cp /usr/local/src/redis-6.0.3/utils/redis_init_script /etc/init.d/redisd
# chkconfig redisd on

Start and stop the service with:

# service redisd start
# service redisd stop

5. Adjust firewall and Redis configuration :

# systemctl stop firewalld   # or open port 6379
# In redis.conf comment out "bind 127.0.0.1" and set "protected-mode no"
# requirepass 123456
# masterauth 123456

6. Set up slave servers in their redis.conf:

slaveof 192.168.1.101 6379
requirepass 123456
masterauth 123456

7. Configure Sentinel (sentinel.conf):

protected-mode no
sentinel monitor mymaster 192.168.1.101 6379 2
sentinel auth-pass mymaster 123456

Start Sentinel with:

# ./redis-server /path/to/sentinel.conf --sentinel

After launching the master, slaves, and Sentinel, verify the cluster is operational and that failover works as expected.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CachedatabaseredisLinuxReplicationsentinelCentOS
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.