Installing Redis As A Service

In previous articles, I was just starting redis instances from command line with parameters. But, in production environment we want to keep it always open and work in background more reliable. For this, we install it as a service of course. This way we can give that service custom credentials, keep bootable, and make more built-in on OS.

This is also not the only problem we need to solve in production environment. You need to prepare a clean folder structure for keeping everything organized for redis. And most probably you want some failover mechanism too. This way, you can easily handle some systematic failures. Fortunately, after redis 2.6, we have a built-in sentinel mechanism. You can define some sentinels to make failover between redis instances.

Now, I want to show you how I am installing it on both Windows and Linux environments. This article is not going to be about architectural design of redis servers, but I am also planning to write another article about it like how to create a good sentinel system, which server is a good candidate to install a sentinel on it, how to build a good replication system, etc. But, as you know these things are very domain specific and decision based. Eventually, topics are becoming more subjective. So, here, I only want to talk about installation part.

For Debian Linux

For Linux, I am going to use my Vagrant Debian VM like in the previous articles. Luckily, we have service script in redis github page. So, we are not going to work hard for installing it on Linux. Just in a few simple steps, we are good to go for Linux:

Now let’s configure our config file like below:

Lets start the service again:

Until here, we installed redis executables to our machine and created a service working well. For failover mechanism, now we need to add a sentinel:

And here is our sentinel config file:

Before starting our sentinel, we need to change our sentinel service script a little which is /etc/init.d/redis_16371:

Here, let’s see if we setup it properly:

For making sure everything working properly, you can connect to servers via redis-cli and query some commands like info.

For Windows

For Windows, I have no written cmd script actually. But I made some folder structure for keeping things more smooth. Below is my basic installation steps on a Windows machine:

  • Get MSOpenTech/redis release executables and put them into C:\redis\bin\ folder.
  • Create Redis Service configuration file in C:\redis\ folder and name it with service port number, like C:\redis\6371.conf
  • Create C:\redis\log folder and set logging configuration to map logging file, like C:\redis\log\6371.log
  • Create a folder named with service port number under C:\redis , like C:\redis\6371\
  • Map default directory and other related directories of redis service to above folder path, like .dmp file path, .aof file path.
  • Give necessary permissions to redis service user on C:\redis\ folder and its all sub folders.
  • Install redis service and start it with desired credentials.

Something like this 🙂  (16371 folder explained below)

Redis Folder Structure on Windows

So, its that easy for an instance of redis on Windows. And here are the goods about installation part:

Here, we setup our redis server (self-documented configuration file link for windows here):

And here is a sample sentinel configuration file (sentinel configuration documentation):

Now, after preparing folder structure and making configurations for redis servers, we can install and start them like this:

I hope you liked the article. As you know, configurations are very basic for disabling the verbosity in article. Normally, you can make everything working smoothly, but sometimes you may get permission related errors. Don’t worry and continue.

Have a nice day, and keep up good work.

I am csharp developer, mathematics graduated, visionary coder, tennis player, bad english speaker, blog reader, blog writer, and very lazy person. I will be sharing my personal thoughts, experiences, hobbies that I'd like to do and different news that takes my interest as a simple, regular person. Sometimes in English, sometimes in Turkish.