Redis is a free, open-source, in-memory data structure store widely used as a database, cache, and message broker.
Here at LinuxAPT, we shall look into how to install Redis on a Rocky Linux 8 machine.
To see how you can install Redis on Ubuntu 20.04, visit: https://linuxapt.com/blog/194-install-and-configure-redis-in-ubuntu-20-04
1. Install Redis
To install Redis, run this command:
$ sudo dnf install redis
2. Edit Redis Configuration file
Next, we will make some changes to the Redis configuration file.
Open the file using the vim editor:
$ sudo vim /etc/redis.conf
Locate supervised directive in the file. It will be written as:
supervised no
Change it to:
supervised systemd
3. Start Redis
Now you can start Redis with the below command:
$ sudo systemctl start redis
4. Enable Redis
Similarly, we will enable Redis with this command:
$ sudo systemctl enable redis
5. Check Redis status
Now we will confirm if Redis service is running fine or not. Do that with this command:
$ sudo systemctl status redis
6. Test Redis Installation
Here, we will test Redis by running the command mentioned below. If it returns with PONG, this means redis is working fine:
$ sudo redis-cli ping
To secure the database, we will assign it a password to prevent unauthorized access.
1. Edit Redis configuration file
To begin, open the Redis configuration file again using this command:
$ sudo vim /etc/redis.conf
Find the following directive in the file to uncomment it and assign your password:
requirepass strong_password
2. Restart Redis
To update changes, restart Redis:
$ sudo systemctl restart redis
3. Enter Redis-cli
Now, we will check if the password authentication is working fine or not. To do that, access Redis client with this command:
$ redis-cli
4. Set Key to a value
Now set a key to a value like this:
set keystudent John
This will give an error, telling you that authentication is required to set the key.
To get access, push your password with auth command like this:
$ auth your_password
Once the password is accepted, you will be able to set a key to the value.
5. Retrieve the value
To retrieve the value you just assigned to the key, use the get command like this:
$ get keystudent
6. Exit Redis
To exit the database, just type quit and hit enter:
Quit
1. Edit Redis configuration file
First of all, open the redis.conf file with this command:
$ sudo nano /etc/redis.conf
Search for the bind directive, which is set to listen to localhost. Comment it:
Next, give the remote server's ip address like this:
Bind private_ip
To grant access to Redis over the public internet, set the bind directive to 0.0.0.0:
bind 0.0.0.0
2. Disable protected mode
Now change protected mode yes to no.
Save the changes and exit.
3. Restart Redis
Now, restart the database with this command to update changes in the Redis configuration file:
$ sudo systemctl restart redis
Here, we will configure the default firewall in Rocky Linux, namely firewalld, to allow Redis to listen on port 6379 which is its default port.
1. Allow Redis port 6379
Run the following command so that Redis can listen on its default port:
$ sudo firewall-cmd --add-port=6379/tcp --permanent
2. Reload firewall
To update changes, reload the firewall with this command:
$ sudo firewall-cmd --reload
3. Test new settings
Now that we have configured the firewall for Redis, let’s test if a remote machine can access Redis or not. Do that by running the following command from a remote machine:
$ redis-cli -h server_IP
server_IP is the IP address of the machine on which Redis is deployed. In my case, it is 10.128.1.2.
$ redis-cli -h 10.128.1.2
This article covers how to install and configure Redis on Rocky Linux 8. In fact, Redis is a popular and open-source in-memory key-value data store. It supports various data structures such as Hash, Lists, Sets, Strings, and much more.