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.
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
makeIf 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.confCheck 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 onControl 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 123456Sentinel 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 123456Create sentinel.conf with the following key directives:
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 starting the master, the slaves, and Sentinel, the Redis cluster is fully operational and ready for production use.
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.