Redis persists in two ways

First, RDB persistence

This way is to save the data.

Execution method:

  1. Manual: save (deprecated)/bgSave
  2. Automatic: Save m n in the configuration file

Configure common file parameters

  • Save path of RDB file: dir in configuration file
  • RDB filename: dbfilename in the configuration file
  • RDB file compression: indicates rDBCompression in the configuration file

2. AOF persistence

This way to preserve the write command, more mainstream.

This is disabled by default, to enable, in the configuration file: appendonly yes

AOF rewrite: Converts current data to write commands, independent of old AOF files

  • Manual override: bgrewriteaof
  • Automatic override: in a configuration file:
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
Copy the code

A master-slave replication

Both Sentinels and clusters are highly available on a replication basis. Master-slave replication is initiated entirely on the slave node and does not require us to do anything on the master node.

You can set up the master-slave relationship by running the slaveof


command on the slave node in addition to configuration files.

The masterauth file from the node configuration file is used to verify the password of the master node.

Master/slave replication includes the connection establishment phase, data synchronization phase, and command transmission phase.

  • In the data synchronization phase, there are two data synchronization modes: full replication and partial replication. During command propagation, the PING and REPLCONF ACK commands are used between the primary and secondary nodes to check the heartbeat of each other.

  • If the offset difference between master and slave is too large and exceeds the replication backlog buffer, full replication can only be performed. Change the replication backlog buffer size to repl-backlog-size

The sentry

The core function of Sentry is automatic failover of the master node

Architecture:

  • Different sentinel nodes should be deployed on different physical machines
  • Turn off the Redis password while learning the demo
  • Forced failover:sentinel failover mymasterThis command can force a failover of MyMaster even if the current master node is healthy. For example, if the current active node is about to become obsolete, you can run the failover command to perform failover in advance.
  • Subjective referral: the sentry’s own perception of referral; Objective logoff: The sentry consults other sentries and decides that if the number of logoffs reaches a certain level, it is an objective logoff. Objective offline truth is valid for the primary node.

The cluster

  • A cluster is used to share master data on multiple nodes and can share the master write burden on a single node.

  • The cluster consists of multiple sentinel patterns. However, in actual deployment, the sentry is not configured, and the fault can be automatically transferred. The principle is that each master acts as an agent for sentinel, and one of the slaves elected offline by the master becomes the new master to continue the work.

  • Regardless of the size of the project, it is recommended to deploy as a cluster to be fully prepared for expansion.

  • After Redis 5.0, Ruby script was cancelled and integrated into Redis – CLI. After 5.0, build process. Note that the public IP is used to build the cluster, and the +10000 port of Ali Cloud should also be opened. The password must be configured, otherwise it will be attacked, the key becomes backup1, backup2.

    Requirepass is set for both master and slave, and MasterAuth is set for slave. The -a parameter specifies the password when building the cluster.

    Solution: Edit the nodes-port. conf file and replace the internal IP address with the public IP address

  • Pre-5.0 build process with Ruby scripts

  • To disable the cluster: shutdown the node, delete the cluster configuration file and data file, and keep only the redis-port. conf file.

  • Deleting a node: You can delete a secondary node directly, but delete all slots on the primary node.

    Example:

    Redis – cli – cluster del -node 127.0.0.1:6381 26976 c7da741133edf0648da207ce40336bcbcba,

    127.0.0.1:6379 > cluster flushslots