Redis [6] master slave replication + read write separation

You and other students 2022-02-13 08:08:51 阅读数:363

redis master slave replication read

redis6 Master slave copy + Read / write separation

Redis6.X Master slave copy + Introduction to the separation of reading and writing

  • background
    • Simple stand-alone deployment , But reliability is low , And can't make good use of CPU Multi core processing power
    • Production environment - High availability must be ensured - It is generally impossible to deploy on a single machine
    • The separation of reading and writing is that the usability requirements are not high 、 High performance requirements 、 In the case of small data scale ;
  • The goal is
    • Read / write separation , Expand the read ability of the master node , Share the read pressure of the master node
    • disaster recovery , Once the primary node goes down , As the backup of the master node, the slave node can be up at any time

Master slave copy - Analysis of the principle of reading and writing separation

  • There are two types of master-slave replication ( When the master and slave just connected , Do full synchronization ; When the full synchronization is over , Incremental synchronization )

    • Copy in full
      • master The server will start a background process for redis The data in generate a rdb file
      • The master server will cache all the write commands received from the client , When the background saves the process After processing , Will be the rdb The document is passed to slave The server
      • slave The server will rdb The file is saved on disk and the data is loaded into memory by reading the file
      • After that master The server will send commands cached during this period through redis The transport protocol is sent to slave The server
      • then slave The server acts these commands on its own local data set in turn to achieve data consistency
    • Incremental replication
      • Slave The process of synchronizing writes that occur on the primary server to slave servers when they start working normally after initialization
      • Every time the server executes a write command, it will send the same write command to the slave server , Receives and executes the received write command from the server
  • characteristic

    • Master slave replication for Lord / from redis The server is non blocking , Therefore, external requests can be handled normally during synchronization
    • A master redis Can contain multiple from redis, Each from redis Can receive from other from redis Server connection
    • The slave node will not let key Be overdue , It's the primary node key After expired deletion , Become del The command is transmitted to the slave node for deletion
      • Open from node sync Log
  • Accelerate replication

    • Full resynchronization requires the creation of a... On disk RDB file , Then load this file to send data from the server
    • On slower disks , This kind of operation will bring more pressure to the main server
    • The new version supports diskless replication , The child process will directly RDB Send over the network to the slave server , No disk for intermediate storage
    • repl-diskless-sync yes ( The default is no)
  • Master slave disconnection and reconnection

    • If the connection is broken , After reconnecting, you can continue to copy from the break , Without having to resynchronize
    • 2.8 After version Partial resynchronization of this new feature is used internally PSYNC command , The old implementation uses SYNC command
copyright:author[You and other students],Please bring the original link to reprint, thank you.