Daily Archives: December 27, 2016

I have been asked by few folks on quick tutorial setting up Redis under systemd in Ubuntu Linux version 16.04.

I have blogged quite a bit about Redis in general –https://gennadny.wordpress.com/category/redis/ , however just a quick line on Redis in general. Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. That makes Redis one of the most popular key value data stores in existence today. Below are steps to install and configure it to run under systemd in Ubuntu 16.04 and above.

After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do this by typing:

$ make test

This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing:

$ sudo make install

Now we need to configure Redis to run under systemd. Systemd is an init system used in Linux distributions to bootstrap the user space and manage all processes subsequently, instead of the UNIX System V or Berkeley Software Distribution (BSD) init systems. As of 2016, most Linux distributions have adopted systemd as their default init system.

To start off, we need to create a configuration directory. We will use the conventional /etc/redis directory, which can be created by typing

$ sudo mkdir /etc/redi

Now, copy over the sample Redis configuration file included in the Redis source archive:

$ sudo cp /tmp/redis-stable/redis.conf /etc/redis

Next, we can open the file to adjust a few items in the configuration:

$ sudo nano /etc/redis/redis.conf

In the file, find the supervised directive. Currently, this is set to no. Since we are running an operating system that uses the systemd init system, we can change this to systemd:

Next, find the dir directory. This option specifies the directory that Redis will use to dump persistent data. We need to pick a location that Redis will have write permission and that isn’t viewable by normal users.
We will use the /var/lib/redis directory for this, which we will create

. . .
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis
. . .

Save and close the file when you are finished

Next, we can create a systemd unit file so that the init system can manage the Redis process.
Create and open the /etc/systemd/system/redis.service file to get started: