打开网站提示:MISCONF Redis is configured to save RDB

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打开网站提示:MISCONF Redis is configured to save RDB相关的知识,希望对你有一定的参考价值。

1、问题描述:
用浏览器打开网站 https://www.test.org 提示: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.,具体报错如下:

技术分享图片

2、环境:
centos环境:
[[email protected] redis]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[[email protected] redis]#
redis版本:
[[email protected] redis]# redis-server -v
Redis server v=3.0.2 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=76b21ee90041b162
[[email protected] redis]# redis-server --version
Redis server v=3.0.2 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=76b21ee90041b162
Redis属于源码安装的:
[[email protected] ~]# cd /usr/local/redis/
[[email protected] redis]# tree
.
├── bin
│?? ├── redis-benchmark
│?? ├── redis-check-aof
│?? ├── redis-check-dump
│?? ├── redis-cli
│?? ├── redis-sentinel -> redis-server
│?? └── redis-server
├── conf
│?? └── redis.conf
├── data
│?? └── dump.rdb
└── logs
└── redis.log

3、解决方法
方法1:操作无效
有两种修改方法,一种是通过redis命令行修改,另一种是直接修改redis.conf配置文件

命令行修改方式示例:
[[email protected] redis]# redis-cli
127.0.0.1:6379> config set stop-writes-on-bgsave-error no
修改redis.conf文件:vi打开redis-server配置的redis.conf文件,然后使用快捷匹配模式:/stop-writes-on-bgsave-error定位到stop-writes-on-bgsave-error字符串所在位置,接着把后面的yes设置为no即可。

方法2:此方法无效,因为此机器已经设置过了。
[[email protected] /]# cat /etc/sysctl.conf|grep vm.overcommit_memory
vm.overcommit_memory = 1

    Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题

今天在程序中,jedis put数据到redis过程中,“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”报错;
再查看Redis日志,看到有这样的错误提示“Can’t save in background: fork: Cannot allocate memory”,这个提示很明显"Fork进程时内存不够用了!",但内存明明还有一个多G;
经网上查询,Redis在保存数据到硬盘时为了避免主进程假死,需要Fork一份主进程,然后在Fork进程内完成数据保存到硬盘的操作,如果主进程使用了4GB的内存,Fork子进程的时候需要额外的4GB,此时内存就不够了,Fork失败,进而数据保存硬盘也失败了。
解决方法:
很简单,按提示的操作(将vm.overcommit_memory 设为1)即可:
有三种方式修改内核参数,但要有root权限:
(1)编辑/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效
(2)sysctl vm.overcommit_memory=1
(3)echo 1 > /proc/sys/vm/overcommit_memory

方法3:重启redis服务 操作无效
由于是通过源码安装的redis的,此时需要通过redis客户端程序redis-cli的shutdown命令来重启redis
[[email protected] redis]# redis-cli -h 127.0.0.1 -p 6379 shutdown
(error) NOAUTH Authentication required.
此时只能kill命令关闭redis进程了
[[email protected] redis]# ps -ef|grep redis
root 36219 1 0 11:19 ? 00:00:05 ./bin/redis-server :6379
root 40410 39701 0 14:19 pts/7 00:00:00 grep redis
[[email protected] redis]# kill 36129
kill 进程号无法关闭redis进程
[[email protected] redis]# ps -ef|grep redis
root 36219 1 0 11:19 ? 00:00:05 ./bin/redis-server
:6379
root 40410 39701 0 14:19 pts/7 00:00:00 grep redis
用kill -9 +进程号 强制关闭redis进程才可以强制关闭redis进程
[[email protected] redis]# kill -9 36129
[[email protected] redis]# ps -ef|grep redis
root 40410 39701 0 14:19 pts/7 00:00:00 grep redis
redis进程关闭了,然后再指定配置文件,开启redis服务
[[email protected] redis]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
[[email protected] redis]# ps -ef|grep redis
root 36219 1 0 11:19 ? 00:00:05 /usr/local/redis/bin/redis-server *:6379
root 40410 39701 0 14:19 pts/7 00:00:00 grep redis
这时再打开网站 https://www.test.org 可以正常打开网站,但是不到1分钟网站报错依旧。

方法4:查看redis日志
直接用tail -30 redis.log 查看redis.log最后30行的日志
[[email protected] logs]# cd /usr/local/redis/logs
[[email protected] logs]# tail -30 redis.log
2654:M 28 Apr 09:57:58.036 Background saving started by pid 33756
33756:C 28 Apr 09:57:58.037 # Write error saving DB on disk: No space left on device
2654:M 28 Apr 09:57:58.136 # Background saving error
2654:M 28 Apr 09:58:04.047
10 changes in 300 seconds. Saving...
2654:M 28 Apr 09:58:04.047 Background saving started by pid 33757
33757:C 28 Apr 09:58:04.049 # Write error saving DB on disk: No space left on device
2654:M 28 Apr 09:58:04.148 # Background saving error
2654:M 28 Apr 09:58:10.056
10 changes in 300 seconds. Saving...
2654:M 28 Apr 09:58:10.057 Background saving started by pid 33758
33758:C 28 Apr 09:58:10.058 # Write error saving DB on disk: No space left on device
2654:M 28 Apr 09:58:10.157 # Background saving error
2654:M 28 Apr 09:58:16.067
10 changes in 300 seconds. Saving...
2654:M 28 Apr 09:58:16.068 Background saving started by pid 33771
33771:C 28 Apr 09:58:16.069 # Write error saving DB on disk: No space left on device
2654:M 28 Apr 09:58:16.168 # Background saving error
2654:M 28 Apr 09:58:22.078
10 changes in 300 seconds. Saving...
2654:M 28 Apr 09:58:22.079 * Background saving started by pid 33773
33773:C 28 Apr 09:58:22.080 # Write error saving DB on disk: No space left on device
2654:M 28 Apr 09:58:22.179 # Background saving error
发现此是日志:Write error saving DB on disk: No space left on device,磁盘空间不足了

查看inode使用情况:发现inode没有使用完
[[email protected] logs]# df -i
文件系统 Inode 已用(I) 可用(I) 已用(I)%% 挂载点
/dev/mapper/vg_yyd-lv_root
512064 122336 389728 24% /
tmpfs 489644 4 489640 1% /dev/shm
/dev/sda1 128016 38 127978 1% /boot
/dev/mapper/vg_yyd-lv_home
640848 19358 621490 4% /home
/dev/sdb1 6553600 138928 6414672 3% /data
[[email protected] logs]# df -hT
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_yyd-lv_root
ext4 7.7G 5.5G 1.9G 75% /
tmpfs tmpfs 1.9G 12K 0 100% /dev/shm
/dev/sda1 ext4 485M 40M 420M 9% /boot
/dev/mapper/vg_yyd-lv_home
ext4 9.7G 1.5G 7.8G 16% /home
/dev/sdb1 ext4 99G 15G 80G 16% /data

查看block使用率,发现/根目录磁盘已使用100%了,基本已经确认是这个原因导致的。
[[email protected] redis]# df -hT
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_yyd-lv_root
ext4 7.7G 7.7G 0 100% /
tmpfs tmpfs 1.9G 12K 1.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 420M 9% /boot
/dev/mapper/vg_yyd-lv_home
ext4 9.7G 1.5G 7.8G 16% /home
/dev/sdb1 ext4 99G 15G 80G 16% /data
-bash: echo: write error: 设备上没有空间
[[email protected] ~]# cd /var/log
[[email protected] log]# du -sh
2.4G .
查看/var/log/目录下最占空间大小的文件,由此可见 /var/log/notification.log占2.3G大小。
[[email protected] log]# du -sh /var/log/|sort -nr #也可以直接用命令du -sh |sort -nr
2.3G /var/log/notification.log
148K /var/log/anaconda.storage.log
128K /var/log/dracut.log-20160101
128K /var/log/cron
124K /var/log/anaconda.syslog
120K /var/log/cron-20180422
116K /var/log/anaconda.xlog
80K /var/log/secure-20180422
80K /var/log/dmesg.old
76K /var/log/dmesg
40K /var/log/rsyncd.log
36K /var/log/salt
36K /var/log/lastlog
36K /var/log/anaconda.program.log
28K /var/log/anaconda.log
清空日志文件notification.log,注意此时一定不要用删除,因为日志文件很可能被服务进程占用,虽然能删除成功,但是进程没有释放此文件,还得重启对应服务释放才行,所以此时最佳方法就是清空日志,而不是删除日志。
[[email protected] log]# >notification.log
[[email protected] log]# df -hT
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/mapper/vg_yyd-lv_root
ext4 7.7G 5.5G 1.9G 75% /
tmpfs tmpfs 1.9G 12K 1.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 420M 9% /boot
/dev/mapper/vg_yyd-lv_home
ext4 9.7G 1.5G 7.8G 16% /home
/dev/sdb1 ext4 99G 15G 80G 16% /data
日志清空后,磁盘已有空间了,此时再打开网站 https://www.test.org 就可以正常打开了。

以上是关于打开网站提示:MISCONF Redis is configured to save RDB的主要内容,如果未能解决你的问题,请参考以下文章

Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on di

MISCONF Redis is configured to save RDB snapshots

连接redis报错MISCONF Redis is configured to save RDB s

(error) MISCONF Redis is configured to save RDB snapshots, but is currently

Redis常见报错之 Redis::CommandError (MISCONF Redis is configured to save RDB snapshots, but it is current

redisredis异常-MISCONF Redis is configured to save RDB snapshots