Redis replication (Master/Slave)

1. Master/Slave Replication (master-slave replication)
  After the host data is updated, it will be automatically synchronized to the master/slave mechanism of the slave (standby) machine according to the configuration and strategy. The Master is mainly for writing, and the Slave is mainly for reading.
  Role: read-write separation; disaster recovery.
2. Application
  2.1. Slave (library) not matching master (library)
  2.2. Slave library configuration: slaveof main library IP main library port
    After disconnecting from master (main library) every time, you need to reconnect unless configured in the redis.conf file;
    use the command Info replication to view the master-slave library information.
  2.3. Modify the detailed operation of the configuration file
    Create three containers through the Redis image, as follows:
  2.4. Common master/slave configuration
    a, one master and two slaves:
      Init: Initialize, configure two slave libraries; one master
      and two slave logs to view: 1) master log; 2
      )
      standby log; Do slave1 and slave2 start copying from the beginning or from the entry point?
      2) Can the slave be written? Can it be set?
      3) After the host is shut down, is the slave the master or is it on standby (still the slave)?
      4) After the host comes back (restart), the host adds new records (data), can the slave copy it smoothly?
      5) What happens after one of the slaves goes down? According to the original, can it still connect to the original host?   Full copy: After the slave service receives the database file data, it saves it and loads it into the memory; Incremental   copy: the master continues to pass all the new collected modification commands to the slave one by one to complete the synchronization, but as long as the master is reconnected, a full synchronization (full copy) will be executed automatically. 4. Sentinel mode (Sentinel)   Sentinel mode is an automatic version of "anti-customer-oriented". It does not need to manually execute SLAVEOF no one. Sentinel mode can monitor whether the host has failed in the background. Once a host fails, it will automatically convert a slave library to the master library according to the number of votes.   4.1. Steps to use
    



    








  1) Create three redis containers, the ports are 6379, 6380, 6381, 6379 as the main library, 80, 81 as the slave library
  2) Configure the sentinel, fill in the content: sentinel monitor the name of the monitored database (named by yourself) 127.0
    .
  3) Start Sentinel: Redis-sentinel /myredis/sentinel.conf (The directory is different according to the actual configuration)
  4) Normal master-slave demonstration
  5) The original master hangs up
  6) The slave library votes to select a new master library
  7) Restart the master-slave library and continue to work, info replication to check the master-slave library information
  8) If the previous master restarts, will the two masters conflict?
    Won't. After restarting, the previous host will be mounted on the new host as a slave.
  9) A sentinel can monitor multiple masters at the same time.
5. Disadvantages of replication
  Replication delay: Since all write operations are performed on the master and then updated to the slave synchronously, there is a certain delay in synchronizing from the master to the slave machine. When the system is very busy, the delay problem will be more serious, and the increase in the number of slave machines will also make this problem more serious.
Remarks: Wait for the time to do it again, and put the screenshots up.

Guess you like

Origin blog.csdn.net/qq_37196265/article/details/105961967