Redis master (separate read and write) from the Copy

From the master copy (separate read and write):
Read read from the library, the library written in the master write.

From the main benefits of replication:
avoid single points of failure redis
build separate read and write architecture to meet the needs of reading and writing less.

Master-slave architecture:

Operation (Start instance, starting in a machine of different instances, the pseudo-master replication):
1. Copy profile, modify the configuration file, start 6379,6380,6381 three examples;

2. the primary and
two disposed in a main redis from:
(1) arranged in redis.conf slaveof (permanent)
(2) using redis client to connect to the service, salveod execute command (temporary)

3. Review the information from the master, using the INFO replication command.

4. Test
write data in the main library:

In the data read from the library:

From the master-slave architecture:


Operation of master-slave architecture is similar to not write.

From the library read-only:
By default redis act as slave role can only be read but not write.

The configuration file can be opened in non-read only: slave-read-only no

Master-slave replication principle:
When building from the main library and the main library, sync command is sent from the relationship as the main library;
the main library received sync command to start saving snapshots (rdb processes) in the background, and received during the write commands cached;
when the snapshot is complete, the main redis will send the snapshot file and cache write command together to from redis;
from redis received, will load a snapshot and do receive cache write command;
after each when the main redis received are sent to the write command from redis, to ensure data consistency.

无磁盘复制:
如果主库所在的服务器的磁盘io能力较差的话,那么主从复制就会遇到瓶颈。的redis2.8.18版本后引入了无磁盘复制。
原理:
redis在与从库进行复制初始化的时候不再将快照保存在磁盘,而是通过网络直接发送给从库,从而避免了io性能差的问题。
开启无磁盘复制:repl-diskless-sync yes

主从架构出现宕机怎么办?
如果在主从复制架构中遇到宕机的话,一般要分情况:
1.从redis宕机
这种情况相对来说比较简单,只需将从redis重启,重启后从redis会自动加入到主从架构中,完成数据的同步。而且从redis2.8开始还实现了主从断线后恢复的情况下实现增量更新的功能。
2.主redis宕机
需要完成两步,第一步是在从redis中执行SLAVEOF NO ONE 命令,断开主从关系并且提升为主库继续提供服务;第二步是将主库重新启动,执行SLAVEOF命令,将其设置为其他库的从库,这时数据就会更新回来。这个过程一般使用哨兵来监听。

Guess you like

Origin www.cnblogs.com/ericz2j/p/11110598.html