This post shows students and new users the step to install and configure Redis on Ubuntu Linux. Redis is an in-memory key-value and data store commonly used as a database to store data structures such as strings, hashes, lists, sets, ordered sets with range queries, etc.
At a higher level of deployment, you can also provide high availability through Redis Sentinel, including monitoring, automatic notification failover, and partitioning across multiple Redis nodes.
If you want to speed up your dynamic apps or websites, it can be helpful to use Redis to cache and return frequently requested items. Redis is commonly implemented with WordPress, Drupal, and other dynamic PHP-based web applications.
Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.
Ubuntu is a great Linux operating system for beginners.
To start installing Redis on Ubuntu Linux, follow the steps below.
How to install Redis on Ubuntu Linux
This publication assumes that your account on the server can be run with administrative privileges. That means you can run the sudo process.
Redis is available in the default Ubuntu repositories. However, the version that comes with Ubuntu may not necessarily be the most recent. If you need to install the latest version of Redis, add your repository and install it from there.
Installing Redis on Ubuntu is pretty straightforward. Just run the following commands to install it on Ubuntu Linux.
sudo apt update sudo apt install redis-server
After running the above commands, the Redis server should be installed and ready to use. The following commands can be used to stop, start and enable Redis Server to start automatically every time the system boots.
sudo systemctl stop redis-server sudo systemctl start redis-server sudo systemctl enable redis-server
To check if the server is running, run the following commands
sudo systemctl status redis-server
That should show the status of the Redis Server service:
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 ...
This is how you know Redis is running
How to configure Redis on Ubuntu Linux
Now that the server is installed and verified, follow the steps below to configure remote login and adjust the Ubuntu firewall.
By default, Redis does not allow access from remote locations (access from a different server / client). All access is restricted to the local host of the server on which it is installed. (example: 127.0.0.1).
In most environments, Redis Server and the applications it supports run on a single server. In this situation, remote access is not necessary, since all communication is done on one host computer.
However, if both the Redis server and the applications that use it are on separate hosts, remote access will be required.
To allow remote access, open the Redis configuration file by running the following commands:
sudo nano /etc/redis/redis.conf
Then change the highlighted line as shown below. basically replacing 127.0.0.1 with all zeros 0.0.0.0 ) or restrict access to a specific host IP that will need access to Redis.
# 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.
Save the file and close.
After making the changes to the file, restart the Redis service.
sudo systemctl restart redis-server
Verify that Redis is listening for all connections on 0.0.0.0 running the following commands:
ss -an | grep 6379
You should get a result as shown below:
Output: tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* tcp LISTEN 0 128 [::1]:6379 [::]:*
If you are also running the Ubuntu firewall, just 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
You should do that.
To test if Redis is hosted on an IP address 192.168.0.2 it is responding to remote hosts. type the following commands from the remote server.
redis-cli -h 192.168.0.2 ping
The Redis server should respond with a pong
If you get a correct answer, then everything is done.
In this tutorial we have seen how to install and Redis on Ubuntu Linux. If you find any bugs or have something to add, please use the comment form below.