Redis是很有效的一项服务,但是初学者会碰到很多问题,我希望这篇文章能够帮助到他们。
在运行Redis服务后,几分钟后抛出一个错误:
Failed Opening .rdb for saving:Permission denied.
Background saving error
根据错误提示,是Redis后台保存时遭遇了权限问题。
-
在终端中打开redis.conf文件,redis.conf文件通常是在/usr/local/bin 目录下
$ cd /usr/local/bin
$ vim redis.conf
-
在redis.conf文件中搜索dir的配置项,dir配置项是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 ./
此处./表示redis-server所在的目录,查看该目录的权限
-
查看权限
$ ls -l
....
-rw-r--r--. 1 root root 35 Aug 4 00:59 dump.rdb
....
此处dump.rdb文件root账号是有读写权限,而同为管理员组的其他账号之后读权限,所以造成了上诉问题
-
修改文件权限:
$ chmod g+w dump.rdb