Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install and configure Redis on Ubuntu 16.04 with systemd
  1. Install pre-requisities

sudo apt-get install build-essential tcl

  1. Install Redis
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
make
make test
sudo make install
  1. Configure Redis
sudo mkdir /etc/redis
sudo cp /tmp/redis-stable/redis.conf /etc/redis
sudo nano /etc/redis/redis.conf

In the file, change the supervised directive's value to systemd.

...
supervised systemd
...

Next, specify the working directory for Redis. This is the directory that Redis will use to dump persistent data. We can use /var/lib/redis

...
dir /var/lib/redis
...

Save and close the file.

  1. Configure systemd to start Redis on boot

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

Copy the contents of this gist to the file, save and close.

  1. Create Redis user, group and directories
sudo adduser --system --group --no-create-home redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis
  1. Start the Redis service and set Redis to start on boot
sudo systemctl start redis
sudo systemctl enable redis
@harveymatt

This comment has been minimized.

Copy link

@harveymatt harveymatt commented Aug 15, 2017

I also had to update my redis config to run as a daemon using daemonize yes

@qreeves

This comment has been minimized.

Copy link

@qreeves qreeves commented Feb 28, 2018

You might also need Type=forking under [Service] in redis.service

@anhducbkhn

This comment has been minimized.

Copy link

@anhducbkhn anhducbkhn commented Mar 27, 2018

thanks

@drienkop

This comment has been minimized.

Copy link

@drienkop drienkop commented May 21, 2018

@harveymatt systemd actually has a problem when you run redis with daemon yes. See: https://serverfault.com/questions/616430/why-isnt-systemctl-starting-redis-server-on-centos-7

@zqhhh

This comment has been minimized.

Copy link

@zqhhh zqhhh commented Oct 15, 2018

very nice

@sshymko

This comment has been minimized.

Copy link

@sshymko sshymko commented Jan 22, 2019

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

Alternative settings that seem to be equivalent:

redis.conf redis.service
daemonize no
supervised systemd
Type=notify
daemonize no
supervised no
Type=exec
daemonize yes
supervised no
Type=forking

Example config: Gist.

@Swaggadan

This comment has been minimized.

Copy link

@Swaggadan Swaggadan commented Feb 21, 2020

How do i migrate from apt install redis to this?

@nickolay-github

This comment has been minimized.

Copy link

@nickolay-github nickolay-github commented Oct 20, 2020

And need to remember to change the permissions of the config file.
sudo chown redis:redis /etc/redis/redis.conf

I was getting an error when changing the redis configuration using the command redis-cli config rewrite until I changed the ownership of the conf file:

(error) ERR Rewriting config file: Permission denied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment