How to Install Redis on AlmaLinux 9

Choose a different version or distribution

Introduction

Before we begin talking about how to install Redis on AlmaLinux 9, let's briefly understand – What is Redis?

Redis is a powerful open-source data structure server. It acts as a key-value store where data is stored and retrieved incredibly fast. It's known for its high performance and in-memory storage, making it ideal for caching, real-time analytics, session management, and more.

Redis is versatile, supporting various data structures like strings, lists, sets, and hashes. With persistent storage options, it ensures data durability. Overall, Redis is a handy tool for developers seeking efficient data handling in their applications.

In this tutorial, you will install Redis on AlmaLinux 9. We will also address a few FAQs on how to install Redis on AlmaLinux 9.

Advantages of Redis

  1. High Performance: Redis offers blazing fast data processing and retrieval.
  2. In-Memory Storage: Data stored in Redis resides in memory, ensuring quick access.
  3. Versatile Data Structures: Supports various data structures, enhancing flexibility.
  4. Scalability: Easily scales to handle increasing data loads.
  5. Durability: Provides options for persistent storage to ensure data safety.

Prerequisites

  • An AlmaLinux VPS
  • Either a regular user with sudo rights or root SSH access

Step 1: Log in to Your Server via SSH

You must first log in as the root user to your AlmaLinux 9 VPS via SSH in order to begin this:

ssh root@IP_Address -p Port_number

The IP address and SSH port number of your server must be substituted for IP_Address and Port_number, respectively. Moreover, change root to the username of the system user who has sudo access.

Use the following command to see if your server is running the correct version of AlmaLinux:

cat /etc/almalinux-release

This is the output that you will get:

Output

AlmaLinux release 9.1 (Lime Lynx)

In order to run the shell commands in this article, we use the command root. Be sure to add sudo in front of the commands if you want to run them using your normal user with sudo rights.

Step 2: Update the System

Make sure all the AlmaLinux OS packages are current before you begin. To accomplish this, run the following commands:

dnf update
dnf upgrade

Step 3. Install Redis

Redis can be installed in a number of ways, such as through the operating system repository, docker, source compilation, etc. Redis installation is simple because we will be using the default AlmaLinux 9 repository in this tutorial.

dnf install redis

Redis will not launch on its own after installation. Let's run the following command to launch and enable Redis.

systemctl enable --now redis

This command allows you to see the current status of the Redis service.

systemctl status redis

The following output will be displayed by the command:

Output

redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Wed 2023-03-15 23:52:57 CDT; 5h 48min ago
Main PID: 2153 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 12328)
Memory: 6.7M
CPU: 31.654s
CGroup: /system.slice/redis.service
└─2153 "/usr/bin/redis-server *:16379"

Mar 15 23:52:57 redis.rosehosting.com systemd[1]: Starting Redis persistent key-value database...
Mar 15 23:52:57 redis.rosehosting.com systemd[1]: Started Redis persistent key-value database.

Step 4. Configure Redis

After Redis has started operating on your server, we will modify its configuration. We must make changes to the configuration file in order to personalize your Redis setup. Redis, for instance, is by default running on port 6379; to change the port to, say, 16379, we can locate the line and edit /etc/redis/redis.conf.

port 6379

Edit or replace the line,

port 16379

Next, we must restart the Redis service in order to take effect of the modifications.

systemctl restart redis

Redis is now operational and available on port 16379. To check it, we can log into Redis CLI and run a command.

redis-cli -p 16379

Redis is currently listening on port 16379, so we must include the port number in the command in order for it to connect. The command above will take you to the Redis CLI.

To see its current status, we can run the following command in the Redis CLI:

127.0.0.1:16379> info server

The output from the two commands above looks like this:

Output

[root@rh ~]# redis-cli -p 16379
127.0.0.1:16379> info server
# Server
redis_version:6.2.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ec192bdd77ecd321
redis_mode:standalone
os:Linux 5.14.0-162.18.1.el9_1.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:11.3.1
process_id:2096
process_supervised:systemd
run_id:f0594ef263f551b29236e6a5a56e9dfb713789a4
tcp_port:16379
server_time_usec:1678939600623971
uptime_in_seconds:157
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:1218000
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
127.0.0.1:16379>

By changing this line, we can also specify the listening interface in the same /etc/redis/redis.conf configuration file.

bind 127.0.0.1 -::1

with

bind *

To apply the configuration changes, let's restart Redis.

systemctl restart redis

Step 5. Secure Redis

We demonstrated how to set Redis up to listen on ports other than localhost in the previous step. Please be aware that it is risky to bind Redis to the public IP address of your server in the absence of an authentication interface. Therefore, you can add authentication by adding this line to your redis.conf file if you absolutely need to bind your Redis server to your server's IP address.

requirepass YOURSTRONGPASSWORD

Every time you make changes to the configuration file, remember to restart Redis and replace YOURSTRONGPASSWORD with your own strong password.

systemctl restart redis

With this command, you can now establish a connection from another server to your Redis server:

redis-cli -h YOUR_REDIS_SERVER_IP_ADDRESS -p 16379 -a 'YOURSTRONGPASSWORD'

You should also set up the firewall to only allow connections from particular IP addresses while blocking all others.

iptables -A INPUT -s [YOUR_EXTERNAL_IP_ADDRESS] -p tcp --dport [YOUR_REDIS_PORT] -j ACCEPT

FAQs to Install Redis on AlmaLinux 9

What are the prerequisites for installing Redis on AlmaLinux 9?

You'll need a running AlmaLinux 9 system with root privileges and an internet connection.

What is the recommended way to install Redis for most users?

Using the AlmaLinux repositories is generally the easiest and most convenient option.

How do I secure Redis after installation?

  • Set a strong password for Redis access using the requirepass directive in the configuration file.
  • Consider using firewalls or access control lists to restrict access to the Redis server.

What is the default port for Redis on AlmaLinux 9?

The default port used by Redis on AlmaLinux 9 is 6379.

How can I configure Redis for remote access on AlmaLinux 9?

Configure Redis for remote access by modifying the bind parameter in the redis.conf file to allow remote connections.

Are there Redis GUI tools available for managing Redis on AlmaLinux 9?

Yes, you can install GUI tools such as RedisInsight or RDM for easier Redis management.

How do I upgrade Redis to a newer version?

Update the package using the package manager (e.g., dnf upgrade redis) or follow the upgrade instructions for your chosen installation method.

Conclusion

We hope this tutorial helped you understand how to install Redis on AlmaLinux 9.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.