Redis Master-slave replication

Source: Internet
Author: User
Tags install redis

First, the principle of Redis master-slave replication

after the slave is started and connected to master, the Sync command is sent proactively. Master will then start the background disk process, save the database snapshot to a file, and collect new write commands (add, delete, change) and cache them to execute the write file in the background process. When finished, master will transfer the entire database file to slave to complete a full synchronization. The slave server then disks the database file data and loads it into the memory recovery database snapshot to slave. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization. Commands that synchronize data from master to slave and commands sent from the client use the same protocol format. If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but once the connection is successful, a full synchronization will be performed automatically. If master receives multiple slave simultaneous connection commands at the same time, it will only use the START process to write database mirroring and then send it to all slave. second, the characteristics of Redis master-slave replication1, the same master can synchronize multiple slaves. 2, slave can accept other slaves connection and synchronization request, effectively load the sync pressure of master. The replication architecture of Redis can therefore be considered a graph structure. 3. Master Server provides services for slaves in a non-blocking manner. During Master-slave synchronization, the client can still submit queries or modify requests. 4. Slave Server completes data synchronization in a non-blocking manner, blocking the inability to process client requests when synchronizing data for the first time. After the client submits the query request during synchronization, Slave server returns the data before synchronization. 5, master-slave replication can be used to improve the scalability of the system, multiple slave servers can be dedicated to provide read-only requests, such as can be used to do sort operations or to do simple data redundancy. 6, can disable the master data persistence operation, data persistence to slaves completion, to avoid in master to have a separate process to complete this operation. You only need to comment out all the save configurations in the master configuration file, and then configure data persistence only on slave. Third, configure master-slave replicationExample:master:10.142.130.81 slave:10.142.130.821. Install Redis on both servers and start the port using 6379. 2. Execute command on 10.142.130.82: redis-cli slaveof 10.142.130.81 6379The above configuration is temporarily in effect, and if slave restarts, the replication relationship between them will be terminated. If you want to guarantee the replication relationship between these two servers over the long term, you need to configure the slave server:editing the redis.conf configuration file will# slaveof <masterip> <masterport>    instead
slaveof10.142.130.81 6379

Redis Master-slave 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.