Databases 6 min read

How to Build a Redis Master‑Slave Replication and Sentinel Cluster on CentOS 7

This guide walks through preparing three CentOS 7 servers, installing Redis 6.0.3, configuring master‑slave replication, handling common compilation errors, setting up system startup, adjusting firewall and Redis settings, and finally enabling Sentinel for high‑availability monitoring.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
How to Build a Redis Master‑Slave Replication and Sentinel Cluster on CentOS 7

Redis can distribute data across multiple servers to handle high concurrency and load, improving website performance and relieving MySQL read‑write pressure; therefore building a master‑slave replication and Sentinel cluster is essential for large‑scale sites.

Environment and versions : three CentOS 7 virtual machines with IPs 192.168.1.101, 192.168.1.102, 192.168.1.103 and Redis 6.0.3 (latest) installed under /usr/local/src .

Installation :

cd /usr/local/src
wget http://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 before rebuilding:

yum -y install gcc-c++
make clean
make CFLAGS="-march=x86-64"

Start the service using the configuration file:

redis-server /usr/local/src/redis.conf

Check the process with ps aux | grep redis and stop it if necessary using kill -9 <pid> . Enable daemon mode by adding daemonize yes to redis.conf .

Configure system startup :

mkdir /etc/redis
cp /usr/local/src/redis-6.0.3/redis_init_script/init.d /etc/redis/redisd
chmod +x /etc/redis/redisd
chkconfig redisd on

Control the service with service redisd start and service redisd stop .

Client connection settings : disable the firewall or open port 6379, then edit redis.conf to comment out the bind 127.0.0.1 line, set protected-mode no , and add authentication:

requirepass 123456
masterauth 123456

Sentinel mode (high‑availability): configure three servers as one master (192.168.1.101) and two slaves (192.168.1.102, 192.168.1.103). In the master’s redis.conf set the same password as above. In each slave’s redis.conf add:

slaveof 192.168.1.101 6379
masterauth 123456

Create sentinel.conf with the following key directives:

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 starting the master, the slaves, and Sentinel, the Redis cluster is fully operational and ready for production use.

DatabaseRedisCachingSentinelMaster-Slave ReplicationCentOS
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

login 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.