Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The significance of redis Master-Slave replication failure recovery and persistence

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Server configuration: (centos7)

Server IP installation component Node Note 192.168.27.210redis-5.0.5master one Master and two Slave Architecture 192.168.26.112redis-5.0.5slave192.168.26.206redis-5.0.5slave

Download the latest version to each node: Wget http://download.redis.io/releases/redis-5.0.5.tar.gz

Extract the package and configure:

Switch users (production environment uses less ROOT user operations)

[jerry@master data] $sudo chown-R jerry.root redis-5.0.5

Cd / data/redis-5.0.5/src

Make

192.168.27.210 configuration file: vim / data/redis-5.0.5/redis-m-7000.conf

Bind 0.0.0.0

Port 7000

Logfile "7000.log"

Dbfilename "dump-7000.rdb"

Daemonize yes

Rdbcompression yes

192.168.26.112 configuration:

Cd / data/redis-5.0.5/src

Make

[jerry@BDDB redis-5.0.5] $vim / data/redis-5.0.5/redis-s-7000.conf

Bind 0.0.0.0

Port 7000

Logfile "7000.log"

Dbfilename "dump-7000.rdb"

Daemonize yes

Rdbcompression yes

Slaveof 192.168.27.210 7000

192.168.26.206 configuration:

Cd / data/redis-5.0.5/src

Make

Bind 0.0.0.0

Port 7000

Logfile "7000.log"

Dbfilename "dump-7000.rdb"

Daemonize yes

Rdbcompression yes

Slaveof 192.168.27.210 7000

Start each node separately:

[jerry@master src] $. / redis-server.. / redis-m-7000.conf

[jerry@BDDB src] $sudo ln-s / data/redis-5.0.5/src/redis-server / usr/bin/redis-server

[jerry@BDDB src] $redis-server.. / redis-s-7000.conf

[jerry@DGIDC src] $sudo ln-s / data/redis-5.0.5/src/redis-server / usr/bin/redis-server

[jerry@DGIDC src] $redis-server.. / redis-s-7000.conf

[jerry@DGIDC src] $ss-tnl

Take a look at the master-slave status information of the three servers:

Then we create a key value to test whether the master and slave are synchronized:

We create a link for all three nodes, which is convenient for us to use.

[jerry@master src] $sudo ln-s / data/redis-5.0.5/src/redis-cli / usr/bin/redis-cli

[jerry@BDDB src] $sudo ln-s / data/redis-5.0.5/src/redis-cli / usr/bin/redis-cli

[jerry@DGIDC src] $sudo ln-s / data/redis-5.0.5/src/redis-cli / usr/bin/redis-cli

Observe the status of master-slave information:

Info

After restarting the master, the server observes that the unsaved data will be lost:

Conclusion:

When using the master-slave mode, you should pay attention to the persistence operation of the master node. If the matser node goes down without persistence, and automatically restarts the service, the slave server will lose data. Reason for data loss: after the master service is hung up and the service is restarted, the slave node will perform a complete resynchronization operation with the master node, so the data on the slave node will also be lost because the master node is not persisted. So when you configure the master-slave mode of Redis, you should turn on the persistence feature of the master server.

The test uses Sentinel mode to automatically monitor the Master node, and automatically change the Slaver node into a Master node when the current node is dead:

Then manually switch from (26.206):

127.0.0.1 slaveof 7000 > 192.168.26.112 7000

127.0.0.1V7 000 > set name tom

Summary:

Master can read and write, Slaver can only read, but cannot write Master can correspond to multiple Slaver, but the greater the number, the greater the pressure, the more serious the delay may be. Master returns immediately after writing, synchronizing writes asynchronously to each Slaver almost at the same time, so the delay can basically be ignored. You can upgrade Slaver to Master through the slaveof no one command (manually change a Slaver to Master when Master is down) and monitor Master through sentinel sentinel mode. Automatically elects Slaver to Master when Master hangs up, and other Slaver automatically reconnects to the new Master (automatic failure sometimes requires manual cutting, but the specific reason has not been found yet)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 288

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report