Posted by & filed under Linux, Redis.

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
wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
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 https://gist.github.com/peterc/408762/raw -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/redis.pid
logfile /var/log/redis.log
port 6379
# bind 127.0.0.1
# 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
> INFO

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.

9 Responses to “Installing Redis on Debian as a Service”

  1. Jonathan

    Thomas,
    using: redis-2.8.0-rc3

    $ sudo redis-server
    # Creating Server TCP listening socket *:6379: unable to bind socket

    $ sudo redis-server /etc/redis/redis.conf
    $

    but ps ax does not list redis-server

    sudo apt-get install redis-server is now possible, but out of date and more seriously was not keeping a log, and SAVE gave err
    ie works but all data is lost on reboot.

    Reply
  2. seunggu lee

    Thanks for the guide, raspberry pi redis.
    But my raspberry pi not working.

    $ sudo service redis start
    Could not connect to Redis at 127.0.0.1:6379: Connection refuese.

    how can i fix it?

    Reply
  3. Michael

    If you can’t get this to work, check the location of redis-server in the script. The pi does not always install into /user/bin. It can also go into /usr/local/bin.

    Reply
  4. Guzman Monne

    Thank you very much for this tutorial. I also had the same problem as Jonathan, and fix it changing the init script to /usr/local/bin as Michael posted

    Reply
  5. alex

    I’m confused since you (and also redis webpage) doesn’t specify where to download redis, like if this doesn’t matter…
    I downloaded it in /home/myuser/Downloads/redis.xxxx/
    and when I made $make install it created a dir inside /home/myuser/Downloads/redis.xxxx/src/

    now in the entire guide you put steps as if magically linux should know where it was installed.

    when I did $sudo service redis start I got no notification, and server is not running, if I do $ps aux | grep redis I got nothing but the grep command in the processes list.

    what do you think could be problem ?

    Reply
  6. alex

    Ok, I got the idea, you need to edit:

    /etc/init.d/redis

    and change this line
    DAEMON=/usr/bin/redis-server
    to
    DAEMON=/usr/local/bin/redis-server

    this is in case you have redis server and other clients inside /usr/local/bin.

    @brunto mentioned but he was not specific with details.
    thanks for tutorial.

    Reply
  7. tane

    i followed the instructions and had this error
    # redis-cli
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    not connected>

    i fixed it as by changing the init script as it was shown by Alex .
    thanks you all for your comments

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>