How can I change Redis configuration directory?
-
Hi, I want change Redis configuration directory to
/home/redis
.
So I make a fresh reinstall a Debian 11 and used this commands:add-apt-repository ppa:chris-lea/redis-server -y apt-get update apt-get install -y redis-server mkdir -p /home/redis /home/redis/sock/ /home/redis/log/ /home/redis/db/ /home/redis/lib/ cp /etc/redis/redis.conf /home/redis/lib chown -hR redis:redis /home/redis chmod 2770 /home/redis chmod 2770 /home/redis/* chmod 640 /home/redis/lib/redis.conf # ---------------------------------------------------# vim /etc/init.d/redis-server # Change: DAEMON_ARGS=/etc/redis/redis.conf # To: DAEMON_ARGS=/home/redis/lib/redis.conf CTRL+C :wq vim /etc/systemd/system/redis.service # Change: ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no # To: ExecStart=/usr/bin/redis-server /home/redis/lib/redis.conf --supervised systemd --daemonize no # Change: ReadWriteDirectories=-/etc/redis # To: ReadWriteDirectories=-/home/redis CTRL+C :wq # ---------------------------------------------------# sudo systemctl daemon-reload sudo service redis-server restart
Why 2270 permission? This is default permission for Redis user in
/etc/redis
directory so I thinked this maybe help but same (Permission Denied)User permissions from WinSCP group:user:
output from syslog:
redis-server[639]: 639:C 07 Sep 2021 11:33:19.214 # Fatal error, can't open config file '/home/redis/lib/redis.conf': Permission denied
Only working this command from root:
/usr/bin/redis-server /home/redis/lib/redis.conf
I searched solutions in google in websites like stackoverflow but no one helped me
I know this is not a redis.io forum but I think someone maybe can help.
Thanks for help in advance. -
@Mroczny, I am checking the post, and I wanted to ask: Did you solve the problem by commenting #ProtectHome:yes in the service file, or were there other steps you took?
I am trying to set up a symlink to where my redis.conf is on /etc/. but it keeps failing; as you mentioned, the web doesn't have much info about it. -
@Daniel-Mendoza-Pupo Why are you changing the location of the Redis configuration anyway? Moving it to the home directory is potentially problematic if only because it could end up readable by that user.
It's in
/etc
specifically so unprivileged users can't access it.But... likely you could just tell Redis to use a different config file
-
@julian, because I am using git to control the changes in redis.conf in all my nodes, that's why? I mentioned home directory, but it will be in secured location. So should I go with the include /path/to/local.conf?
-
In that case if you want to reference a
redis.conf
elsewhere, you just have to modify whatever runner is handling redis... for example, Redis installed on Fedora uses systemd, whose config is stored in/usr/lib/systemd/system/redis.service
So you'll need to edit that file (or something ) to change the config file path, which is the first argument passed to the redis executable.
-
@julian I tried that route, and it still didn't work:
-rw-r--r--. 1 redis redis 63122 Mar 6 13:56 /path/to/redis/redis.conf
redis.service: (changed the path to my redis.conf)
ExecStart=/usr/bin/redis-server /path/to/redis/redis.conf --supervised systemsAfter changing the redis service file:
systemctl daemon-reload
systemctl start/restart redis
β redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
ββlimit.conf
Active: failed (Result: exit-code) since Thu 2024-03-07 16:18:06 EST; 7s ago
Process: 3672598 ExecStop=/usr/libexec/redis-shutdown (code=exited, status=0/SUCCESS)
Process: 3672869 ExecStart=/usr/bin/redis-server /path/to/redis/redis.conf --supervised systemd (code=exited, status=1/FAILURE)
Main PID: 3672869 (code=exited, status=1/FAILURE)Mar 07 16:18:06 my-lab systemd[1]: Starting Redis persistent key-value database...
Mar 07 16:18:06 my-lab redis-server[3672869]: 3672869:C 07 Mar 2024 16:18:06.355 # Fatal error, can't open config file '/path/to/redis/redis.conf'
Mar 07 16:18:06 my-lab systemd[1]: redis.service: Main process exited, code=exited, status=1/FAILURE
Mar 07 16:18:06 my-lab systemd[1]: redis.service: Failed with result 'exit-code'.
Mar 07 16:18:06 my-lab systemd[1]: Failed to start Redis persistent key-value database.