Redis is an in-memory key-value store and used as a database server, cache, and message broker. Redis supports wide languages with flexibility and high performance. This tutorial will demonstrates how to install and configure Redis on Ubuntu 20.04 system.
- Make sure you logged in as root or non-root user account with sudo privileges.
IPv6should be enabled on your server otherwise Redis service will
Install Redis on Ubuntu
At first, to get the latest version of Redis, we will update apt package cache:
sudo apt update && sudo apt upgrade
sudo apt install redis-server
This will install Redis and its dependencies. On the completion of installation, Redis service will be start automatically. You can verify it by typing:
sudo systemctl status redis-server
It should show 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 Thu 2020-05-15 18:20:12 PDT; 37s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 2205 (redis-server) Tasks: 4 (limit: 2349) Memory: 6.9M CGroup: /system.slice/redis-server.service └─2205 /usr/bin/redis-server 127.0.0.1:6379
That’s it! Redis is ready to use on your Ubuntu server.
By default, Redis is configured to listen on
localhost only. You can connect to the Redis server only from the same machine where its service is running.
If you want to configure Redis to accept remote connections, open the Redis configuration file with your text editor using below command:
sudo nano /etc/redis/redis.conf
Now comment the line
bind 127.0.0.1 ::1 by adding
# at the beginning of line.
Save the file and close.
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # bind 127.0.0.1 ::1
You should restart the Redis service for changes to take effect:
sudo systemctl restart redis-server
Run the below command to verify:
ss -an | grep 6379
It should show as below output:
tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* tcp LISTEN 0 128 [::]:6379 [::]:*
If your are using firewall, you’ll also need to add a firewall rule to enable traffic from your remote machines on TCP port
6379. If you are using UFW, run below command:
sudo ufw allow proto tcp from 192.168.0.0/16 to any port 6379
Ensure that your firewall is configured to accept connections only from trusted IP ranges.
Now to test that Redis is functioning correctly, connect to the server using
redis-cli utility by pinging the Redis server from your remote machine:
redis-cli -h <REDIS_IP_ADDRESS> ping
You should see exact below output:
redis-cli shell by typing:
You have successfully learned how to install Redis on Ubuntu 20.04 server. To find more information about how to manage your Redis installation, visit the Redis documentation page.
If you have any queries please don’t forget to comment out.
Leave a Reply