Redis Sentinel Mode
| Server IP | Host Role |
|---|---|
| 192.168.10.13 | Redis Master |
| 192.168.10.14 | Redis Slave1 |
| 192.168.10.15 | Redis Slave2 |
Redis Master
-
Download the Redis installation package
- Internet-accessible server
- Non-Internet-accessible server
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz# Redis installation package download link; upload to the deployment server once downloadedhttps://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.4-glibc2.17-amd64.tar.gzmv redis-8.0.4-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.d/99-sysctl.confecho 'vm.overcommit_memory = 1' >> /etc/sysctl.d/99-sysctl.confsysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<'EOF'bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised nopidfile /usr/local/redis/redis.pidloglevel noticelogfile /usr/local/redis/redis.logdatabases 16save 900 1save 300 10save 60 100000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redisslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 0 0 0hz 10requirepass 123456masterauth 123456maxmemory 16gbmaxmemory-policy allkeys-lrumaxclients 100000rename-command KEYS ""EOF- The password for Redis authentication and master-slave authentication is
123456; it must be changed to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed; characters like@ ! # &are prohibited to avoid compatibility issues.
- The password for Redis authentication and master-slave authentication is
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redischown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'[Unit]Description=Redis[Service]User=redisGroup=redisTasksMax=infinityLimitNOFILE=102400LimitNPROC=infinityLimitCORE=0ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.confExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Redis service and enable it on system boot
systemctl start redissystemctl enable redis
Redis Slave-01
-
Download the Redis installation package
- Internet-accessible server
- Non-Internet-accessible server
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz# Redis installation package download link; upload to the deployment server once downloadedhttps://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.4-glibc2.17-amd64.tar.gzmv redis-8.0.4-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.d/99-sysctl.confecho 'vm.overcommit_memory = 1' >> /etc/sysctl.d/99-sysctl.confsysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<'EOF'bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised nopidfile /usr/local/redis/redis.pidloglevel noticelogfile /usr/local/redis/redis.logdatabases 16save 900 1save 300 10save 60 100000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redisslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 0 0 0hz 10requirepass 123456masterauth 123456maxmemory 16gbmaxmemory-policy allkeys-lrumaxclients 100000rename-command KEYS ""slaveof 192.168.1.13 6379EOF- The password for Redis authentication and master-slave authentication is
123456; it must be changed to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed; characters like@ ! # &are prohibited to avoid compatibility issues. - Replace the master IP in the
slaveofparameter during actual deployment.
- The password for Redis authentication and master-slave authentication is
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redischown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'[Unit]Description=Redis[Service]User=redisGroup=redisTasksMax=infinityLimitNOFILE=102400LimitNPROC=infinityLimitCORE=0ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.confExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Redis service and enable it on system boot
systemctl start redissystemctl enable redis
Redis Slave-02
-
Download the Redis installation package
- Internet-accessible server
- Non-Internet-accessible server
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz# Redis installation package download link; upload to the deployment server once downloadedhttps://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.4-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.4-glibc2.17-amd64.tar.gzmv redis-8.0.4-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.d/99-sysctl.confecho 'vm.overcommit_memory = 1' >> /etc/sysctl.d/99-sysctl.confsysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<EOFbind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised nopidfile /usr/local/redis/redis.pidloglevel noticelogfile /usr/local/redis/redis.logdatabases 16save 900 1save 300 10save 60 100000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redisslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 0 0 0hz 10requirepass 123456masterauth 123456maxmemory 16gbmaxmemory-policy allkeys-lrumaxclients 100000rename-command KEYS ""slaveof 192.168.1.13 6379EOF- The password for Redis authentication and master-slave authentication is
123456; it must be changed to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed; characters like@ ! # &are prohibited to avoid compatibility issues. - Replace the master IP in the
slaveofparameter during actual deployment.
- The password for Redis authentication and master-slave authentication is
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redischown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'[Unit]Description=Redis[Service]User=redisGroup=redisTasksMax=infinityLimitNOFILE=102400LimitNPROC=infinityLimitCORE=0ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.confExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Redis service and enable it on system boot
systemctl start redissystemctl enable redis
Check Master-Slave Synchronization Status of Each Node
/usr/local/redis/bin/redis-cli -a 123456 info replication
Sentinel Configuration
Perform operations on all three Redis servers
-
Configure the sentinel configuration file
cat > /usr/local/redis/sentinel.conf <<'EOF'port 26379daemonize yessentinel deny-scripts-reconfig yessentinel monitor mymaster 192.168.10.13 6379 2sentinel auth-pass mymaster 123456sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 30000pidfile "/usr/local/redis/redis-sentinel.pid"logfile "/usr/local/redis/redis-sentinel.log"dir "/data/redis/sentinel"maxclients 100000EOF- Note to replace 192.168.10.13 with the actual current Redis Master node IP address.
123456is a sample password; please change it to a strong password consistent with the Redis node upon deployment.- If the password contains special characters, only
-or_are allowed; characters like@ ! # &are prohibited to avoid compatibility issues.
-
Create the directory and authorize Redis-related directory permissions
mkdir -p /data/redis/sentinelchown -R redis:redis /data/redis /usr/local/redis -
Configure systemd management
cat > /etc/systemd/system/sentinel.service <<'EOF'[Unit]Description=Redis-sentinel[Service]User=redisGroup=redisType=forkingTasksMax=infinityLimitNOFILE=102400LimitNPROC=infinityLimitCORE=0ExecStart=/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel.confExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start the sentinel
systemctl start sentinelsystemctl enable sentinel
Check Status
-
View Sentinel Status
/usr/local/redis/bin/redis-cli -a 123456 -p 26379 info sentinel -
Get Current Master Information
/usr/local/redis/bin/redis-cli -a 123456 -p 26379 SENTINEL get-master-addr-by-name mymaster -
View Monitored Slave Databases
/usr/local/redis/bin/redis-cli -a 123456 -p 26379 SENTINEL slaves mymaster