Redis is a popular open source, in-memory data structure store that competes with other databases such as SQLite and MySQL. It’s often used to speed up web application response time by caching pages or content generated from user interactions on websites or applications. In this tutorial, we will install Redis on Ubuntu 18.04 LTS and monitor the installation process using the built-in command line tool ‘redis-server’.
What’s the big deal about Redis? Redis has established a reputation as a go-to data storage. It’s a key-value, in-memory, and open-source data store. Redis is an excellent message broker, cache, and database candidate/application because of these characteristics.
Redis’ résumé also shows that it supports a variety of data structures, including Sets, Hashes, Lists, and Strings. Multiple Redis nodes and Redis Cluster enable excellent Redis availability thanks to features like automated partitioning and Redis Sentinel.
Prerequisite
On the Ubuntu operating system, you must be a sudoer/root user.
Redis installation on Ubuntu
Ensure that your Ubuntu operating system is up to date, since this aids in the performance optimization of both installed and uninstalled application packages.
$ sudo apt update && sudo apt upgrade -y
Then, to install Redis on your Ubuntu machine, use the command below.
$ sudo apt install redis-server -y Install Redis in Ubuntu
Once the installation is complete, check the version of Redis that is installed on your machine.
$ redis-server –version Check Redis Version in Ubuntu
Then, make sure Redis is up and running by enabling it and checking its status.
$ sudo systemctl enable redis-server $ sudo systemctl status redis-server Check Redis Status in Ubuntu
Setting up Redis on Ubuntu
After we’ve installed Redis and verified that it’s up and running, we’ll need to make some crucial configuration changes. Redis’ default installation does not allow for remote connections. On the system hosting Redis, the default setup only allows connections from localhost (127.0.0.1).
If you just have one server, you don’t need to allow remote access/connection in your Redis settings. If you need to run Redis on a separate/remote server for whatever reason, you’ll need to configure it to support remote connections.
On your Ubuntu machine, use the following command to access Redis’ primary configuration file:
/etc/redis/redis.conf sudo nano
On the file, trace the following sections:
Configuration File for Redis
This section explains how to bind Redis to the IP addresses of all or specified remote computers. For example, if we want any remote user to be able to connect to this Redis server, we may comment out or remove the line bind 127.0.0.1::1 and replace it with bind 0.0.0.0::1.
Redis Remote Connection should be enabled.
Restart the Redis server for the new configuration modifications to take effect.
sudo systemctl redis-server restart
Next, make sure that all of Redis’ interfaces are listening.
$ ss -an | grep 6379 Check Redis Listening State
Because Redis communicates on port 6379, your firewall should be set to allow traffic over this port if it is enabled.
ufw allow 6379/tcp $ sudo ufw allow 6379/tcp ufw reload $ sudo ufw status $ sudo
Redis Remote Connection is being tested.
Install redis-tools on the remote workstation that wants to connect to the Redis server to make client-server communication easier.
apt install redis-tools -y $ sudo apt install redis-tools -y
The redis-cli program will now be used to ping the Redis server via IP address.
$ redis-cli -h 192.168.100.23 ping Test Redis Remote Connection
The PONG result indicates that the two distant computers are able to connect with one another.
The installation, setup, and testing of the Redis server on Ubuntu were covered in this post. Refer to the file /etc/redis/redis.conf for a more detailed Redis setup tutorial.