Install and Configure Redis Server on Rocky Linux 8 / AlmaLinux 8. Redis is an open-source in-memory data structure store that can be used as a NoSQL database, message broker, or cache. It is ideal for applications that frequently handle large amounts of data. This tutorial will explain how to install and configure Redis Server version 5.x on Rocky Linux 8 or AlmaLinux 8.
Before beginning, you will need to have a registered domain name and have configured DNS records pointing to your server’s IP address. You will also need to make sure you have root access or equivalent privileges to install and configure Redis.
Install Redis Server on Rocky Linux 8 / AlmaLinux 8
In the next section we cover all the steps that are required to install and configure Redis Server on Rocky Linux 8 / AlmaLinux 8.
Step 1: Install Redis packages
Let’s begin the process by updating system package list and upgrade any existing packages:
sudo dnf -y update
Redis server and client packages are available on the OS AppStream repository. You can check versions using the commands below:
$ sudo dnf module list redis
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
redis 5 [d][e] common [d] [i] Redis persistent key-value database
redis 6 common [d] Redis persistent key-value database
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
From the output we can see the default version is 5. We need to reset and enable 6 instead.
sudo dnf -y module reset redis
sudo dnf install @redis:6
Accept installation prompts to proceed.
Transaction Summary
======================================================================================================================================================================================================
Install 1 Package
Total download size: 1.2 M
Installed size: 4.3 M
Is this ok [y/N]: y
After installation of the package, proceed to start and enable redis service to start at boot.
sudo systemctl enable --now redis
Service status should show running.
$ 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) since Mon 2023-01-16 07:09:09 UTC; 6s ago
Main PID: 30476 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 23036)
Memory: 7.3M
CGroup: /system.slice/redis.service
└─30476 /usr/bin/redis-server 127.0.0.1:6379
Jan 16 07:09:09 rocky8.mylab.io systemd[1]: Starting Redis persistent key-value database...
Jan 16 07:09:09 rocky8.mylab.io systemd[1]: Started Redis persistent key-value database.
Step 2: Configure Redis Server
Redis Server can be configured by editing the configuration file located at /etc/redis.conf
.
Enable Redis Service to listen on all interfaces
By default, Redis service listens on 127.0.0.1
.
$ ss -tunelp | grep 6379
tcp LISTEN 0 128 127.0.0.1:6379 0.0.0.0:* users:(("redis-server",pid=30348,fd=6)) uid:986 ino:71091 sk:4 <->
You can edit to allow the service listen on all network interfaces for remote clients connections.
sudo vim /etc/redis.conf
The line to changed is bind 127.0.0.1
to below:
bind 0.0.0.0
Restart Redis after making the change using the commands below.
sudo systemctl restart redis
Confirm if Redis Server is now listening on the new bind address.
$ ss -tunelp | grep 6379 tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* users:(("redis-server",pid=30348,fd=6)) uid:986 ino:71091 sk:4 <->
Step 3: Configuring Redis Authentication
Configure Redis Authentication for clients to require AUTH <PASSWORD>
before processing any other commands. Edit the configuration file using your favorite file editor.
requirepass <AuthPassword>
Set desired password in requirepass parameter.
requirepass StrongPassword
Step 4: Setting Persistent Store for Recovery
Set persistence mode by changing the appendonly
value to yes
appendonly yes
appendfilename "appendonly.aof"
Restart redis service after making the changes
sudo systemctl restart redis
If you have an active firewalld service, allow port 6379
sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload
Confirm status of your service after the restart.
systemctl status redis
Step 5: Connect to Redis Server from CLI
An easy way to test Redis server is by running the command redis-cli
and pass ping as an argument.
$ redis-cli ping
PONG
If you see “PONG” in response, it indicates that Redis server is running and responding to commands. You can also use interactive session.
$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> INFO
NOAUTH Authentication required.
Test authentication of Redis.
127.0.0.1:6379> AUTH <AuthPassword>
OK
You should receive OK
in the output. If you input a wrong password, Authentication should fail:
127.0.0.1:6379> AUTH WrongPassword
(error) ERR invalid password
Check redis information.
127.0.0.1:6379> INFO
This will output a long list of data. You can limit the output by passing Section as an argument. E.g.
127.0.0.1:6379> INFO Server
# Server
redis_version:6.2.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:56aeeede275be948
redis_mode:standalone
os:Linux 4.18.0-425.3.1.el8.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:8.5.0
process_id:30517
process_supervised:systemd
run_id:e33d0c7941bf3add63ffc9dc2a30c34657835e06
tcp_port:6379
server_time_usec:1673854139726987
uptime_in_seconds:631
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:12909755
executable:/usr/bin/redis-server
config_file:/etc/redis.conf
io_threads_active:0
Step 6: Performing Redis Benchmarking
Run the benchmark with 10
parallel connections, for a total of 100k
requests, against local redis to test its performance.
# redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 10
..................................................
100.00% <= 0 milliseconds
85470.09 requests per second
====== LRANGE_500 (first 450 elements) ======
100000 requests completed in 1.17 seconds
10 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
85397.09 requests per second
====== LRANGE_600 (first 600 elements) ======
100000 requests completed in 1.18 seconds
10 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
84530.86 requests per second
====== MSET (10 keys) ======
100000 requests completed in 1.18 seconds
10 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
84961.77 requests per second
To see all possible command options use --help
$ redis-benchmark --help
You can check clients connected to your Redis server using:
127.0.0.1:6379> client list
id=185 addr=127.0.0.1:54300 fd=8 name= age=75 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
Using Redis with Python
To use redis with Python, install Python Redis Client Library:
sudo yum -y install python-redis
Using Redis with PHP
To connect to Redis server with PHP, install PHP Redis Client Module.
sudo yum -y install php-redis
Conclusion
We have successfully installed and configured Redis Server 5.x on Rocky Linux 8 or AlmaLinux 8. With Redis, you can store data in an in-memory key-value store and can be used for various applications including caching and message brokering. We hope this guide has been helpful for you in setting up Redis on your systems.
One of the key features of Redis is the ability to handle high-performance data operations in any kind of application. By storing its data in memory, it has faster data access than traditional disk-based databases. This makes Redis an ideal choice for use cases such as real-time analytics, session management, and leaderboards. With Redis support for data clustering you can easily achieve horizontal scaling of the database to handle the increased load by adding extra nodes. This enables Redis server(s) to handle large amounts of data and traffic without losing on the performance aspect.