Redis from the master copy (Master / Slave)

1. What is

Jargon: what we call the master-slave replication, host data is updated according to configuration and policy automatically synchronized to the standby machine master / slave mechanism, Master in order to write the main, Slave read-mostly

Redis from the master copy (Master / Slave)

2. Why can

  • Data redundancy: a master-slave realized hot backup copy of data is a data redundancy than persistence
  • Recovery: When there is a problem the master node, a node can be provided by the service, fast failure recovery; redundancy is actually a service
  • Load balancing: (i.e., primary node connected to application Redis write data, the application connection from the node read Redis data) in the main, with separate read and write from the base on the copy, writing services may be provided by the master node, providing a service from the node read , server load balancing; especially writing less reading multiple scenes, the shared node from the plurality of load reading
  • Availability cornerstone: because the main cluster is the basis of Sentinel and can be implemented from the copy, so say the master-slave replication is the basis for highly available Redis

3. how to play

Redis master-slave replication explain

(1) info replication:. View From the main target redis

Redis from the master copy (Master / Slave)

(2) with a main library from the library unworthy

From the library configuration: slaveof main library main library IP port

Note: slaveof be configured, after each disconnect all need to reconnect, unless the configuration file into redis.conf

(When this is the first execution slaveof command) from the library followed once the main library, from the library is not read write, for the first time is the total amount after synchronization is incremental, if present from the library before synchronization with the main reservoir same key data, then data covering the main library from the library

Redis from the master copy (Master / Slave)

(3). A common strategy

①. A master from two

Redis from the master copy (Master / Slave)

This can be expanded from two main level is a master multi-slave, the host is responsible for writing the slave is responsible for reading

Host is down in the absence of sentinel mechanism, the slave will resume running silently waiting until the host state

Redis from the master copy (Master / Slave)

②. Passing the torch

Redis from the master copy (Master / Slave)

A Slave can be a slave of the Master, Slave can also receive other slaves connection and synchronization request, then the slave as a master in the next chain, can effectively reduce the writing pressure of the master.

The first thing a master at the beginning, others are slave, just in the middle of a slave is the master

(4) Copy principle

Sends a sync command Slave start successfully connected to the master

Master ordered to start the process of archiving the background while collecting all data received to modify the set command,
after the background process is finished, master transfers the entire data file to the slave, to complete a full synchronization

  • Copy the full amount: The slave database service after receiving the data file, save it and load it into memory.
  • Incremental Copy: Master will continue to collect all the new changes in order to pass command slave, synchronization is complete

But as long as the connection is re-master, a full synchronization (full volume copy) will be automatically executed

(5) It is important to sentry mode

Background monitoring host is capable of fault, if fault according to the number of votes from the library automatically converts the main library

To a strategy from two main example:

1. Since the New sentinel.conf file / myredis defined directory name must not be wrong

2. Configure Sentinel, fill in the content

sentinel monitor 被监控数据库名字(自己起名字) 127.0.0.1 6379 1

上面最后一个数字1,表示主机挂掉后salve投票看让谁接替成为主机,得票数多少后成为主机

Redis from the master copy (Master / Slave)

3. Start Sentinel

Redis-sentinel /myredis/sentinel.conf

4. From the main normal presentation, the original master hung
Redis from the master copy (Master / Slave)

5. Voting newly elected and re-master and slave to remain in operation, info replication check to see
Redis from the master copy (Master / Slave)

6. Master the original host is down recovery operation, the wheel is slave Slave

Cons: Copy Delay

Since all write operations are the first to operate on the Master, and then synchronize updates to the Slave, so there is a delay from Master to Slave synchronous machine, when the system is busy, delay problem will become more severe, increasing the number of Slave machine also make this problem worse.

Guess you like

Origin blog.51cto.com/14230003/2406320