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
- Server with internet access
- Server without internet access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz# Download link for the Redis installation package, upload to the deployment server after download
https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.3-glibc2.17-amd64.tar.gz
mv redis-8.0.3-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.conf
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<'EOF'
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /usr/local/redis/redis.pid
loglevel notice
logfile /usr/local/redis/redis.log
databases 16
save 900 1
save 300 10
save 60 100000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 0 0 0
hz 10
requirepass 123456
masterauth 123456
maxmemory 16gb
maxmemory-policy allkeys-lru
maxclients 100000
rename-command KEYS ""
EOF- Redis authentication and master-slave authentication passwords are
123456. Please replace them in actual deployment.
- Redis authentication and master-slave authentication passwords are
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redis
chown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'
[Unit]
Description=Redis
[Service]
User=redis
Group=redis
TasksMax=infinity
LimitNOFILE=102400
LimitNPROC=infinity
LimitCORE=0
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/bin/kill $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Start the Redis service and enable it to start at boot
systemctl start redis
systemctl enable redis
Redis Slave-01
-
Download the Redis installation package
- Server with internet access
- Server without internet access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz# Download link for the Redis installation package, upload to the deployment server after download
https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.3-glibc2.17-amd64.tar.gz
mv redis-8.0.3-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.conf
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<'EOF'
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /usr/local/redis/redis.pid
loglevel notice
logfile /usr/local/redis/redis.log
databases 16
save 900 1
save 300 10
save 60 100000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 0 0 0
hz 10
requirepass 123456
masterauth 123456
maxmemory 16gb
maxmemory-policy allkeys-lru
maxclients 100000
rename-command KEYS ""
slaveof 192.168.1.13 6379
EOF- Redis authentication and master-slave authentication passwords are
123456. Please replace them in actual deployment. - Note to replace the master IP address in the
slaveofparameter during deployment
- Redis authentication and master-slave authentication passwords are
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redis
chown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'
[Unit]
Description=Redis
[Service]
User=redis
Group=redis
TasksMax=infinity
LimitNOFILE=102400
LimitNPROC=infinity
LimitCORE=0
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/bin/kill $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Start the Redis service and enable it to start at boot
systemctl start redis
systemctl enable redis
Redis Slave-02
-
Download the Redis installation package
- Server with internet access
- Server without internet access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz# Download link for the Redis installation package, upload to the deployment server after download
https://pdpublic.mingdao.com/private-deployment/offline/common/redis-8.0.3-glibc2.17-amd64.tar.gz -
Extract to the installation directory
tar -zxvf redis-8.0.3-glibc2.17-amd64.tar.gz
mv redis-8.0.3-glibc2.17-amd64 /usr/local/redis -
Adjust kernel parameters
echo 'net.core.somaxconn = 32768' >> /etc/sysctl.conf
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl -p -
Create Redis data directory
mkdir /data/redis -
Modify the configuration file
cat > /usr/local/redis/redis.conf <<EOF
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /usr/local/redis/redis.pid
loglevel notice
logfile /usr/local/redis/redis.log
databases 16
save 900 1
save 300 10
save 60 100000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 0 0 0
hz 10
requirepass 123456
masterauth 123456
maxmemory 16gb
maxmemory-policy allkeys-lru
maxclients 100000
rename-command KEYS ""
slaveof 192.168.1.13 6379
EOF- Redis authentication and master-slave authentication passwords are
123456. Please replace them in actual deployment. - Note to replace the master IP address in the
slaveofparameter during deployment
- Redis authentication and master-slave authentication passwords are
-
Create Redis user authorization
useradd -U -M -s /sbin/nologin redis
chown -R redis:redis /usr/local/redis/ /data/redis -
Configure systemd management
cat > /etc/systemd/system/redis.service <<'EOF'
[Unit]
Description=Redis
[Service]
User=redis
Group=redis
TasksMax=infinity
LimitNOFILE=102400
LimitNPROC=infinity
LimitCORE=0
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/bin/kill $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Start the Redis service and enable it to start at boot
systemctl start redis
systemctl enable redis
Check Master-Slave Synchronization Status
/usr/local/redis/bin/redis-cli -a 123456 info replication
Sentinel Configuration
Applicable to all three Redis servers
-
Configure sentinel configuration file
cat > /usr/local/redis/sentinel.conf <<'EOF'
port 26379
daemonize yes
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.10.13 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 30000
pidfile "/usr/local/redis/redis-sentinel.pid"
logfile "/usr/local/redis/redis-sentinel.log"
dir "/data/redis/sentinel"
EOF- Replace 192.168.10.13 with the actual current Redis Master node IP
123456is a sample password; replace it with a strong password consistent with the Redis node at deployment
-
Create directory and authorize Redis-related directory permissions
mkdir -p /data/redis/sentinel
chown -R redis:redis /data/redis /usr/local/redis -
Configure systemd management
cat > /etc/systemd/system/sentinel.service <<'EOF'
[Unit]
Description=Redis-sentinel
[Service]
User=redis
Group=redis
Type=forking
TasksMax=infinity
LimitNOFILE=102400
LimitNPROC=infinity
LimitCORE=0
ExecStart=/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel.conf
ExecStop=/usr/bin/kill $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Start the Sentinel
systemctl start sentinel
systemctl enable sentinel
Check Status
-
Check 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 -
Check the monitored slaves
/usr/local/redis/bin/redis-cli -a 123456 -p 26379 SENTINEL slaves mymaster