HairLossException 2022-01-26 11:28:38 阅读数:73
Here we use three different ports to simulate three independent redis The server
First, create three redis.conf The configuration file :
Let's call them redis6379.conf、redis6380.conf、redis6381.conf
cp redis.conf redis6379.conf
cp redis.conf redis6380.conf
cp redis.conf redis6381.conf
modify redis The configuration file , The following redis6380.conf For example ( The other two operations are the same )
port 6380
pidfile /var/run/redis_6380.pid
logfile 6380.log
dbfilename dump6380.rdb
redis-server redis6379.conf &
redis-server redis6380.conf &
redis-server redis6381.conf &
redis-cli -h 127.0.0.1 -p 6379
redis-cli -h 127.0.0.1 -p 6380
redis-cli -h 127.0.0.1 -p 6381
Before the master-slave relationship is not set, each computer is set by default redis Servers are Master
Set never set the master
stay 6380 On the implementation slaveof 127.0.0.1 6379 // Set up slave
stay 6381 On the implementation slaveof 127.0.0.1 6379 // Set up slave
info replication // View master-slave relationship
here 6379 It's the main warehouse (Master)6380 and 6381 It's from the library (Slave)
- Copy in full : Once the master-slave relationship is determined, the existing data in the master database will be automatically copied to the slave database
- Incremental replication : The data written by the master library will be automatically synchronized to the slave library ( Read only from the library without writing )
Here, the shutdown of the host service is used to simulate the host downtime
- redis-cli -h 127.0.0.1 -p 6379 shutdown
View slave roles
After restoring the host, check the master-slave relationship again
Conclusion : The host is down and the slave is on standby After the host is restored, everything returns to normal
It's closed here 6380 Service to simulate slave downtime
- redis-cli -h 127.0.0.1 -p 6380 shutdown
View master-slave relationship
After the slave is restored, check the master-slave relationship again
Conclusion : After the slave goes down, other slaves will not be affected After the slave is restored, it will change back to the host, and the master-slave relationship needs to be reset
If the host fails to recover in a short time after downtime This database cluster can only perform read operations and cannot perform write operations At this time, it is necessary to replace the host computer from the host computer
// First, let the slave disconnect the original master-slave relationship
slaveof no one
// And then in 6381 Reset the master-slave relationship
slaveof 127.0.0.1 6381
copyright:author[HairLossException],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261128361444.html