1

I am trying to set redis up to use a Unix Socket.

I am using the stock Debian installation /etc/redis/redis.conf except with the following additions at the end of the file, based on this info:

# create a unix domain socket to listen on 
unixsocket /run/project/redis.sock 

# set permissions for the socket 
unixsocketperm 775 
 
#requirepass passwordtouse 
# bind 127.0.0.1 
 
daemonize yes 
 
# maximum memory allowed for redis 
maxmemory 128Mb 

I am requesting it to create the unix socket in /run/project/redis.socket:

# ll /run/project
total 4
drwxrwxrwx  2 michael  www-data 100 Aug 29 16:32 .
drwxr-xr-x 21 root     root     640 Aug 30 10:49 ..

I added user redis to the group www-data, and in desperation added redis to group michael.:

$ cat /etc/group | grep redis
www-data:x:33:michael,redis
michael:x:1000:www-data,redis
redis:x:119:

To me I think the permissions are fine:

$ sudo -u redis touch /run/project/foo
$ ll /run/project/foo
-rw-r--r-- 1 redis redis 0 Aug 30 11:13 /run/project/foo

However when I restart the redis server it fails:

$ systemctl restart redis-server.service
Job for redis-server.service failed because the control process exited with error code.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
$ systemctl status redis-server.service
redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-08-30 10:49:52 SAST; 3min 47s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 2465457 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
   Main PID: 2465457 (code=exited, status=1/FAILURE)
     Status: "Redis is loading..."
        CPU: 23ms

Aug 30 10:49:52 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 10:49:52 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.

This is the log file (apparently the warning about TimeoutStartSec / TimeoutStopSec is to be ignored, accordingly to my research.

2465442:C 30 Aug 2022 10:49:51.155 # WARNING supervised by systemd - you MUST set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit. 
2465442:C 30 Aug 2022 10:49:51.158 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 
2465442:C 30 Aug 2022 10:49:51.158 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=2465442, just started 
2465442:C 30 Aug 2022 10:49:51.158 # Configuration loaded 
2465442:M 30 Aug 2022 10:49:51.158 # Opening Unix socket: bind: Read-only file system 
$ journalctl -xeu redis.service
-- Journal begins at Mon 2021-08-16 08:09:33 SAST, ends at Tue 2022-08-30 10:59:15 SAST. --
-- No entries --

Using Debian. Installed redis with sudo apt install redis.

I tried this solution, but get this error:

$ sudo systemctl enable redis.service
Failed to enable unit: Refusing to operate on alias name or linked unit file: redis.service

UPDATE: File permission on log/config files:

$ ll /var/lib/redis/dump.rdb
-rw-rw---- 1 redis redis 93 Aug 29 14:53 /var/lib/redis/dump.rdb
$ ll /etc/redis/redis.conf 
-rw-r----- 1 redis redis 86461 Aug 30 11:11 /etc/redis/redis.conf
$ ll /var/log/redis/redis-server.log
-rw-rw---- 1 redis adm 22476 Aug 30 11:22 /var/log/redis/redis-server.log

Update about stopping then reunning /usr/bin/redis-server:

$ systemctl stop redis-server.service
$ systemctl status redis-server.service
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-08-30 11:22:15 SAST; 1h 44min ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 2682 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
   Main PID: 2682 (code=exited, status=1/FAILURE)
     Status: "Redis is loading..."
        CPU: 24ms

Aug 30 11:22:15 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 11:22:15 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
$ /usr/bin/redis-server /etc/redis/redis.conf
$

UPDATE: Tried purging and resintalling redis and it did not help. The installation is fine, if I start it with the default config ir runs:

# systemctl status redis-server.service
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-08-30 20:52:29 SAST; 44s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 26102 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 1133)
     Memory: 7.4M
        CPU: 90ms
     CGroup: /system.slice/redis-server.service
             └─26102 /usr/bin/redis-server 127.0.0.1:6379

Aug 30 20:52:29 vps systemd[1]: Starting Advanced key-value store...
Aug 30 20:52:29 vps systemd[1]: Started Advanced key-value store.

However soon as I add the following to use a unix socket, it stops working:

unixsocket /run/project/redis.sock

# set permissions for the socket
unixsocketperm 775

requirepass passwordtouse
# bind 127.0.0.1

daemonize yes

# maximum memory allowed for redis
maxmemory 128Mb
run_the_race
  • 167
  • 1
  • 9

2 Answers2

0

I guess you messed up with essential redis file permissions. Please check below and make sure files/configs can be accessible by redis

redis-server.log(and associated logs files)
dump.rdb
Any config file which is read by redis process

Update: If something else is stopping redis to start try below command (Change path according to your setup) it will show you exact issue most of the time.

/usr/bin/redis-server /etc/redis/redis.conf
asktyagi
  • 2,860
  • 2
  • 8
  • 25
  • Thanks for the suggestion, but `redis-server.log/dump.rdb/redis.conf` are all owned by redis, I updated my post to show the info. – run_the_race Aug 30 '22 at 09:59
  • Updated my answer, please try if that help you(change path according to your setup). – asktyagi Aug 30 '22 at 10:35
  • It prints nothing for me, guessing it means there are no errors in the config. PS the paths were the same for my system: `/usr/bin/redis-server -> redis-check-rdb` – run_the_race Aug 30 '22 at 10:46
  • First stop redis server make sure it's stopped, after that start it manually with above command and update your question with corresponding output please. – asktyagi Aug 30 '22 at 10:59
  • I stopped then check the status, then ran the command, still nothing printed. – run_the_race Aug 30 '22 at 11:08
  • You can try reinstalling redis(with purge file), if possible. – asktyagi Aug 30 '22 at 11:14
  • I tried purging, and then resintalling it, and it did not change anything. In my updated post I explain its not the installation (runs fine without using unix socket), its the configuration. The problem is in those few lines of trying to make it use a unix socket. – run_the_race Aug 30 '22 at 18:58
  • Can you change these parameters `unixsocket /run/redis.sock` and `unixsocketperm 700` and restart? – asktyagi Aug 31 '22 at 02:48
  • Tried changing socket params. Same result, after the configuration is loaded, the last item in the log is `Opening Unix socket: bind: Read-only file system`. I don't know if that is an error or is okay. – run_the_race Aug 31 '22 at 08:14
0

unixsocketperm 777

Then restart redis.

Lots of info on this, google it

It worked for me and others.

I think I found out about it here... https://github.com/redis/node-redis/issues/204