How to Install Redis on AlmaLinux 9

Advertisement

Redis is an open-source database frequently used as a cache or message broker. Unlike other databases, Redis stores data in memory, making it significantly faster. In addition, Redis supports a wide range of data structures, including strings, hashes, lists, sets, sorted sets, bitmaps, and streams. This makes Redis an incredibly versatile tool that can be used for various purposes. For example, Redis can be used as a message queue or for tracking user sessions. It can also be used for leaderboards or for storing real-time data. In addition to its speed and flexibility, Redis is highly scalable and can be easily deployed in both physical and cloud environments. As a result, it is no wonder that Redis has become one of the most popular databases among developers.

In the following tutorial, you will learn how to install Redis on AlmaLinux 9 workstation or server using the terminal command line with two methods: appstream or Remi Redis pm, along with basic setup instructions to get you started using the command line terminal.

Update AlmaLinux

Before installing Redis, start by ensuring your systems’ packages are up-to-date to avoid any conflicts during the installation using the following command.

sudo dnf upgrade --refresh

Install Redis – Appstream Method

Install Redis Appstream Version

The Appstream repository, by default, contains the stable version of Redis tested on the AlmaLinux team, making the installation straightforward.

Use the following command to install.

Advertisement

sudo dnf install redis -y

By default, the installation does not start or enable Redis on system boot; run the following command to activate the service and enable it on system boot.

sudo systemctl enable redis --now

Install Redis – Remi RPM Method

The following method is recommended for users that prefer having the latest version of Redis. Luckily for EPEL 9, Remi, which maintains PHP repositories, maintains the latest stable versions, as many would know working with PHP.

Advertisement

First, import the Remi Redis repository with the following command.

The first task is to install the (EPEL) repository, which stands for (Extra Packages for Enterprise Linux). For newer users of AlmaLinux and similar distributions based on RHEL, EPEL contains the most commonly used software packages for Enterprise Linux.

First, enable the CRB.

sudo dnf config-manager --set-enabled crb

Next, install EPEL using the following (dnf) terminal command.

Advertisement

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

Now that you have added the EPEL repository enable the (Remi repository) with the following command.

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

Now, list the versions available with the following command.

sudo dnf module list redis -y

Example output:

How to Install Redis on AlmaLinux 9

As above, Redis version 5, 6, and 7 is available. For now, Redis version 6 is the latest stable, with version 7 still in RC status during tutorial time creation. Select one of the versions below to enable it.

Advertisement

Enable Redis 7.0:

sudo dnf module enable redis:remi-7.0 -y

Enable Redis 6.2:

Advertisement

sudo dnf module enable redis:remi-6.2 -y

Enable Redis 5.0:

sudo dnf module enable redis:remi-5.0 -y

The process here is the same for whatever version you install. For example, if you install seven and it’s too buggy, remove and change the module to version 6.2.

Now install Redis.

sudo dnf install redis -y

Verify the installation.

redis-server -v

Example output:

Redis server v=7.0.4 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=222b5ae120437328

By default, the installation does not start or enable Redis on system boot; run the following command to activate the service and enable it on system boot.

Advertisement
Advertisement

sudo systemctl enable redis --now

Next, verify the status and make sure Redis is running and, more importantly, with no errors.

systemctl status redis

Example output:

How to Install Redis on AlmaLinux 9

Note that Reddis actively listens to localhost on the default port 6379. To confirm this type, the following:

ps -ef | grep redis

Example output:

How to Install Redis on AlmaLinux 9

While testing, everything is working and operational, connecting to your Redis service is good, and then performing a ping test.

To perform the test, enter the following command:

Advertisement

redis-cli

Once connected, your terminal will display (127.0.0.1:6379). Now ping the Redis service as follows:

ping

Example output:

Advertisement
How to Install Redis on AlmaLinux 9

Type the following to exit the Redis instance:

exit

Congratulations, you have installed Redis on your workstation or server and verified it is operational.

Next, you can configure Redis.

How to Configure Redis

Redis can be configured in a few ways. The most notable action of why people use Redis is for caching purposes. To do this, you need to open the “/etc/redis/redis.conf” file using nano editor.

Advertisement

sudo nano /etc/redis.conf

Configure Max Memory

Now, add the following to the end of the file. Note that you can change the memory value to whatever you like or, more importantly, optimal for your web application and server hardware.

maxmemory 500mb 
maxmemory-policy allkeys-lru

As you can see, the setting in the guide has 500MB dedicated to Redis as it is on a dedicated host with lots of RAM to spare. Once the 500MB is exhausted, Redis removes any key per the LRU algorithm.

Configure Network Access

Another option is to listen to all services or set an IP address/subnet if you like your Redis service.

First, find line 69 in the configuration file.

Advertisement

First, to listen to all network interfaces, Comment “#” the line bind to IP.

Example:

Advertisement

# bind 127.0.0.1 ::1

Alternative Method:

bind 0.0.0.0/0

Ensure your internal network is trustworthy and has appropriate security controls.

To bind to an IP address, make sure it is a static IP address.

Example:

bind 192.150.5.2

To bind a network subnet.

Example:

Advertisement
Advertisement

bind 192.150.5.0/24

Note that it is highly suggested to set a password when using subnet or to access all interfaces to listen to.

Configure Password

Another security feature to further harden Redis is to set a password on the Redis instance.

Navigate to line 507, uncomment the “# requiredpass” line, and set a password.

Example:

requiredpass APASSWORD

Make sure this password is robust, numbers, letters, special symbols, and capitals randomized as Redis servers can be bruted forced on a decent box.

Next, when invoking the Redis-CLI, use the following command with the password that was set for the user.

Advertisement

Example:

auth THEPASSWORDSET

“THEPASSWORDSET” is the password that was created.

Advertisement

Users who fail to log in will see the following error message.

(error) NOAUTH Authentication required.

When a user successfully logs in, they will see the following message.

OK

Once done, save your changes CTRL+O then exit CTRL+X. Now restart the Redis service by typing:

sudo systemctl restart redis-server

Configure Firewalld for Redis

By default, no rules are set up for Redis. This means you will need to create rules essential to stop attacks on Redis, failure to secure Redis will lead to issues down the track, so do not skip this unless you have other means to protect your Redis installation.

Advertisement

First, add a new dedicated zone for Redis firewalld policy.

sudo firewall-cmd --permanent --new-zone=redis

Next, specify the allowed IP addresses permitted to access the Redis.

sudo firewall-cmd --permanent --zone=redis --add-source=1.2.3.4

Replace 1.2.3.4 with the IP address that will be added to the allow list.

Once you have finished adding the IP addresses, open the port of the Redis. By default, this is TCP port 6379.

Advertisement
sudo firewall-cmd --permanent --zone=redis --add-port=6379/tcp

Note that you can change the default port in your configuration file if you change the firewall port open rule above to the new value.

After running those commands, reload the firewall to implement the new rules.

Advertisement

sudo firewall-cmd --reload

Example output if successful:

success

Now, as you tested at the start of the guide by pinging your Redis service to ensure it was operational, you can try the firewall rules and changes in IP by using the “redis-cli” command.

redis-cli -h  <ip address> ping

If setup correctly, the output should be:

pong

How to Remove (Uninstall) Redis

When you need to remove Redis, use the following command.

sudo dnf autoremove redis

Comments and Conclusion

Redis is a powerful tool to consider for your next project. Its ability to handle large-scale data can be essential to scaling your architecture. Combined with its wide variety of features, this makes it an attractive choice for many applications. If you’re looking for a reliable, fast storage solution with plenty of features, Redis is worth considering!

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

Advertisement

Share on: