Redis stands for Remote Dictionary Server. Redis is a type of data structure that is stored in RAM and where information is temporarily stored. Redis stores data with a key-value system. Thanks to this feature, since there is no complex relationship between the data, accessing and retrieving this information becomes much easier. In this article, we try to teach you how to install and Secure Redis on Debian 10. If you want to buy a Linux VPS server, see the packages available in Eldernode.
Table of Contents
Tutorial install and Secure Redis on Debian 10
Redis is quite different from databases like MySQL and Oracle. Because it does not contain columns, rows, tables and functions. Redis also does not use the Select, Insert, Update and Delete commands. Instead, Redis uses data structures such as String and Lists, Sets, and Hashes to sort information. Also, it is not bad to know that interaction with Redis is done through the command. In the continuation of this article, join us to learn you how to Install and Secure Redis on Debian 10 or Debian 9.
Install and Secure Redis on Debian 10 | Debian 9
To start Install and Secure Redis on Debian 10, the first step is to update the system. So you have to run the following commands and then restart the system:
apt-get update -y
apt-get upgrade -y
Given that Redis is in the Debian 10 repository by default, it is not difficult to install. Just run the following command:
apt-get install redis-server -y
In the next step, you need to start the Redis service and activate it. By doing this after restarting the system, Redis will start working:
systemctl start redis-server
systemctl enable redis-server
To check the status of the Redis server, run the following command:
systemctl status redis-server
Since Redis listens on localhost on port 6379, you can check the status by running the following command:
ps -ef | grep redis
The important and practical point is that you can check the connection status of the Redis. So you can simply do this by running the following command:
redis-cli
The output of the above command will be similar to the following:
127.0.0.1:6379>
Another way to check the Redis connection is to use the ping command:
127.0.0.1:6379> ping
If everything is correct, you will see the following command in the output:
PONG
How to configure Redis as a Cache
You can configure Redis as a cache by editing the path in the following command. We used a nano editor to do this.
nano /etc/redis/redis.conf
After opening the redis.conf file, you need to put the following commands at the bottom of it. Then save the file and restart the system for the changes to take effect.
maxmemory 64mb
maxmemory-policy allkeys-lru
systemctl restart redis-server
Tutorial configure Redis Authentication
Since you can run any command in the Redis shell, you need to configure Redis Authentication for clients. After doing this, you will need a password before executing the commands. To authenticate the password using the nano editor Open the redis.conf file:
nano /etc/redis/redis.conf
In the opened file, look for the following command:
# requirepass foobared
You can cancel the password and replace it with your password, as in the following example. After making changes to the file, save it and restart the system to apply the changes:
requirepass Bdre26%!c
systemctl restart redis-server
Enter the Redis shell by executing the following command:
redis-cli
From this step on, to open the Redis file, you must execute the following command by entering your password:
127.0.0.1:6379> AUTH Bdre26%!c
Then you can easily enter the following command as before:
127.0.0.1:6379> INFO server
How to Rename Specific Commands
Depending on the security issues, you can change some of the commands. The first step is to enter the Redis shell by executing the following command:
redis-cli
127.0.0.1:6379> AUTH Bdre26%!c
In the next step, you need to recover the Redis password by running the following command:
127.0.0.1:6379> config get requirepass
Open the Redis configuration file using the nano editor or your favorite editor so you can change it:
nano /etc/redis/redis.conf
After opening the configuration file, search for the following command:
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
In this step, you must replace the desired string. Save the file after making the changes. Then restart the system:
rename-command CONFIG H2sW_Config
systemctl restart redis-server
In the next step, you can connect to Redis by executing the following commands:
redis-cli
127.0.0.1:6379> AUTH Bdre26%!c
In the next step, you must use the new command instead of the previous one. The following command is the same as the rename command.
127.0.0.1:6379> H2sW_Config get requirepass
Finally you can exit Redis by running the following command:
127.0.0.1:6379> exit
Conclusion
Redis is easy to use, and this feature has led many developers to use it. But the benefits of Redis do not end there. Redis’ strong point is the speed of this technology, and since it is written in C, we see a significant increase in speed in Redis. With Redis, less resources are spent on the server and users need to provide cost-effective infrastructure. Redis supports most of the world’s leading programming languages. Languages such as JavaScript, Java, Go, C, C++, C#, Python, Objective C, and PHP are well compatible with Redis, and Redis can be said to meet the needs of a wide range of developers. In this article, we tried to learn you how to Install and Secure Redis on Debian 10.