Redis持久化失败,MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist o

1. Error description

MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

Redis log description:

21222:C 25 Feb 03:58:01.811 * RDB: 70 MB of memory used by copy-on-write
797:M 25 Feb 03:58:01.825 * Background saving terminated with success
797:M 25 Feb 04:03:02.100 * 10 changes in 300 seconds. Saving...
797:M 25 Feb 04:03:02.101 # Can't save in background: fork: Cannot allocate memor

2. RBD persistence method

When redis saves the dump.rdb file:

  1. First, the parent process forks a child process, at this time redis owns the parent and child processes
  2. The child process writes the data set to a temporary rdb file
  3. But after the child process writes the new rdb, redis will replace the old rdb file with the new file, and then delete the old one.

This way of working allows Redis to benefit from the copy-on-write mechanism!

3. Error analysis

When Redis dumps data, it forks a child process. In theory, the memory occupied by the child process is the same as that of the parent. For example, the memory occupied by the parent is 8G. At this time, 8G of memory should also be allocated to the child. Unaffordable, it often causes the redis server to be down or the IO load is too high, and the efficiency decreases. So the more optimized memory allocation strategy here should be set to 1 (indicating that the kernel allows all physical memory to be allocated regardless of the current memory state).

Memory allocation strategy parameters

Overcommit_memory parameter description: Set the memory allocation strategy (optional, set according to the actual situation of the server), optional values: 0, 1, 2.

  • 0: The kernel will check whether there is enough available memory for the application process; if there is enough available memory, the memory application is allowed; otherwise, the memory application fails and an error is returned to the application process.
  • 1: Indicates that the kernel allows all physical memory to be allocated, regardless of the current memory status.
  • 2: Indicates that the kernel allows the allocation of memory that exceeds the sum of all physical memory and swap space.

3. Solution

  1. Ignore the persistent exception and continue to write
    xxx> config set stop-writes-on-bgsave-error no
  2. Modify Linux memory allocation strategy
    vim /etc/sysctl.conf
    # ---
    vm.overcommit_memory = 1
    

Guess you like

Origin blog.csdn.net/JAYU_37/article/details/107093321