How to install from redis-5.0.8.tar.gz on linux (Ubuntu)?


Redis data structure is light weight, in-memory and easy to use. This can be very useful, if you have multiple threads that need to share data. I have successfully used redis on raspibian OS(running on Raspberry Pi B+) and Ubuntu 18.04.4 LTS(on Laptop). I had code written in C. Using hiredis, I was able to interact with redis. Here are the steps that were followed to get redis-5.0.8 installed on Ubuntu:-

1)   Download the latest stable version of redis from https://redis.io/download. Extract the redis-5.0.8.tar.gz folder. Navigate inside the extracted folder named redis-5.0.8 .

2)   Open terminal window inside this folder. Run following in terminal
$> sudo -s  #enter the password
$> make  #this will take some time. May be a minute or two
$> make install     
$> nano redis.conf   #now the configuration file is opened to be edited for adjusting to your requirements


This file has good explanation and comments for each line used in configuration. You may do the configurations to meet your specific needs here. I will put down what was done to meet my requirements.
Since I wanted clients from outside the host to connect to redis server using its interface IP address (not just local loopback IP of 127.0.0.1), I had to comment out the bind line to
#bind 127.0.0.1
and turn off protected mode using
protected-mode no
Further, I needed to run the redis in background. So changes were made in following line also
daemonize yes
My requirement was to get the redis server started in background when system starts, without any manual intervention. So I had to change this line also
supervised systemd        
I also wanted the server to continue working irrespective of disk, permission errors. So changed the following
stop-writes-on-bgsave-error no

3)   Now move the redis.conf file to /etc directory
$> mkdir /etc/redis
$> cp redis.conf /etc/redis


4)   Add the redis service to systemd. This is to start the redis server as a service, by default when the system starts
$> nano /etc/systemd/system/redis.service

Add the lines to this file as shown in the image.


 
Now save the file using Ctrl+x then Y .

5)   Create user by following commands.
$> adduser --system --group --no-create-home redis        #creates a user to run this service
$> mkdir /var/lib/redis                    
$> chown redis:redis /var/lib/redis                       #make the user owner of this directory
$> systemctl enable redis

 
6)   Reboot the system.

7)   Open a terminal and start the redis client
$> redis-cli

This opens the client and connect to default server at 127.0.0.1. To check the functionality of redis type following to the prompt that appeared in terminal.
> SET PRINT "HELLO WORLD!"
> GET PRINT


This will return
HELLO WORLD!
at the terminal.
Further reading on how to use redis may be explored from https://redis.io/documentation .

Comments

Popular from this site

How to set static IP address for Raspberry pi in headless setup?

Exception: Please shut down the controller which is running on port 6653: Mininet

Send and Capture icmp packets with type&code using hping