LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Install and Use Redis on a Ubuntu 20.04 Server

Tags: , , , Date/Time: February 12, 2021 @ 1:44 am, by Jon Biloh

How to Install and Use Redis on a Ubuntu 20.04 Server

This article was contributed by the folks at RackNerd – a provider of shared hosting, reseller hosting, VPS hosting, dedicated servers, DRaaS, colocation, and more. If you are looking for a VPS with full root access to set up Redis on, be sure to review their latest LowEndBox special offers here.

Redis, or Remote Dictionary Server, was created by Salvatore Sanfilippo in 2009. It is an open-source project and provides an in-memory data structure platform. It implements a key-value distributed database supporting various types of data, such as sets, bitmaps, streams, and spatial indexes. The Redis is popularly used as a cache, message broker, and database.

Today, we will see how you can install and use the Redis software on your Ubuntu 20.04 system.

  1. Requirements

This tutorial is for Ubuntu 20.04, so make sure your operating system is running Ubuntu 20.04. Also, root access to the system is required before we proceed.

  1. Install Redis

It is an easy job to get Redis installed on your system because it is included in the repositories of Ubuntu 20.04.

Run the following commands to get Redis installed:

sudo apt update

sudo apt install redis-server

After the installation is done, Redis will automatically start running in the background. To make sure that the installation was successful, run the next command:

sudo systemctl status redis-server

If the installation were completed successfully, you would see the Redis server’s status as the output.

In case Redis is installed properly, but it fails to start, make sure that IPv6 is disabled on the server.

  1. Configuring remote access

By default, you can only connect to Redis through the local host at 127.0.0.1. However, you can also enable remote access for Redis.

To enable remote access, you need to open the config file for Redis. You can do this by the following command:

sudo nano /etc/redis/redis.conf

Now, find the line that says, “bind 127.0.0.1 ::1” and put a “#” before it to comment that line.  You can now save the file and restart the Redis service by running this command.

sudo systemctl restart redis-server

To confirm that remote access has been configured, run the following command.

ss -an | grep 6379

If the output displays 0.0.0.0, it means that it is listening to all IP addresses on port 6379.

  1. Configure firewall

Now that we have configured the remote access for Redis. We need to configure the firewall for port 6379 so that incoming connections are allowed. Run the following command to enable traffic for Redis.

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

Make sure that you replace “192.1.168.111.0/24” with the IP address of your remote server. The firewall only allows traffic from this IP address.

To verify the remote access, you can run the following command on your remote machine:

redis-cli -h <Your_Redis_IP_Address> ping

If everything is working properly, you will see the output that says “PONG”.

Thanks for reading! Please leave any questions or feedback below.

I'm Jon Biloh and I own LowEndBox and LowEndTalk. I've spent my nearly 20 year career in IT building companies and now I'm excited to focus on building and enhancing the community at LowEndBox and LowEndTalk.

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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