Caused by: io.lettuce.core.RedisCommandExecutionException 记一次Redis报错修复

Caused by: io.lettuce.core.RedisCommandExecutionException

问题描述:

Caused by: io.lettuce.core.RedisCommandExecutionException: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.

问题大意:Redis在进行RDB持久化操作的时候写入磁盘的时候出现了问题

问题分析:出现此种问题的可能情况

  • 磁盘损坏
  • 分给Redis进行持久化的磁盘写满
  • 对磁盘访问的权限不足

官方提供解决方案:
查看Redis日志可得

17175:M 23 Mar 20:56:43.185 #

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.

To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

17175:M 23 Mar 20:56:43.185 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command
‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
17175:M 23 Mar 20:56:43.185 * DB loaded from disk: 0.000 seconds
17175:M 23 Mar 20:56:43.185 * Ready to accept connections

解决方案(参照官方):

vim /etc/sysctl.conf 添加 vm.overcommit_memory = 1

echo never > /sys/kernel/mm/transparent_hugepage/enabled

vim /etc/rc.local 添加 echo never > /sys/kernel/mm/transparent_hugepage/enabled

作用:禁用 Transparent Huge Pages (THP)

科普:

内核参数overcommit_memory

它是内存分配策略可选值:0、1、2。
0 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2表示内核允许分配超过所有物理内存和交换空间总和的内存

什么是Overcommit和OOM

​ Linux对大部分申请内存的请求都回复"yes",以便能跑更多更大的程序。因为申请内存后,并不会马上使用内存。这种技术叫做 Overcommit当linux发现内存不足时,会发生OOM killer(OOM=out-of-memory)。它会选择杀死一些进程(用户态进程,不是内核线程),以便释放内存。 当oom-killer发生时,linux会选择杀死哪些进程?选择进程的函数是oom_badness函数(在mm/oom_kill.c中),该 函数会计算每个进程的点数(0~1000)。点数越高,这个进程越有可能被杀死。每个进程的点数跟oom_score_adj有关,而且 oom_score_adj可以被设置(-1000最低,1000最高)。

你可能感兴趣的:(Redis,redis)