解決Redis報錯Redis is configured to save RDB snapshots, but it is currently not able to persist on disk

Redis報錯信息

在Spring Boot中集成Redis客戶之後,進行數據操作,發現報如下錯誤:

org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is 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.

	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54)
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52)
	at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.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.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:270)
	at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799)
	at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:148)
	at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:281)
	at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:240)
	at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:60)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
	at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
	at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)

報錯原因

從Redis層面來分析錯誤的直接原因是:

Redis被配置爲保存數據庫快照,但它目前不能持久化到硬盤。用來修改集合數據的命令不能用。請查看Redis日誌的詳細錯誤信息。

也就是說,Redis無法將緩存中的數據寫入本地磁盤。

針對Redis報錯無法寫入磁盤,往往有以下原因:

  • 磁盤滿了
  • Redis配置問題
  • 操作權限問題

如果磁盤滿了,直接清理磁盤或進行擴充即可。

解決方案

問題一

如果是權限問題,查看日誌會發現如下日誌:

11875:M 06 Mar 2020 09:00:12.034 * 1 changes in 3600 seconds. Saving...
11875:M 06 Mar 2020 09:00:12.035 * Background saving started by pid 12625
12625:C 06 Mar 2020 09:00:12.036 # Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis-5.0.7) for saving: Permission denied

如果是權限問題,則服務對應目錄的權限,或在配置文件中修改目標目錄到有權限操作的目錄。

默認目錄配置如下:

# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

修改下面的dir路徑:

dir /Users/zzs/tools/dbs

然後重啓即可。在重啓的過程中可能依然由於無法保存數據而死循環,此時就需要殺手鐗了。

問題二

如果是配置問題導致,則可進行如下修改。

使用redis-cli連接上redis,然後執行如下命令:

config set stop-writes-on-bgsave-error no

通過將stop-writes-on-bgsave-error設置爲no來進行解決。但這種方案治標不治本,從根本上來講,還是需要大家查看後臺異常原因,進行有針對性的解決。

原文鏈接:《解決Redis報錯Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.

精品SpringBoot 2.x視頻教程

《Spring Boot 2.x 視頻教程全家桶》,精品Spring Boot 2.x視頻教程,打造一套最全的Spring Boot 2.x視頻教程。


程序新視界

公衆號“程序新視界”,一個讓你軟實力、硬技術同步提升的平臺

csdn-微信公衆號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章