How to install Redis on Linux (AlmaLinux)
Redis is a powerful, high-performance, in-memory key-value data storage solution. Primarily leveraged for caching, message brokering, and session storage, Redis ensures swift and efficient data access and manipulation. Its support for diverse data structures, replication, the ability to handle real-time data processing tasks, and seamless scalability make Redis an indispensable solution for modern high-performance applications.
As an open source, cross-platform data storage solution, Redis demonstrates its adaptability across various operating systems. You can opt to deploy Redis on Windows or macOS or install Redis on Linux systems such as Ubuntu or AlmaLinux. A community-driven, enterprise-grade Linux distribution, AlmaLinux offers a robust and reliable platform for running Redis for applications that demand high-performance data storage. Let's review how to install Redis on Linux (AlmaLinux) via two popular methods, secure Redis, and configure the data storage solution for the needs of your application.
System Requirements and Prerequisites
- Operating system. AlmaLinux 8 or AlmaLinux 9.
- Privilege level. Root or system access to your server.
- Memory. At least 2 GB of total system RAM is recommended.
- Disk space. Redis offers multiple options for data persistence, which ensures that all data is saved to the hard disk. The amount of free disk space required depends on the volume of data Redis will store.
- Firewall configuration. Implementing firewall rules to limit access to Redis is advisable when making Redis accessible externally, as opposed to being bound to localhost.
Method #1. Install Redis on Linux (AlmaLinux) using a package manager
AlmaLinux and other major Linux distributions provide packages for Redis in standard software repositories. However, you can still opt to install Redis on Linux from the source. The installation process is simple and straightforward. It includes installing and configuring Redis as a service to run in the background as a daemon under systemd.
Step #1.1. Access your Liquid Web server
Access your Liquid Web server using SSH or another remote access method.
Step #1.2. Install available updates for your AlmaLinux system
Some package installations may fail if your system’s sources are outdated. Therefore, it is a good practice to refresh repository information and check for updates to system components before installing new software packages. Use the command below to update your package sources and install all available software updates. The dnf update command checks whether any software packages have been added or removed as well as if there have been updates your local index. And then, the dnf update command installs all updates for you:
[root@host ~]# dnf update
Dependencies resolved.
Nothing to do.
Complete!
Step #1.3. Enable the EPEL repository
You can install Redis on Linux (AlmaLinux) through the EPEL repository, an acronym for Extra Packages for Enterprise Linux. The EPEL repository features a set of additional software packages for RedHat-based Linux distributions. All packages available through the EPEL repository are free and open source.
The EPEL repository is not installed by default on AlmaLinux. You can enable it by installing the epel-release package, which will install and configure the repository and add the necessary GPG keys for package signing:
[root@host ~]# dnf install epel-release
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
Installing:
epel-release noarch 8-19.el8 extras 24 k
Transaction Summary
========================================================================================================================
Installed:
epel-release-8-19.el8.noarch
Step #1.4. Install Redis on Linux (AlmaLinux) through the EPEL repository
Once the EPEL repository has been successfully installed on your AlmaLinux server, you can install Redis using the command below. The DNF package manager will locate and install the Redis software package along with all its dependencies:
[root@host ~]# dnf install redis
Alma Linux 8 - PowerTools 3.1 kB/s | 4.1 kB 00:01
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
Installing:
redis x86_64 5.0.3-5.module_el8.4.0+2583+b9845322 appstream 926 k
Enabling module streams:
redis 5
Transaction Summary
========================================================================================================================
Installed:
redis-5.0.3-5.module_el8.4.0+2583+b9845322.x86_64
[root@host ~]# dnf info redis
Installed Packages
Name : redis
Version : 5.0.3
Release : 5.module_el8.4.0+2583+b9845322
Architecture : x86_64
Size : 3.2 M
Source : redis-5.0.3-5.module_el8.4.0+2583+b9845322.src.rpm
Repository : @System
From repo : appstream
Summary : A persistent key-value database
URL : http://redis.io
License : BSD and MIT
Description : Redis is an advanced key-value store.
Step #1.5. Start and enable Redis to run in the background
Once Redis has been installed through the package manager, use systemctl commands to start it and enable it to run persistently across system boots. While some software packages will be automatically configured to start on boot after the installation, you will see that the Redis systemd service has the vendor preset set to disabled, which indicates that you need to manually enable it:
[root@host ~]# systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: inactive (dead)
[root@host ~]# systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
[root@host ~]# systemctl start redis
[root@host ~]# systemctl status redis
● 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)
Method #2. Install Redis on Linux (AlmaLinux) from the source
While using a package manager is the recommended way to install Redis on Linux (AlmaLinux), an alternative option is getting Redis installed and compiled from the source. This method involves downloading the Redis source files and manually compiling the software solution. An important consideration when opting for this method is the need to manually create and configure a systemd service for Redis, ensuring its persistent operation. Follow the steps below to learn how to install Redis on Linux (AlmaLinux) from the source.
Step #2.1. Access your Liquid Web server
Log into your Liquid Web server using SSH or another remote access method.
Step #2.2. Install the required tools for compiling Redis
Ensure you have the make, gcc, and openssl-devel software packages installed on your AlmaLinux system to compile and build software from its source code. The make Linux utility orchestrates the build process, executing compilation commands and managing dependencies. Having GNU Compiler Collection, or gcc, installed is crucial for compiling the C source code that Redis is written in, transforming it into executable binaries. Lastly, openssl-devel provides the necessary file for developing applications that utilize OpenSSL:
# dnf install make
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
make x86_64 1:4.2.1-11.el8 baseos 497 k
Transaction Summary
============================================================================================================================================================================================================
Install 1 Package
# dnf install gcc
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
gcc x86_64 8.5.0-20.el8.alma appstream 23 M
Installing dependencies:
binutils x86_64 2.30-123.el8 baseos 5.8 M
cpp x86_64 8.5.0-20.el8.alma appstream 10 M
glibc-devel x86_64 2.28-236.el8.7 baseos 84 k
glibc-headers x86_64 2.28-236.el8.7 baseos 489 k
isl x86_64 0.16.1-6.el8 appstream 841 k
kernel-headers x86_64 4.18.0-513.11.1.el8_9 baseos 11 M
libmpc x86_64 1.1.0-9.1.el8 appstream 60 k
libxcrypt-devel x86_64 4.1.1-6.el8 baseos 24 k
Transaction Summary
============================================================================================================================================================================================================
Install 9 Packages
# dnf install openssl-devel
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
openssl-devel x86_64 1:1.1.1k-12.el8_9 baseos 2.3 M
Installing dependencies:
keyutils-libs-devel x86_64 1.5.10-9.el8 baseos 47 k
krb5-devel x86_64 1.18.2-26.el8_9 baseos 561 k
libcom_err-devel x86_64 1.45.6-5.el8 baseos 38 k
libkadm5 x86_64 1.18.2-26.el8_9 baseos 187 k
libselinux-devel x86_64 2.9-8.el8 baseos 199 k
libsepol-devel x86_64 2.9-3.el8 baseos 86 k
libverto-devel x86_64 0.3.2-2.el8 baseos 17 k
pcre2-devel x86_64 10.32-3.el8_6 baseos 604 k
pcre2-utf16 x86_64 10.32-3.el8_6 baseos 228 k
pcre2-utf32 x86_64 10.32-3.el8_6 baseos 219 k
zlib-devel x86_64 1.2.11-25.el8 baseos 57 k
Transaction Summary
============================================================================================================================================================================================================
Install 12 Packages
Step #2.3. Obtain Redis source files
Download the source files for the newest stable release of Redis from the Redis Download page using the wget or curl utilities. You can verify the integrity of the compressed tarball you downloaded using the corresponding SHA1 hash published in the redis-hashes git repository:
# wget https://download.redis.io/redis-stable.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.121.1
Connecting to download.redis.io (download.redis.io)|45.60.121.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3479614 (3.3M) [application/octet-stream]
Saving to: 'redis-stable.tar.gz'
redis-stable.tar.gz 100%[================================================================================================================>] 3.32M 19.1MB/s in 0.2s
Step #2.4. Compile Redis with TLS support
After downloading the Redis source tarball, extract the files using the tar command:
# tar -xzvf redis-stable.tar.gz
redis-stable/
redis-stable/src/
Navigate to the resulting redis-stable directory and run the make command with the BUILD_TLS configuration option. This option will compile Redis with TLS support and install the Redis CLI Linux utility. You will see redis-server and redis-cli binaries appear in the src directory:
# make BUILD_TLS=yes
cd src && make all
make[1]: Entering directory '/home/redis-stable/src'
CC Makefile.dep
...
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory '/opt/redis-stable/src'
Run the make install command to install the Redis binaries in /usr/local/bin:
# make install
cd src && make install
make[1]: Entering directory '/home/redis-stable/src'
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli
make[1]: Leaving directory '/opt/redis-stable/src'
Step #2.5. Start and enable Redis to run in the background
While you can use the redis-server command to start Redis in a screen session, it's important to note that without configuring Redis as a systemd service, it won't run persistently or automatically start on system boot. Therefore, the installation method through a package manager is recommended. As configuring systemd services is outside the scope of this article, refer to the official Redis documentation to manually configure Redis to run as a daemon under systemd.
How to update Redis
Updating Redis involves checking whether a new version of the Redis software package is available in the EPEL repository or on the official Redis Download page. If you have installed Redis on AlmaLinux using a package manager, it will automatically retrieve and install the updated version of Redis once system updates are performed. Alternatively, you can run dnf update redis to install the latest release:
# dnf update redis
How to uninstall Redis from your AlmaLinux server
You can uninstall Redis from your AlmaLinux server by running the following command if Redis has been installed using a package manager. It will automatically remove the service and its configuration, as well as erase all data that Redis previously stored. If you installed Redis from the source, you must remove all of its components from your system manually.
# dnf remove redis
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Removing:
redis x86_64 5.0.3-5.module_el8.4.0+2583+b9845322 @appstream 3.2 M
Transaction Summary
============================================================================================================================================================================================================
Remove 1 Package
Removed:
redis-5.0.3-5.module_el8.4.0+2583+b9845322.x86_64
Configure and secure Redis
By default, Redis binds to localhost. However, it doesn’t require any authentication to interact with the stored data and make configuration changes. This setup introduces significant security concerns and significantly increases the attack surface. Furthermore, while Redis has persistence enabled, which means it will save all data to the hard disk, it will only do so from time to time. Therefore, it’s a good practice to change the default security and data persistence policies right after you install Redis on Linux.
To modify the configuration of your Redis system, edit the main Redis configuration file located in the /etc directory (typically, /etc/redis.conf). Open /etc/redis.conf for editing with a preferred text editor and locate the desired configuration parameters. Ensure you reload the Redis service after making configuration changes using the systemctl reload rediscommand.
Step #1. Bind Redis to a specific interface
The first step towards securing Redis is binding the service to a specific network interface. It's advisable to bind Redis to a private IP address if you need to access Redis from another host or end system. If your application runs on the same server, you can leave Redis bound to localhost.
Locate the bind configuration parameter and modify its value to the chosen IP address. Please note that it will only instruct Redis to listen on the specified interface. It is highly recommended to further enhance the security of the Redis service by implementing robust firewall rules restricting access to Redis on the port it listens on, namely port 6379, if you choose to make Redis accessible externally:
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
bind 127.0.0.1
Step #2. Configure a password for Redis
Utilize the requirepass configuration directive found in the Security section of the configuration file to define a password for authenticating clients connecting to Redis. Since the requirepass configuration parameter is initially disabled, uncomment the directive before saving the changes. Replace the default foobared value with a strong password:
requirepass your-strong-password
Step #3. Configure Redis persistence policies
The default Redis persistence policies in /etc/redis.conf specified by the save directive are set to create snapshots of the dataset at various intervals if certain conditions are met. Here are the default values:
save 900 1 #create a snapshot every 900 seconds (15 minutes) if at least 1 key changed
save 300 10 #create a snapshot every 300 seconds (5 minutes) if at least 10 keys changed
save 60 10000 #create a snapshot every 60 seconds (1 minute) is at least 10000 keys changed
However, the default persistence policies may not provide sufficient protection against data loss for mission-critical applications. You may want to increase the frequency of snapshots or explore the Append-Only File (AOF) persistence option Redis offers. AOF persistence policy enables logging every write operation Redis receives. This feature allows Redis to redo the operations in case of a system failure and reconstruct the original dataset.
You can enable Append-Only File by setting the value of the appendonly parameter to yes. Redis recommends leveraging both RDB (Redis Database) and AOF (Append-Only File) policies to ensure a higher degree of data safety:
appendonly yes
# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"
Using the Redis command line interface (CLI) to communicate with Redis
The Redis command line interface (CLI) enables you to communicate with Redis and the data it stores from the terminal. Both installation methods covered in this tutorial will install the Redis CLI Linux utility for your AlmaLinux server. By default, Redis CLI expects Redis to be bound to localhost on port 6379. If you have configured a different IP address for Redis to listen on and set up a password, use the -h option to specify the IP address or host to connect to. Be aware that if you have previously set up a password for Redis, you will be asked to authenticate.
Redis CLI provides several ways to interact with the Redis server. For example, the redis-cli INFO and redis-stat commands will provide a comprehensive overview of the Redis server's status, configuration, and performance:
# redis-cli INFO
# Server
redis_version:5.0.3
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:14b81d825631ff0c
redis_mode:standalone
Integrating Redis into your application
Integrating Redis into a web application involves taking advantage of Redis clients to interact with the Redis server to leverage its powerful in-memory data storage capabilities. Redis clients play a central role in the process, serving as a bridge between the application code and the Redis database, allowing for seamless data retrieval and manipulation.
For example, if you run an application written in Python, you can easily install the Redis client library using the Pip package manager by running pip install redis. Once a Redis client is integrated into the application code, developers can employ the functionality it offers to interact with the Redis server. This functionality includes commands to retrieve data and manage key-value pairs, among other things.
Deploy a Redis server on AlmaLinux with Liquid Web
Redis is a highly versatile and performance-driven in-memory data storage solution renowned for ensuring swift access to data and efficient data management. Widely adopted across industries, Redis excels in environments requiring mission-critical functionality, delivering unrivaled performance and reliability. The cross-platform nature of Redis adds to its broad appeal, providing a solid foundation for applications running on different operating systems.
Running Redis on AlmaLinux offers a robust environment for high-performance data storage due to the distribution’s reliability, security, and long-term support. Unlock the full potential of in-memory data storage solutions and elevate your hosting experience with Liquid Web Cloud and Dedicated hosting solutions. To power mission-critical applications, explore the advantages of deploying Redis in the cloud with Liquid Web’s Private Cloud solutions.
At Liquid Web, we are proud to rival leading cloud platforms with unparalleled performance and reliability.
Related Articles:
About the Author: Luke Cavanagh
Product Operations Manager at Liquid Web. Devoted husband and Tween wrangler. Synthwave enthusiast. Jerry Goldsmith fan. Doctor Who fan and related gubbins.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
In-place CentOS 7 upgrades
Read ArticleHow to use kill commands in Linux
Read ArticleChange cPanel password from WebHost Manager (WHM)
Read ArticleChange cPanel password from WebHost Manager (WHM)
Read ArticleChange the root password in WebHost Manager (WHM)
Read Article