Redis Master-Slave Mode
| Server IP | Host Role |
|---|---|
| 192.168.10.13 | Redis Master |
| 192.168.10.14 | Redis Slave |
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.4-glibc2.17-amd64.tar.gz# Redis installation package download link, upload to deployment server after downloadhttps://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 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 10gbmaxmemory-policy allkeys-lrumaxclients 100000rename-command KEYS ""EOF- The password for Redis authentication and master-slave authentication is
123456. It is mandatory to change it to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed. Avoid using@ ! # &to prevent 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 the Redis service and enable it to start on boot
systemctl start redissystemctl enable redis -
Test Redis connection login
/usr/local/redis/bin/redis-cli -a 123456
Redis Slave
-
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.4-glibc2.17-amd64.tar.gz# Redis installation package download link, upload to deployment server after downloadhttps://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 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 10gbmaxmemory-policy allkeys-lrumaxclients 100000rename-command KEYS ""slaveof 192.168.1.13 6379EOF- The password for Redis authentication and master-slave authentication is
123456. It is mandatory to change it to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed. Avoid using@ ! # &to prevent compatibility issues. - Note that the Redis master IP address should be replaced 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 the Redis service and enable it to start on boot
systemctl start redissystemctl enable redis -
Test Redis connection login
/usr/local/redis/bin/redis-cli -a 123456
Check Master-Slave Synchronization Status
/usr/local/redis/bin/redis-cli -a 123456 info replication