Redis 无法持久化到硬盘错误:not able to persist on disk

一、报错:
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被配置为保存数据库快照,但它目前不能持久化到硬盘。用来修改集合数据的命令不能用。请查看Redis日志的详细错误信息。


二、搜索网上的解决方案,大概有三种:
1. 直接忽略形
将stop-writes-on-bgsave-error设置为no

# 临时生效
127.0.0.1:6379> config set stop-writes-on-bgsave-error no

# 永久生效 修改配置文件,重启服务
vim /etc/redis.conf
xxx

简单粗暴,但不推荐

2. 解决问题形

查日志 不能保存到硬盘?为什么?

1.权限不足? chown授权

#tail /var/log/redis/redis.log
12402:C 26 Nov 18:06:13.077 # Failed opening the RDB file root (in server root dir /var/spool/cron) for saving: Permission denied
30640:M 26 Nov 18:06:13.177 # Background saving error
  
# chmod 777 /var/log/redis/redis.log

2.磁盘满了? df -h

3.内存不足了? free -m

原因: 强制关闭Redis快照导致不能持久化

这种方式是比较正常的套路,通过查日志来确定内存、磁盘问题、权限问题

3. 内存型问题处理:

修改系统内核相关内存分配策略:sysctl vm.overcommit_memory=1
这个参数是vm.overcommit_memory 是linux系统在应用申请内存使用的一个策略。
该策略有三个值:0、1、2 。0为默认值

在日志中看到有相关的日志:
Can’t save in background: fork: Cannot allocate memory

不能保存,fork进程没有足够内存。但查看系统内存还有两三个G,这个时候就懵逼了。
原来默认情况下系统对于内存的分配特别是dump内存中数据到磁盘上时会都需要fork一份,然后保存在磁盘上。而我们的redis内存应使用了8个G,持久化时候会额外增加一部分,而系统中的内存只有3G,不够。
可以修改overcommit_memory的值来改善这个问题。

三、排查具体情况:

3.1 开发反馈redis异常、日志有报错

redis.exceptions.ResponseError: 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 che
ck Redis logs for details about the error.

During handling of the above exception, another exception occurred:

3.2 查看系统情况:

[root@hn-xx-xx celery]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3790        1826        1363           0         600        1728
Swap:             0           0           0
[root@hn-xx-xx celery]# ps -ef |grep redis
root      6496  3536  0 21:59 pts/0    00:00:00 grep --color=auto redis
redis     9978     1  0  2018 ?        03:27:01 /usr/bin/redis-server 172.16.1.19:6379
[root@hn-xx-xx celery]# ll -d /var/lib/redis/
drwxr-x--- 2 redis redis 4096 Jul 18 21:46 /var/lib/redis/
[root@hn-xx-xx celery]# df -H
Filesystem                   Size  Used Avail Use% Mounted on
/dev/vda1                     43G   11G   30G  26% /
devtmpfs                     2.0G     0  2.0G   0% /dev
tmpfs                        2.0G     0  2.0G   0% /dev/shm
tmpfs                        2.0G  537k  2.0G   1% /run
tmpfs                        2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/vdb--vg-vdb--lv  106G   79M  106G   1% /data
tmpfs                        398M     0  398M   0% /run/user/0
tmpfs                        398M     0  398M   0% /run/user/1004
tmpfs                        398M     0  398M   0% /run/user/1002

3.3 查redis日志

tail /var/log/redis/redis.log

3.4查监控  分布式监控系统Zabbix--使用Grafana进行图形展示

3.5 查看redis的使用情况

[root@hn-xx-xx celery]# redis-cli -h 127.0.0.1
127.0.0.1:6379> info Memory
# Memory
used_memory:1129160
used_memory_human:1.08M
used_memory_rss:5255168
used_memory_rss_human:5.01M
used_memory_peak:765978920
used_memory_peak_human:730.49M
total_system_memory:3974848512
total_system_memory_human:3.70G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:4.65
mem_allocator:jemalloc-3.6.0
原文地址:https://www.cnblogs.com/zhouj850/p/13218520.html