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.
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
# makeIf compilation fails, install the C++ compiler and clean previous builds:
# yum -y install gcc-c++
# make clean
# makeAfter a successful build, start the server:
# cd src
# ./redis-server ../redis.conf3. 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 onStart and stop the service with:
# service redisd start
# service redisd stop5. 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 1234566. Set up slave servers in their redis.conf:
slaveof 192.168.1.101 6379
requirepass 123456
masterauth 1234567. Configure Sentinel (sentinel.conf):
protected-mode no
sentinel monitor mymaster 192.168.1.101 6379 2
sentinel auth-pass mymaster 123456Start Sentinel with:
# ./redis-server /path/to/sentinel.conf --sentinelAfter launching the master, slaves, and Sentinel, verify the cluster is operational and that failover works as expected.
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.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
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.
