Redis写入失败MISCONFRedisisconfiguredtosaveRDBsnapshots, but is currently not able to persist on disk

java日志报错如下:

redis hput异常org.springframework.dao.InvalidDataAccessApiUsageException: 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.; nested exception is redis.clients.jedis.exceptions.JedisDataException: 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.
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:64)
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
at org.springframework.data.redis.connection.jedis.JedisHashCommands.convertJedisAccessException(JedisHashCommands.java:433)
at org.springframework.data.redis.connection.jedis.JedisHashCommands.hSet(JedisHashCommands.java:69)
at org.springframework.data.redis.connection.DefaultedRedisConnection.hSet(DefaultedRedisConnection.java:827)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.hSet(DefaultStringRedisConnection.java:501)
at org.springframework.data.redis.core.DefaultHashOperations.lambda$put$8(DefaultHashOperations.java:178)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultHashOperations.put(DefaultHashOperations.java:177)
at org.springframework.data.redis.core.DefaultBoundHashOperations.put(DefaultBoundHashOperations.java:145)
at com.augurit.xmjg.province.config.RedisClient.hput(RedisClient.java:165)
at

redis deleteKey操作异常org.springframework.dao.InvalidDataAccessApiUsageException: 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.; nested exception is redis.clients.jedis.exceptions.JedisDataException: 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.
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:64)
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
at org.springframework.data.redis.connection.jedis.JedisKeyCommands.del(JedisKeyCommands.java:93)
at org.springframework.data.redis.connection.DefaultedRedisConnection.del(DefaultedRedisConnection.java:61)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.del(DefaultStringRedisConnection.java:252)
at org.springframework.data.redis.core.RedisTemplate.lambda$delete$2(RedisTemplate.java:709)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.RedisTemplate.delete(RedisTemplate.java:709)
at

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.; nested exception is redis.clients.jedis.exceptions.JedisDataException: 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 erro

Redis被配置为保存RDB快照,但目前无法持久化到磁盘上。可能修改数据集的命令被禁用。请检查Redis日志的详细错误。Redis被配置为保存RDB快照,但目前不能持久化到磁盘上。可能修改数据集的命令被禁用。请检查Redis日志的详细错误

解决方法(1)

翻看日志

find / -name redis
find / -name redis.conf

找到redis的日志路径并查看

Can't save in background: fork: Cannot allocate memory
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

国外给的方法如下:

sysctl vm.overcommit_memory=1   

编辑

/etc/sysctl.cnf 

补充:

vm.overcommit_memory=1

国外的文章如下:

If you get this error  
  
Can't save in background: fork: Cannot allocate memory  
  
it means that your current database is bigger than memory you have. To fix the issue enable vm.overcommit_memory:  
  
sysctl vm.overcommit_memory=1  
  
To have if after reboot add this line to /etc/sysctl.cnf:  
  
vm.overcommit_memory=1  

程序保存数据时继续报“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进程时内存不够用了!"(还是内存的问题)。

编辑sysctl.conf

vi /etc/sysctl.conf

最下方补充内容

net.core.somaxconn= 1024

执行命令

sysctl -p

解决方法(2)重启大招释放内存:

重启之后,起码可以释放当前所有的内存,可以先观察一下重启是否正常!

步骤(1)将JAVA应用先关闭

步骤(2)用Redis工具连上数据库,人工清库FLASH DATABASE操作

FLASH DATABASE
Redis写入失败MISCONFRedisisconfiguredtosaveRDBsnapshots, but is currently not able to persist on disk_第1张图片

步骤3重启redis服务

或者杀掉redis进程重启

ps -ef|grep redis

在这里插入图片描述

kill -9 {redis进程号}

找到redis-server的bin路径,并且要找到redis配置文件的路径

find / -name redis
find / -name redis.conf

进到redis的bin路径
在这里插入图片描述

redis-cli shutdown   #关闭命令
redis-server /path/to/redis.conf    #启动命令

或者注册服务的重启redis服务

解决方法(3)扩容服务器的虚拟内存,物理方法解决扩展redis服务能用到服务器更大的内存资源

一、查看当前虚拟内存的配置大小

free -h

在这里插入图片描述

二、创建swap文件

cd /usr
mkdir swap
dd if=/dev/zero of=/usr/swap/swapfile bs=1M count=64096

提前保证路径下有剩余的空间
在这里插入图片描述

三.将目标设置为swap分区文件

mkswap /usr/swap/swapfile

在这里插入图片描述

chmod 0600 /usr/swap/swapfile       #改一下权限,系统建议0600

四、 启用swap分区文件

swapon /usr/swap/swapfile
free -h  #检查虚拟内存是否增加了

在这里插入图片描述

五、将虚拟内存的配置增加到开机自动启动配置

vim /etc/fstab         
/usr/swap/swapfile swap swap defaults 0 0  #将这个内容添加到上面的配置文件

在这里插入图片描述
保持文件退出
在这里插入图片描述

六、验证重启服务器之后虚拟内存是否生效

reboot -h now     #重启服务器命令
top    #命令验证

在这里插入图片描述
在这里插入图片描述
验证成功,扩展虚拟内存成功!

你可能感兴趣的:(数据库技术,redis,redis,bootstrap,前端)