Redis Master-slave replication configuration and usage are simple. Master-slave replication allows multiple slave servers to have the same database copy as master server. Here are some of the features of Redis master-slave replication:
1.master can have multiple slave
2. In addition to multiple slave connected to the same master, slave can also connect other slave to form a graphic structure
3. Master-slave replication does not block primary. This means that when one or more slave and master synchronize data for the first time, master can continue to process requests from the client. Conversely, slave will block requests that cannot process the client when the data is first synchronized.
4. Master-slave replication can be used to improve the scalability of the system, we can use multiple slave dedicated to client read requests, such as the sort operation can be handled using slave. can also be used to do simple data redundancy
5. You can disable data persistence in master, just comment out all the save configurations in the master configuration file and configure data persistence on slave only.
The process of master-slave replication:
When the slave server is set up, slave will establish a connection to master and then send the Sync command. Whether it is the first time the connection is established or after the connection is disconnected, master initiates a background process that saves the database snapshot to a file (the fork is also duplicated within the process, that is, the memory is twice times the original), At the same time, the master master process starts collecting new write commands and caches them. After the background process finishes writing the file, master sends the file to Slave,slave to save the file to disk, and then loads it into the memory recovery database snapshot to slave. The master then forwards the cached command to slave. and subsequent master commands are sent to the slave by the connection that was started to be established. Commands that synchronize data from master to slave and commands sent from the client use the same protocol format. Slave can automatically reestablish a connection when master and slave are disconnected. 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.
Configuring the slave server only needs to include the following configuration in the configuration file:
Slaveof 192.168.1.1 6379 #指定master的ip和端口 |
Redis Learning Note 10--redis Master-slave replication