Introduction
Redis stands for Remote Dictionary Server. Redis is a data structure that stores data in key-value pairs. All Redis data is stored in memory, enabling high data access rates. Unlike regular databases in Redis, it takes much less time to read and write to memory and supports millions of operations per second.
This article will explain how to install and secure Redis on openSUSE 15.2.
Prerequisites
- A root or non-root user with
sudo
privileges.
Installing Redis
-
Update the system.
$ sudo zypper update
- To install a Redis, open the terminal and run the following command.
$ sudo zypper -n in redis
-
Create a Redis Systemd Service File
$ sudo vi /etc/systemd/system/redis.service
Add this content to the file.[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/sbin/redis-server /etc/redis/redis.conf
LimitNOFILE=10240
ExecStop=/usr/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target -
Create the specified config file /etc/redis/redis.conf by copying the sample file.
$ sudo cp /etc/redis/default.conf.example /etc/redis/redis.conf
-
Update the file permission.
$ sudo chown redis.redis /etc/redis/redis.conf
-
Start and enable the Redis service.
$ sudo systemctl start redis
$ sudo systemctl enable redis -
Verify the Redis setup with the below command.
If Redis running on your system above command print$ redis-cli ping
PONG
as the response.
Configure Redis
-
Open the original Redis configuration file.
Search the$ sudo vi /etc/redis/redis.conf
bind
and remove localhost IP and bind your IP address.
-
After making all the necessary changes, save the file, exit, and restart the Redis services.
# systemctl restart redis
Securing Redis with Password Authentication
The password authentication for Redis will give you access control to your Redis server. This little layer of security will enhance your Redis server security.
-
Open a Redis configuration file.
# sudo vi /etc/redis/redis.conf
Search the SECURITY section and then uncomment requirepass and provide the password as shown below.requirepass foobared
Change the ‘foobared’ with your strong password.
-
Restart the Redis server.
# systemctl restart redis
Test Redis server connectivity
-
Connect to the Redis client using
redis-cli -h <your-server-ip> -p 6379
.
# redis-cli -h 207.199.149.75 -p 6379
-
You need to authenticate before invoking any command on the Redis CLI. Here we pass the password provided in the earlier step.
AUTH foobared
- After connecting to the Redis server let's try to set and get a new key in Redis.
set key1 "test_key"
get key