Redis: Failed opening .rdb for saving: Permission denied
Asked Answered
M

15

50

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?

Marpet answered 4/3, 2014 at 0:53 Comment(1)
The answer that actually solved my problem was from serverfault.com: serverfault.com/a/800328/429693 The config files were ok, but for some reason redis-cli was with the variables set incorrectly (i.e. different from the config files). It could be that someone had accessed it with malicious intent. After that I noticed I had a Malware in my server and an open port for redis.Vulvitis
C
55

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.

Crowell answered 24/2, 2015 at 1:33 Comment(8)
Where exactly is the permission you refer to?Russelrussell
Thanks. In the end I did chmod 666 and then chmod a+x and now it works. I daresay this isn't recommended but I needed to get it working.Russelrussell
dir and dbfilename is owned by redis and 777 but I still get err on saveCastello
@Crowell error details are not shown, and there's no info in log alsoCastello
@Castello then you should check what's wrong with your log first. If no log, it's hard to guess.Crowell
there is log, but it's not updated with this error messageCastello
Here is how I checked the permissions: stat /var/lib/redis should see Access: (0755/drwxr-xr-x). Then stat /var/lib/redis/dump.rdb and should see Access: (0664/-rw-rw-r--). In my case I saw 0660 for the second one and fixed it with chmod 0664 /var/lib/redis/dump.rdb. Then redis started fine again.Component
@ScottWilleke answer was the correct for me. Thanks a lot!Haig
P
20

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).

Pennipennie answered 11/5, 2018 at 21:38 Comment(3)
It's old but for future ref. I just check the server port as in my case the port is open to the world. I just removed the entry of the open port in aws and all is working fine after that. as the url is localhost so not required also.Lidless
Wow that was it! This is so messed up.Disproportionate
Another item in that service file that might trip people up is ProtectHome=yes. If you want to use a data directory like ~/SSD_Data/redis, that setting will prevent access, so you have to comment out. The redis log will say something like Can't chdir to '~/SSD_Data/redis': Permission denied and no amount of permissiveness on that directory will help.Neogaea
A
10

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.

Autograph answered 13/4, 2018 at 16:7 Comment(0)
P
4

My permission issue seemed to be the result of the Redis user being unable to modify the parent folder (/var/lib/redis/6379) for the purposes of creating a temporary file.

This was seen in an strace of the redis-server process:

open("temp-1833.rdb", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)

The issue was resolved after running the following command:

setfacl -m d:u:redis:rwX,u:redis:rwX /var/lib/redis/6379
Purington answered 8/12, 2015 at 2:35 Comment(1)
It wasn't exactly this issue, but SELinux was ultimately the corporate. I had to use the audit2allow tool to fix it. access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/…Indolent
H
4

For windows only : This means the user does not have permission for this. BY default owner of this file is NETWORK SERVICE, which has very limited access and need to changed(as per documentation)

solution :

  1. go to ur redis folder.

  2. right click --> go to properties--> security tab.

  3. click on advanced.

  4. click on Add to add ur user.

  5. click on select a principal.

  6. enter ur user (for eg GLOBAL\xxx).

  7. click on check names and click on ok

  8. give permissions to this user.

  9. finally change the owner to this user.

Hypocrite answered 4/3, 2017 at 19:35 Comment(0)
O
3

Check the configuration 'dbfilename' in your redis.conf. Your redis running process have no write permission in the path.

Ornithology answered 4/3, 2014 at 3:9 Comment(0)
S
3

In my case all rights were correct(I mean that the most stared answer doesn't help me). BUT! Redis used an incorrect path to file. In config it was correct, but from rails-cli it returned '/proc'. This answer helped me - https://serverfault.com/questions/800295/redis-spontaneously-failed-failed-opening-rdb-for-saving-permission-denied

Warning

For exact question it doesn't matter, but my situation looked like someone hacked server. Link to explanation. So check your setup properly.

Seibel answered 9/3, 2018 at 14:5 Comment(0)
R
3

supervised systemd is intended solely for Type=notify and daemonize yes corresponds to Type=forking.

sudo vim /etc/systemd/system/redis.service

When you see the service file edit the Type=forking

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Type=forking
Group=redis
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

Open up this file

sudo vim /etc/redis/redis.conf

Add these changes to it

daemonize yes
supervised no
Ronnieronny answered 25/2, 2019 at 19:52 Comment(0)
U
3

In my case when I typed the following command sudo tail -F /var/log/redis/redis-server.log I get this log:

987:C 08 Dec 22:28:30.344 # Can't chdir to '/var/lib/redis': Permission denied
1047:C 08 Dec 22:28:30.565 # Can't chdir to '/var/lib/redis': Permission denied
1095:C 08 Dec 22:28:30.876 # Can't chdir to '/var/lib/redis': Permission denied
1119:C 08 Dec 22:28:31.165 # Can't chdir to '/var/lib/redis': Permission denied
1151:C 08 Dec 22:28:31.413 # Can't chdir to '/var/lib/redis': Permission denied
1500:C 08 Dec 22:30:44.706 # Can't chdir to '/var/lib/redis': Permission denied
1523:C 08 Dec 22:30:45.194 # Can't chdir to '/var/lib/redis': Permission denied
1545:C 08 Dec 22:30:45.442 # Can't chdir to '/var/lib/redis': Permission denied
1568:C 08 Dec 22:30:45.696 # Can't chdir to '/var/lib/redis': Permission denied
1590:C 08 Dec 22:30:45.940 # Can't chdir to '/var/lib/redis': Permission denied

That means the user redis doesn't have permission on /var/lib/redis.

That's why I typed this command sudo ls -l /var/lib/redis to see the permissions in this directory. I get the following log:

-rw-r--r-- 1 root root 885 Dec  8 22:12 dump.rdb

That means it was associated with root instead of redis.

Then I typed the following command to change the owner of that directory: sudo chown -R redis:redis /var/lib/redis/.

Then I restarted redis-server by the following command: sudo systemctl restart redis-server.

Boom!! It worked.

Hope this will work for someone, who have similar issue as mine.

Upcoming answered 8/12, 2020 at 22:46 Comment(0)
I
2

If anyone encounters this again and doesn't have a problem upgrading, just upgrade your Redis installation to the latest version. I encountered this problem with Redis 2.8.15, and upgraded to Redis 2.8.22 that was available at the time of this writing. A sysadmin in my company assured me that this was a bug with Redis 2.8.15, and the problem just went away after upgrading.

Iago answered 10/9, 2015 at 15:53 Comment(0)
N
2

I had the same issue with redis used by Sidekiq in Rails application, rm -rf ./tmp/ worked like charm.

Norty answered 29/4, 2017 at 10:46 Comment(0)
I
2

I spent some time on this until i realised that my cmd line session was running in the wrong drive :/. Just in case this might help anyone else!

Islaen answered 17/8, 2017 at 20:5 Comment(0)
P
2

The lock file in the log directory is what was causing this error for me. I was able to clear the error by deleting the lock file:

rm /var/log/redis/lock.

This happened when another system was restored to this one while redis was still running.

Parkins answered 15/1, 2019 at 18:9 Comment(0)
P
2

No one hasn't mentioned about SELinux. On Centos most probably you will have such error when selinux mode = enforcing.

Just check getenforce and if it set to 'enforcing' , hit setenforce 0 and try one more time to run service.

Podolsk answered 1/12, 2020 at 13:38 Comment(0)
O
1

If you are on Windows and the Redis folder was installed in C: \ Program Files \ Redis for example, you will have a problem with access permission. Modifying files within the Program Files folder, usually requires administrator permission and dump.rdb is within this context. In your redis.conf, modify the default directory to anywhere outside the Program Files folder:

from: dir ./
to: dir ../../Exceptions/Redis/

Note that I went up the directory twice to leave the Program Files folder and outside of it I created any directory (C:\Exceptions\Redis). In this directory Redis can save the .rdb file without permission problems.

Occlude answered 16/1, 2021 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.