Redis Daemon not creating a PID file

On my Ubuntu 18.04, I was getting the same error.

Error reported by redis (on /var/log/redis/redis-server.log):

 # Creating Server TCP listening socket ::1:6379: bind: Cannot assign requested address

This is because I've disabled IPv6 on this host and redis-server package (version 5:4.0.9-1) for Ubuntu comes with:

bind 127.0.0.1 ::1

Editing /etc/redis/redis.conf and removing the ::1 address solves the problem. Example:

bind 127.0.0.1

Edit: As pointed out in the comments (thanks to @nicholas-vasilaki and @tommyalvarez), by default redis only allows connections from localhost. Commenting all the line, using:

# bind 127.0.0.1 ::1

works, but makes redis listen from the network (not only from localhost).

More details can be found in redis configuration file.


For those experiencing on Debian buster:

Editing nano /etc/systemd/system/redis.service

and adding this line below redis [Service]

ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"

It suppose to look like this:

[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
ExecStop=/bin/kill -s TERM $MAINPID
ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"
PIDFile=/run/redis/redis-server.pid

then:

sudo systemctl daemon-reload

sudo systemctl restart redis.service

Check redis.service status:

sudo systemctl status redis.service The pid file now should appear.

Tags:

Redis

Rhel6