Install Redis on Ubuntu 16.04 [Comprehensive Tutorial for Beginners]

Install Redis on Ubuntu 16.04 [Comprehensive Tutorial for Beginners]

Introduction

Redis is one of the best memory key value store. There are a lot of other store also available in market such as ArangoDB and Hbase.

But:

Redis is the highly rated memory key value store for it’s performance and language support.

Here, in this tutorial, we are going to see how to install redis on ubuntu 16.04 server.

Requirements

  • You will need a sudo non root user configured on Ubuntu 16.04 server. If you dont have one, follow this guide to create one.

Install Redis Ubuntu

Here, We are going to install latest version of Redis. For that, we will download the package directly from the source and install it on our server.

We have to install build-essential meta-package and tcl package before installing redis.

We can accomplish the task by executing the below command. First, update the package index.

Download the Source Code of Redis

First move to /tmp directory.

Then, Use the below command to download the redis.

Then, extract the file using tar command.

Then, switch to the unpacked redis folder.

Compile and Install Redis

Here, we have to compile the redis binaries using the make command.

Then, test whether those binaries are combined properly.

Then, install the binaries using the next command.

After that, you have to configure the Redis.

Configuring the Redis

Once you install the redis, you have to create the configuration directory for redis. You can do that using the below command.

This command will create the Redis directory and you have to move the redis configuration file from tmp directory to the newly created directory. Here is the command for that.

Now, we have to make some changes in the redis configuration file. Open redis file using the nano editor.

Go through the file and find the supervised directive and it would be set to no.

Change that to systemd.

After that, you have to find the dir directory and set it to /var/lib/redis. 

This will let the redis store the persistent data in a location which is not viewable by ordinary user.

Here is how you make the changes.

After that, save and close the file.

Systemd Unit File Creation for Redis

Now, open the redis.service file using nano editor.

Inside the file, add the below lines.

Here, we are going to add few important lines in the file which will tell server about how our server will work with the system.

We will not run redis on root user. rather we will use a new user called redis and redis group. Then, we wil define how redis has to start and what it should do to recover from errors.

Also, we will mention how to shutdown redis.

Then, add this command also. It will locate the systemd target.

After that, save and close the file.

Creating The Redis User

Now, you have to create the redis user and group. Here is the command for that.

After that, create var/lib/redis directory using the below command.

Now, set the ownership of the directory to Redis user and group.

Then, add access restriction by changing the permission for the directory.

Now, Start the Redis

Then, check the Redis using the below command.

You should get the following output.

There should not be any error.

Now, start the redis server to test it.

Then, a prompt will open. In that type ping

You should get the following as an output.

Then, type this line again.

You will see output as OK. 

Again, type get test

Now, the redis will return the previously input string.

Then type exit and press enter to get out of the redis server environment.

Now, you have to make the redis to initiate at system boot. Here is the command for that.

You should be getting the following output.

Thats all. You have perfectly configured redis on your server.

Conclusion

Handling the key value store is little bit tricky. Your base system should be perfect and running.

Make sure, subscribe for the upcoming tutorials to get notified.

Leave comments, if you have any issues in executing the commands or following the steps.

Leave a Reply

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