How to Install Redis on Rocky Linux EL9 or EL8

Redis, an established open-source in-memory data structure store, serves multiple roles as a database, cache, and message broker. Recognized for its design focused on speed and flexibility, Redis is particularly suited for tasks demanding swift data interactions. If you are seeking to enhance the efficiency of your Rocky Linux server, integrating Redis is a strategic move. The platform’s handling of extensive data volumes positions it as the go-to for overseeing high-traffic applications. Redis can seamlessly operate as a database, cache, or message broker, elevating the velocity and reliability of your applications. This guide aims to help you install Redis on Rocky Linux 9 or the older stable enterprise Linux release of Rocky Linux 8, exploring its myriad functionalities and benefits.

Features of Redis:

  • In-Memory Data Storage: Redis conducts all data operations in memory, ensuring swift read and write actions.
  • Persistence: To prevent data loss, Redis persists data to the disk, even safeguarding it during crashes or shutdowns.
  • Pub/Sub Messaging System: Facilitates real-time inter-application communication through its publish/subscribe messaging framework.
  • Data Structures: Accommodates various data structures like strings, hashes, lists, sets, and sorted sets.
  • Lua Scripting: Redis houses a Lua scripting mechanism for server-side complex operation execution.
  • Clustering: Redis supports data distribution across multiple instances via clustering to aid in application scalability.
  • Multi-Threading: Redis’s multi-threaded design boosts its efficiency and scalability.

In the following sections, we’ll provide a detailed walkthrough to install Redis on Rocky Linux 9 or the older stable enterprise Linux release of Rocky Linux 8. We’ll outline two methods: using the appstream or the Remi Redis pm via terminal command line instructions.

Update Rocky Linux Before Redis Installation

Before proceeding with the Redis installation, it is essential to update your system’s packages to prevent any issues during installation. You can accomplish this by executing the following command.

sudo dnf upgrade --refresh

Install Redis on Rocky Linux 9 or 8 via DNF

Method 1: Install Redis with Rocky Linux Appstream

The Appstream repository, as the default source, holds the stable version of Redis that the Rocky Linux team has thoroughly tested. This makes the installation process straightforward. To begin, just run the following command.

sudo dnf install redis

It’s important to note that by default, the installation of Redis does not activate the service or set it to start on system boot. You can use the following command to activate the service and ensure it launches every time the system starts.

sudo systemctl enable redis --now

Method 2: Install Redis on Rocky Linux 9 or 8 via Remi RPM

The Remi repository is recommended for those who prefer to have the latest version of Redis. Remi is well-known for maintaining the latest stable releases of PHP and provides the latest stable releases of Redis. By using Remi, you can ensure that your Redis installation is up-to-date and fully functional.

Before installing Redis, installing the EPEL (Extra Packages for Enterprise Linux) repository is necessary. For those new to Rocky Linux and other distributions based on RHEL, the EPEL repository is valuable as it provides access to Enterprise Linux’s most commonly used software packages.

After importing the EPEL repository for your specific version of Rocky Linux, the next step is importing the Remi RPM. This will provide access to the latest stable releases of Redis and other software packages Remi maintains. Importing the Remi RPM will allow you to manage and install these packages through the DNF package manager.

Ensure you import the correct repositories for your Rocky Linux release. Failure to do this will lead to complications installing Redis or down the track with other inconsistencies.

Import EPEL and Remi RPM for Rocky Linux 9

Enabling the CRB (Code Ready Builder) with the following command is necessary.

sudo dnf config-manager --set-enabled crb

The next step in the process is to install EPEL 9 using the DNF terminal command.

sudo dnf install \
    https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
    https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm

With the EPEL repository now added, the next step is to enable the Remi repository using the following terminal command.

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Import EPEL and Remi RPM for Rocky Linux 8

For those using the Rocky Linux 8 distribution, installing the EPEL repository is similar to that of Rocky Linux 9. Simply use the following DNF terminal command to install EPEL on your Rocky Linux 8 system.

sudo dnf install \
    https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
    https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-8.noarch.rpm

Having successfully added the EPEL 8 repository, the next step is to enable the Remi repository. This is achieved by executing the following terminal command.

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Install Redis on Rocky Linux 9 or 8

Now, list the versions available with the following command.

sudo dnf module list redis
List of Redis modules from Remi RPM for Rocky Linux 9/8
Detailed list of Redis modules available via Remi RPM for Rocky Linux versions 9 and 8.

When installing Redis, it’s important to note that multiple versions of the software are available, including versions 5, 6, 6.2, and 7.

Select the Redis module you want to enable below:

sudo dnf module enable redis:remi-7.0 -y
sudo dnf module enable redis:remi-6.2 -y
sudo dnf module enable redis:remi-5.0 -y

When installing Redis, it’s important to note that the process for installation remains the same, regardless of the version you choose. This means you can easily switch to a different version if you encounter any issues with your installation. For example, if you have installed Redis 7 and find it too buggy, you can remove it and switch to a different version, such as 6.2.

sudo dnf install redis

To verify the successful installation of Redis, use the following terminal command. This will provide you with information about the version of Redis installed.

redis-server -v

Example output:

Redis server v=7.0.8 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=85aed731497b4b06

By default, Redis is not automatically started or set to run on system boot. You will need to run the following command to activate the service and ensure it is enabled on the system boot. This step is necessary to ensure that Redis is up and running whenever your system is restarted.

sudo systemctl enable redis --now

After activation, it’s essential to verify the status of Redis to ensure it is running correctly and without any errors. You can check the current status and run any necessary diagnostics to confirm its proper operation. This step is crucial for ensuring that Redis functions correctly and provides reliable service.

systemctl status redis
Successful Redis systemctl status on Rocky Linux 9/8
Screenshot of Redis operating successfully via systemctl on Rocky Linux 9 or 8.

It’s important to note that Redis actively listens on localhost on the default port 6379. To verify this, you can use the following terminal command: “ps -ef | grep redis.” This command will show you the current status of Redis and help you confirm that it is indeed listening on the correct port. This is important in ensuring that Redis is set up correctly and ready to use.

ps -ef | grep redis

Example output:

redis         3845           1  0 12:15 ?            00:00:00 /usr/bin/redis-server 127.0.0.1:6379
joshua      3966    3929  0 12:16 pts/0    00:00:00 grep --color=auto redis

Working Redis CLI on Rocky Linux 9 or 8

Redis CLI (Command Line Interface) is a powerful tool that provides an interface for interacting with Redis databases. After installing Redis, you can use Redis CLI to interact with the database and perform various tasks such as setting and getting values, deleting keys, and much more.

Here are a few examples of how to use Redis CLI:

To connect to Redis, open a terminal window and enter the following command:

redis-cli

Set a Value Once you are connected to Redis, you can set a value for a key using the following syntax:

SET key value

For example, to set the key “message” value to “Hello World,” you would enter.

SET message "Hello World"

Get a Value You can retrieve the value of a key by using the following syntax.

GET key

For example, to retrieve the value of the key “message,” you would enter.

GET message

Delete a Key To delete a key, use the following syntax.

DEL key

For example, to delete the key “message,” you would enter.

DEL message

List All Keys To list all keys in the Redis database, use the following syntax.

KEYS *

These are just a few of the many commands available in Redis CLI. The Redis CLI is a powerful tool that provides various capabilities for interacting with Redis databases. To learn more about the different commands available, you can refer to the Redis documentation.

How to Configure Redis with Rocky Linux 9 or 8

Configuring Redis after installation involves setting some key parameters to ensure the proper operation and security of the service. This section will teach you how to configure Redis max memory, network access, password, and cache eviction policies.

First, open the “/etc/redis/redis.conf” file using the nano editor.

sudo nano /etc/redis.conf

Configure Max Memory for Redis on Rocky Linux

The max memory setting determines how much memory Redis can store data. This setting is important for two reasons:

  • To prevent Redis from using too much memory and slowing down the system.
  • To ensure Redis does not store too much data in memory and start writing to disk, which slows down performance.

To configure max memory, in the Redis configuration file “/etc/redis.conf,” find and set the maxmemory parameter, as shown below:

# set maxmemory to 512 MB
maxmemory 512mb

Configure Network Access for Redis on Rocky Linux

By default, Redis listens only on the loopback address (localhost) and is not accessible from other systems. You can modify the bind parameter in the “/etc/redis.conf” configuration file to configure Redis to listen on a specific IP address.

# bind Redis to the specific IP address
bind 192.168.1.100

Instead, you can allow connections from any IP address to Redis by configuring the bind parameter, which is not recommended as it lacks security measures. It is best to implement specific firewalls before proceeding with this method.

bind 0.0.0.0/0

Configure Password for Redis on Rocky Linux

To secure Redis, you can configure a password that must be provided by clients connecting to the server. To configure a password, you must set the “requirepass” parameter in the “/etc/redis.conf” configuration file.

# set Redis password
requirepass password

Redis users will receive the following error message if an unsuccessful login attempt occurs.

(error) NOAUTH Authentication required.

Upon successful login, the following message will be displayed to the user.

OK

Configure Redis as a Cache with Redis on Rocky Linux

Redis can be used as a cache to store frequently accessed data in memory for faster retrieval. To configure Redis as a cache, you must choose an eviction policy that determines how Redis removes old data to make room for new data. There are two central policies:

  • LRU (Least Recently Used): removes the oldest data that has not been accessed recently.
  • LFU (Least Frequently Used): removes the data accessed the least number of times.

To configure an eviction policy, you must set the “maxmemory-policy” parameter in the “/etc/redis.conf” configuration file.

# set Redis eviction policy to LRU
maxmemory-policy LRU

Save the file and restart the Redis server using the following command.

sudo systemctl restart redis-server

You can perform These basic configurations on Redis to ensure its proper operation and security. For more advanced configurations and features, refer to the official Redis documentation.

Configure Firewalld for Redis on Rocky Linux 9 or 8

FirewallD is a firewall management tool for managing a Linux system’s incoming and outgoing network connections. If you have installed Redis on a Linux system, it is essential to configure the firewall to ensure it is adequately protected. This section will review some popular methods for configuring FirewallD for Redis.

Allow Redis Zone with Redis and Firewalld on Rocky Linux

The simplest way to allow Redis connections through the firewall is to assign the service to a firewall zone. This is done by adding the Redis service to the desired zone in the firewall-cmd configuration file.

firewall-cmd --permanent --zone=public --add-service=redis

Allow Dedicated IP Addresses with Redis and Firewalld on Rocky Linux

If you want to allow connections only from a specific IP address, you can add a rule to the firewall that allows incoming connections only from that address.

firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="6379" accept'

Allow IP Range with Redis and Firewalld on Rocky Linux

You can also allow incoming connections from a range of IP addresses. You must specify the IP range using the source address option in the firewall-cmd command to do this.

firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="6379" accept'

Allow Port with Redis and Firewalld on Rocky Linux

Another way to allow incoming connections to Redis is to allow the port that Redis uses for incoming connections. The default port for Redis is 6379.

firewall-cmd --permanent --zone=public --add-port=6379/tcp

Conclusion

In conclusion, installing Redis on Rocky Linux is straightforward but requires careful attention to detail to ensure a smooth and secure installation. You can have Redis up and running quickly using the recommended steps and procedures discussed in this article. It is important to remember that while Redis is a powerful tool, it should always be used carefully and by best security practices. With this in mind, you can use Redis to unleash its full potential, enhance the performance of your applications, and enjoy its many benefits.

To learn more about managing your Redis installation, visit the documentation page.

Leave a Comment