Redis master-slave replication-replication

Source: Internet
Author: User

Website Introduction look here Http://redis.io/topics/replication

Master-slave replication: is the host data after updating according to the configuration and policy, automatic synchronization to the master/slaver mechanism of the standby machine,Master to write-based, Slave to read the main

Redis replication is a very simple to use and configure Master-slave replication, allows slave redis servers to be Exa CT copies of master servers.

    • usefulness: Read-write separation, performance expansion; rapid recovery of disaster tolerance

Characteristics:

  • Redis uses asynchronous replication asynchronous replication
  • A master can have multiple slaves a master may be more from the parallel relationship
  • Slaves is able to accept connections from other slaves concatenation relationship
  • Redis replication is non-blocking on the master side replication is non-blocking mode
  • Replication is also non-blocking on the slave side
  • Avoid the cost of the have the master write the full dataset to disk prevents data overflow from being written to the hard disk

First, provisioning from ( server) Unworthy Master ( server)

configuring three servers 6379,6380,6381 ,

you need to copy three copies of the configuration files and change the port number separately, PID file name, Dump.rdb name,

appendonly turn it off.

Info Replication Querying master-slave replication information, initially master

salveof <ip> <port> set the servant relationship,

Parallel Relationship: and Bayi it's all . the slave

Tandem Relationship: It's the master,80 It's Bayi . the Master

First comes the parallel relationship:

Parallel Relationship: and Bayi it's all . the slave

1 pointcut problem? Slave1, slave2 are you copying from scratch or starting from a pointcut? For example, if you come in from K4, the previous 123 can also be copied.

2 is it possible to write from a slave machine? can set?

127.0.0.1:6380> set K8 V8

(Error) READONLY you can ' t write against a read only slave.

read-only Slave

Since Redis 2.6, slaves support a read-only mode, which is the enabled by default. This behavior slave-read-only was controlled by the option of the redis.conf file, and can be enabled and disabled at runtime using C Onfig SET.

read-only slaves would reject all write commands, so, it's not possible to write to a slave because of a mistake. This does isn't mean that the feature are intended to expose a slave instance to the Internet or more generally to a network Where untrusted clients exist, because administrative commands like  DEBUG  or  CONFIG  are still enabled. However, security of read-only instances can be improved by disabling commands in redis.conf using THE&NBSP; rename-c Ommand directive.

Wonder why it's possible to revert the read-only setting and has slave instances that can be target of write ope Rations. While those writes would be discarded if the slave and the The master resynchronize or if the slave was restarted, there is a f EW legitimate use case for storing ephemeral data in writable slaves. However in the future it's possible that this feature'll be dropped.

3 What happens after the host shutdown? From the machine is the upper or standby

4 host again back, the host new records, from the machine can also be copied smoothly?

5 What happens when one of the machines is down? Can it keep up with the top troop in accordance with the original?

Configuration file

Tandem Relationship: It's the master,80 It's Bayi . the Master

  • Legend of Fire
  • The previous slave can be the next slave master,slave can also receive other slaves connections and synchronization requests, then the slave as the next master in the chain, can effectively reduce the master's write pressure, to reduce the risk of centralized.
  • With slaveof <ip> <port>
  • Change direction: Clears the previous data, re-creates a copy of the latest
  • The risk is that once a slave goes down, the back slave can't be backed up.
  • His new
  • When a master is down, the rear slave can be immediately upgraded to master, and the slave behind it will not be modified.
  • Use Slaveof no one to turn the slave machine into a host.

The principle of Master-slave replication:

Each time from the machine, will send to the Host Sync command, the host immediately save the operation, send the Rdb file to the slave machine,

After receiving the Rdb file from the machine, the full load is carried out, and then each time the host writes, it is sent to the slave immediately, the same command is executed from the machine.

How Redis replication Works

If you set up a slave, upon connection it sends a PSYNC command.

If This is a reconnection and the master have enough backlog, only the difference (what's the slave missed) is sent. Otherwise What's called a full resynchronization is triggered. Trigger resynchronization

When a full resynchronization was triggered, the master starts a background saving process in order to produce an RDB file. At the same time it starts to buffer all new write commands received from the clients. When the background saving are complete, the master transfers the database file to the slave, which saves it on disk, and T Hen loads it into memory. The master would then send all buffered commands to the slave. This was done as a stream of commands and was in the same format of the Redis protocol itself.

You can try it yourself via Telnet. Connect to the Redis port while the server is doing some work and issue the Synccommand. You'll see a bulk transfer and then every command received by the master would be re-issued in the Telnet session.

Slaves is able to automatically reconnect when the Master-slave link goes down for some reason. If the master receives multiple concurrent slave synchronization requests, it performs a single background save in order T o Serve all of them.

Second, Sentinel mode sentinal

    • His new automatic version, to be able to monitor the host if the failure, if the failure of the number of votes automatically from the library converted to the main library.

(1), New Sentinel configuration file

    • Custom/myredis directory to create a new sentinel.conf file, the name must not be wrong
    • Fill in the contents of the configuration file:

Sentinel Monitor MyMaster 127.0.0.1 6379 1

    • Where MyMaster is the server name for the monitoring object, 1 is the number of at least how many sentinels agree to the migration.
    • Execute redis-sentinel/myredis/sentinel.conf Boot Sentinel mode
    • Can see running in Sentinel Mode, and display 79master 80,81slave information

Failure recovery

Host 79shutdown

You can see the new epoch-election leader-elect leader-----switch master into 81,

Redis master-slave replication-replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.