
Redis is an open-source and in-memory key-value store. Its mainly used as database, message broker or as a cache and supports different data structures like strings, lists, sets, maps, spatial indexes, and bitmaps. Redis supports wide languages with flexibility and high performance. In this tutorial, we will cover how to install and configure Redis on a Debian 10, Buster.
Prerequisites
- Before you start to install, you must login as root or non-root user account with sudo privileges.
- IPv6 should be enabled on your server otherwise Redis service will fail to start.
Install Redis on Debian
At first, to get the latest version of Redis, we will use apt to install it from the official Debian repositories. Redis version 5.0.x is included in the default Debian 10 repositories. Run the following commands to install:
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 2019-12-30 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 Debian 10 server.
Enable Redis Remote Access
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:
PONG
You can exit
the redis-cli
shell by typing:
exit
Conclusion
You have successfully learned how to install Redis on Debian 10. 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