1: persistence is not enabled in the redis Master/Slave environment;
When the master instance goes down, data from the instance is not affected;
After the master instance recovers, the data on the master instance will continue to be synchronized to the slave instance, that is, the original value will change to NULL;
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 info | grep-A 3 'replicase' # Replication Role: master Connected_slaves: 1 Slave0: 192.168.1.113, 6379, online [root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> set 1 OK Redis 192.168.1.112: 6379> get 1 "A" [root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown [root @ server12 ~] # Tail-f/var/log/messages Dec 3 15:27:34 server12 redis [32151]: Connecting to MASTER... Dec 3 15:27:34 server12 apsaradb for redis [32151]: MASTER <-> SLAVE sync started Dec 3 15:27:34 server12 redis [32151]: Error condition on socket for SYNC: Connection refused [root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 "A" [root @ server11 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> get 1 (Nil) Redis 192.168.1.112: 6379> exit [root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 (Nil) |
2: Enable snapshot persistence from the instance in redis master-slave Environment
When the master instance goes down, data from the instance is not affected;
After the master instance recovers, the data on the master instance will continue to be synchronized to the slave instance, that is, the original value will change to NULL;
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> get 1 (Nil) Redis 192.168.1.112: 6379> set 1 OK Redis 192.168.1.112: 6379> set 2 B OK Redis 192.168.1.112: 6379> exit [root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown [root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 "" Redis 192.168.1.113: 6379> get 2 "B" Redis 192.168.1.113: 6379> exit [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> get 1 (Nil) Redis 192.168.1.112: 6379> get 2 (Nil) Redis 192.168.1.112: 6379> exit [root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 (Nil) Redis 192.168.1.113: 6379> get 2 (Nil) Redis 192.168.1.113: 6379> exit |
3: What happens when the master and slave instances are down?
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> set 1 OK Redis 192.168.1.112: 6379> set 2 B OK Redis 192.168.1.112: 6379> set 3 c OK Redis 192.168.1.112: 6379> exit [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 "" Redis 192.168.1.113: 6379> get 2 "B" Redis 192.168.1.113: 6379> get 3 "C" Redis 192.168.1.113: 6379> exit Disable the slave instance and then the master instance! Start the slave instance, test data, and then start the master instance, and then test data! [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown [Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 shutdown [Root @ server12 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 "" Redis 192.168.1.113: 6379> get 2 "B" Redis 192.168.1.113: 6379> get 3 "C" [Root @ server11 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> get 1 (Nil) Redis 192.168.1.112: 6379> get 2 (Nil) Redis 192.168.1.112: 6379> get 3 (Nil) Redis 192.168.1.112: 6379> exit [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 1 (Nil) Redis 192.168.1.113: 6379> get 2 (Nil) Redis 192.168.1.113: 6379> get 3 (Nil) Redis 192.168.1.113: 6379> exit |
Practice has proved that, under the condition of redis master-slave read/write splitting, snapshot persistence can only be enabled on the master instance side to ensure that data can be restarted across instances!
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 Redis 192.168.1.112: 6379> set 1 OK Redis 192.168.1.112: 6379> set 2 B OK Redis 192.168.1.112: 6379> set 3 c OK Redis 192.168.1.112: 6379> set 4 d OK Redis 192.168.1.112: 6379> exit [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 Redis 192.168.1.113: 6379> get 4 "D" Redis 192.168.1.113: 6379> exit [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown [Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 shutdown [Root @ server11 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf [Root @ server12 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 get 4 "D" [Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 get 4 "D" |
This article is from the "Bo Yue" blog and will not be reproduced!