Installing Redis on Debian as a Service

Support this website by purchasing prints of my photographs! Check them out here.

If you'd like to have the most recent version of Redis installed on your Debian machine, follow along with this guide. Unfortunately, the process of installing it is not as easy as sudo apt-get install redis, which you probably already knew since you're reading this. The current version of Redis, at the time of me writing this, is 2.6.13. Go to the website and copy the download link and be sure to change the version in the URL below:

# Install the required tools to build the source
sudo apt-get install build-essential
# Download and extract the files
tar -xzf redis-2.6.13.tar.gz
cd redis-2.6.13
# Compile
make install

Now that you've got it “installed”, you're going to want to make it a Debian service (so that it can run on startup, and you can use commands like `sudo service redis start`):

# Create a user account for Redis
sudo adduser --system --no-create-home --disabled-login --disabled-password --group redis
# Make a writable log file
sudo touch /var/log/redis.log
sudo chown redis:redis /var/log/redis.log
sudo chmod u+w /var/log/redis.log
# Make an init script
cd /etc/init.d/
wget -O redis
sudo chmod u+x redis
sudo update-rc.d -f redis defaults
# Make a place to store your database
sudo mkdir /var/redis
sudo chown redis:redis /var/redis
sudo chmod u+xw /var/redis

Next, you'll want to edit the configuration script. Do the following:

sudo mkdir /etc/redis
sudo touch /etc/redis/redis.conf
sudo chown redis:redis -R /etc/redis/
sudo vim /etc/redis/redis.conf

Here is what I use for my redis.conf file:

daemonize yes
pidfile /var/run/
logfile /var/log/redis.log
port 6379
# bind
# unixsocket /tmp/redis.sock
timeout 300
loglevel verbose
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /var/redis/
# requirepass foobared

Once that's all done, run the following to make sure everything was installed properly:

$ sudo service redis start
$ redis-cli

If you see an error when the server is starting, or an error after running the CLI script that it cannot connect, something went awry. Leave a comment and I'll be sure to lend a hand.

Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.