Redis Cluster master-slave copy, read-write separation (upper)

Source: Internet
Author: User
Tags redis cluster

With the further development of web2.0, the productivity of netizens is further improved and the total amount of storage begins to increase. While it is still a mode of reading and writing less, the amount of writing has been greatly improved. The original cache technology can not alleviate the write pressure, and the original space is also limited by the hard disk, so began to appear in the sub-Library, to achieve the separation of reading and writing. The centralized-mode database begins to diverge: a concentrated, stable, strongly relational structure that develops toward a differentiated, fault-tolerant, weak-relationship structure. Data storage space and data access time are further separated. That is, where the data exists, where to go to visit. It is now the data or the old place (the hard drive), but the access is in another place (such as memory, or another server). The goal is to shorten the IO path or detach IO to achieve efficient access.

Redis host Data Update according to configuration and strategy, automatic synchronization to standby master/slaver mechanism, master to write mainly, slave read-oriented, so you can reduce the pressure on the server.

Introduction to the configuration of Redis master and slave copying

Introduction to the Principle of replication

Slave boot successfully connected to master sends a sync command, master receives a command to start the background of the save process, while collecting all received to modify the DataSet command, after the completion of the background process, master will transfer the entire data file to slave, To complete a full synchronous full replication: The slave service, after receiving the database file data, will save it and load it into memory. Incremental replication: Master continues to pass all new collection of modified commands to slave to complete the synchronization

But as long as you reconnect master, a full sync (full copy) will be performed automatically

Case 1: A main n from

(Here I only use a Linux machine, but the configuration can also achieve the requirements of the Redis cluster, if there are more than one server, the configuration is the same)

First from the Copy 3 redis.conf files (copies of two are also possible, here I am to differentiate Master/slave)

So the next step is to modify the configuration of the host configuration introduction (in order to show that the master-slave copy of the time access is not the same database file, the database file name will be modified accordingly)

Introduction from machine configuration

From Machine 6380 configuration

From Machine 6381 configuration

OK configuration is complete, then the next step is to start the Redis service and connect to see if the configuration is valid


View information through the Info Replication command

We can see that the Redis service of 3 servers started successfully, the role is master, then the next is to distinguish master and slave library, through the command slaveof host IP host Redis port

slaveof 127.0.0.1 6379

This is OK, and then again through the Info Replication command to view, found this time the port number for 6380,6381 Redis from the main library into the library

Then perform the write operation in the main library at this time

The set K1,K2,K3 operation was done before set K4, and then 6380,6381 as the main library from the library, discovering that all the data in the main library is from the library, and that each has a database file from the library

So at this point, when we're performing a write operation from the library, we find that it's not performing correctly.

Since reading and writing have been separated from the library, only read operations can be performed from the library

What's up? I am through the command of the way to achieve the separation of the master and slave library, then you will find that this is very troublesome, in case of the Redis service from the library after the suspension, restart the Redis service after the implementation of the

slaveof 127.0.0.1 6369

This is very impersonal, but also very troublesome, then the configuration file through the way to achieve the separation of master and slave library

Other from the library is the same configuration, OK, configuration has been good, then the next is to start the Redis service

As we can see, when the Redis service starts, the character immediately becomes from the library, not to our previous need to manually tap the command, which is very convenient

In case 1 above, we talked about a main n-mode.

So is redis from the library to allow other Redis services to connect to it.

Case 2: Procreation

What's the meaning of the lineage? It means that there is only one library under a main library, and this is followed by another redis from the library. One followed one, instead of a main library there followed N from the library, this way you can go to the center, but this way there will be the delay of data replication, because you are one with the data in the main library changes, then the following from the library will be copied immediately, but this time only one from the library, To wait until the current copy from the library is complete before you can copy down again

Configuration

Modify the configuration of one of the computers

Start the Redis service

Service started successfully, then the middle of that one connected to the main library of the Redis (that is, the direct connection to the main library and then follow from the library) what is the role of it?

You can see that the middle of the redis from the library is still from the role of the library, but below followed by the younger brother. At this point, however, the write operation cannot be performed because the middle one is still from the role of the library

Redis of master and slave copy, read and write separation will come to an ending, the next time for you to continue to explain the Redis cluster Sentinel mode

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.