by slaveof 192.168.1.1 6379 #指定master的ip和端口
After copying the backup library, tap the command.
Slaveof no one #断掉两个主机间的联系
Master-slave replication: Let multiple slave servers have the same database copy as master server.
Characteristics
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 a connection is established or a reconnection after a disconnection, master initiates a background process to save the database snapshot to a file.
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.
The snapshot is then loaded into the memory recovery database on 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 is simple, just add the following configuration to the configuration file
Slaveof 192.168.1.1 6379 #指定master的ip和端口
Redis Add Backup Library