Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: Failed opening .rdb for saving: Permission denied

Tags:

redis

I have a redis server 2.8 installed using ubuntu apt-get on ubuntu 12.04.

I have copied a dump.rdb from an other database. Now when I try to start the new server, I constantly get:

[35763] 04 Mar 01:51:47.088 * 1 changes in 900 seconds. Saving...
[35763] 04 Mar 01:51:47.088 * Background saving started by pid 43313
[43313] 04 Mar 01:51:47.088 # Failed opening .rdb for saving: Permission denied

How can I solve this?

like image 561
Niels Kristian Avatar asked Mar 04 '14 00:03

Niels Kristian


3 Answers

You should check your redis.conf file to see the permissions in dir and dbfilename. If the file named in the dbfilename which is located in the path specified in the dir path exists and the permission is also right. then the problem should be fixed.

Hope this will help someone.

P.S.

To find the redis.conf file location, you can use the #ps ax | grep redis to check. Usually it will be passed to the redis-server as input file.

For the dir permissions:it should be 755, for the dbfilename, it should be 644

Sometimes you also need to use top command to check whether the user:group of the redis-server and the owner of dir are consistent. i.e. The redis-server is running by redis:redis, but the dir is under root:root. In this case, you need to chown redis:redis -R dir.

like image 60
chancyWu Avatar answered Nov 17 '22 12:11

chancyWu


Non of the above worked for me.. I've seen everyone around being so concerned on BGSAVE.. but while you're not on production, SAVE gives you a way more straight forward answer: ERR. BGSAVE does not, unless you inspect logs.

After digging dozens of posts I did not find any clue. The only thing that fixed was stopping the redis service and running it manually.

At first I thought it could be related to the user on behalf of redis was running. Not at all: the actual difference was the damn systemd subsystem which at some point in the redis config service file (/etc/systemd/system/redis.service) had the following:

ReadWriteDirectories: -/etc/redis

WoW super cool! ended up this was preventing redis from accessing anywhere in the system at all even though the permissions would perfectly allow it.

How naive of me to think that permission were just enough to ensure something had the proper rights.. (yes, I'm being ironic).

like image 35
Riccardo Manfrin Avatar answered Nov 17 '22 11:11

Riccardo Manfrin


My /lib/system/systemd/redis-server.service file contained the following:

ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis

My /etc/redis/redis.conf file stated that the database should be located in /data/redis

dir /data/redis

The systemd config file above effectively makes /data/redis read-only.

Once I changed the redis.conf file to read:

dir /var/lib/redis

I stopped getting the error.

like image 7
Tim Stewart Avatar answered Nov 17 '22 12:11

Tim Stewart