How to Install Redis on Ubuntu 18.04 | 20.04

How to Install Redis on Ubuntu 18.04 20.04

This post shows users and new students that how to Install Redis on Ubuntu 18.04 | 20.04. If you’re going to Install Redis on Ubuntu then this post is ideal for you.

Redis (for REmote DIctionary Server) is an open source, in-memory data structure that is used as a distributed, in-memory key–value database, cache and message broker, with optional durability. it is also known as quick-response database.

Redis is supports many different kinds of data structures such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps etc.

Ubuntu is a Linux Operating System based on Debian and mostly composed of non-profit(free) and open-source software. It is a complete Linux operating system that compatible with desktops, laptops, server and other devices. Ubuntu is Open Source so it is freely available for both community and professional support.

If you are a learner and looking for a Linux distribution for Learning then Ubuntu Linux Operating System is best for you as a beginning.

Please follow below steps to start Installing Redis on Ubuntu 18.04 | 20.04 :

Step 1: Install Redis Server

As writing this post we assumes that your server account is able to running administrative privileges.

Run the below commands to installing Redis.

sudo apt update
sudo apt install redis-server

When you run the above commands, Redis server is installed and ready to use.

Now run the below commands to stopstart and enable Redis Server.

sudo systemctl stop redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-server

To check if the server is running or not, run the below commands .

sudo systemctl status redis-server

When you run above command, it will show the output similar as below:

Output:
redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-11-29 09:02:30 CST; 15s ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
 Main PID: 26589 (redis-server)
    Tasks: 4 (limit: 4674)
   CGroup: /system.slice/redis-server.service
           └─26589 /usr/bin/redis-server 127.0.0.1:6379
...................................................

Step 2: Configure Redis Server

By default, Redis does not allow to access from remote locations. All access is restricted to the local host of the server it is installed on. ( For example: 127.0.0.1).

If the Redis Server and the applications is running on a single server then no remote access is necessary. But If both the Redis server and applications running on separate hosts, then remote access is required.

So for do that open the Redis configuration file by using the below commands :

sudo nano /etc/redis/redis.conf

After open the config file and change the highlighted line as shown below by replacing 127.0.0.1 with all zeros ( 0.0.0.0 ) or replacing with specific host IP that will need remote access.

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 ::1


# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.

Now save and exit file. then restart Redis service.

sudo systemctl restart redis-server

To check that Redis is listening for all connections on 0.0.0.0 by running the below commands:

ss -an | grep 6379

You will get a result as show below:

Output:
tcp  LISTEN 0      128       0.0.0.0:6379             0.0.0.0:*                                   
tcp  LISTEN 0      128      [::1]:6379                [::]:*

If you have Ubuntu firewall, then you need to add the policy below to allow all hosts on your subnet ( 192.168.0.0 ) access to the Redis server and port number.

sudo ufw allow proto tcp from 192.168.0.0/24 to any port 6379

For check if the Redis hosted on IP address 192.168.0.5 is responding or not to remote host. For do that type the below commands from the remote server.

redis-cli -h 192.168.0.5 ping

When you run the above command then Redis server will respond with a pong.

If you receive reply then it means Redis is working properly.

That’s all

If you find any error and issue in above steps , please use comment box below to report.

Related Posts

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.