Redis is an in-memory data structure store, used as a distributed key-value database, cache, and message broker, with optional durability. Redis supports different data structures such as strings, lists, hashes, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.
In this tutorial, we are going to learn how to install Redis 7 on Rocky Linux/AlmaLinux 9, enable the service, and apply common configuration changes (authentication, persistence, and remote access).
Related Content
Prerequisites
To follow along, ensure that you have:
- An updated Rocky Linux/AlmaLinux 9 server
- Access to the Internet
- Root access to the server or user with sudo access
Update Rocky Linux 9 Server
Before proceeding, ensure that the server is updated using this command:
Let us also ensure vim is installed using this command since we will use it later:
1
| sudo dnf install -y vim
|
Installing Redis
Redis 7 is not available in the default Rocky Linux 9 repositories. We will use the Remi repository and enable the Redis module stream we want to install.
Enable Remi repo using this command:
1
| sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
|
Type y to accept the importing of the GPG keys. We can then list the modules available using this command:
1
2
3
4
5
6
7
8
9
10
11
| sudo dnf module list redis
Last metadata expiration check: 0:01:49 ago on Tue Aug 9 01:15:42 2022.
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name Stream Profiles Summary
redis remi-5.0 common [d] Redis persistent key-value database
redis remi-6.0 common [d] Redis persistent key-value database
redis remi-6.2 common [d] Redis persistent key-value database
redis remi-7.0 common [d] Redis persistent key-value database
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
|
Enable the Redis 7 module stream (this example uses remi-7.0):
1
| sudo dnf module enable -y redis:remi-7.0
|
Finally install Redis:
1
| sudo dnf install -y redis
|
Use this command to confirm the redis package installed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| rpm -qi redis
Name : redis
Version : 7.0.4
Release : 1.el9.remi
Architecture: x86_64
Install Date: Tue Aug 9 01:18:48 2022
Group : Applications/Databases
Size : 6006104
License : BSD
Signature : RSA/SHA256, Mon Jul 18 14:27:18 2022, Key ID b19527f1478f8947
Source RPM : redis-7.0.4-1.el9.remi.src.rpm
Build Date : Mon Jul 18 14:24:07 2022
Build Host : builder.remirepo.net
Packager : Remi Collet
Vendor : Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
URL : http://redis.io
Bug URL : https://forum.remirepo.net/
Summary : A persistent key-value database
Description :
Redis is an advanced key-value store. It is often referred to as a data
structure server since keys can contain strings, hashes, lists, sets and
sorted sets.
You can run atomic operations on these types, like appending to a string;
incrementing the value in a hash; pushing to a list; computing set
intersection, union and difference; or getting the member with highest
ranking in a sorted set.
In order to achieve its outstanding performance, Redis works with an
in-memory dataset. Depending on your use case, you can persist it either
by dumping the dataset to disk every once in a while, or by appending
each command to a log.
Redis also supports trivial-to-setup master-slave replication, with very
fast non-blocking first synchronization, auto-reconnection on net split
and so forth.
Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
limited time-to-live, and configuration settings to make Redis behave like
a cache.
You can use Redis from most programming languages also.
|
Now that the service has been installed, let’s start it with this command:
1
| sudo systemctl enable --now redis
|
After the service starts, use this command to check the status of the service:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| sudo 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 Tue 2022-08-09 01:19:07 UTC; 11s ago
Main PID: 150066 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 9952)
Memory: 7.7M
CPU: 23ms
CGroup: /system.slice/redis.service
ββ150066 "/usr/bin/redis-server 127.0.0.1:6379"
Aug 09 01:19:07 local-kip-rocky9-srv systemd[1]: Starting Redis persistent key-value database...
Aug 09 01:19:07 local-kip-rocky9-srv systemd[1]: Started Redis persistent key-value database.
|
The Active: active (running) means that the service has been started successfully.
Configuring Redis
The redis configuration file is located at /etc/redis/redis.conf. In this section, we will update the config to:
- allow remote access (optional)
- set an authentication password
- enable persistence for recovery
Edit redis config file using this:
1
| sudo vim /etc/redis/redis.conf
|
Allow remote access (optional)
By default Redis listens on 127.0.0.1 only, which is safer. Only enable remote access if you need it and you have a firewall/security group restricting who can connect.
To allow remote access to the redis instance, bind Redis to 0.0.0.0 (or better: bind to a specific private IP):
Set a password
Set a strong password (use your own value; do not reuse the example below):
1
| requirepass CHANGE_ME_TO_A_STRONG_PASSWORD
|
Enable persistence (AOF)
Enable Append-Only File (AOF) persistence so Redis can recover after a restart:
1
2
| appendonly yes
appendfilename "appendonly.aof"
|
Restart redis service to apply changes:
1
| sudo systemctl restart redis
|
If you enabled remote access and you have an active firewalld service, allow port 6379/tcp:
1
2
| sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reload
|
Connecting to redis locally:
To authenticate:
1
2
| 127.0.0.1:6379> auth CHANGE_ME_TO_A_STRONG_PASSWORD
OK
|
You should receive OK in the output. If you input a wrong password, Authentication should fail.
Check redis information.
This will output a long list of data. You can limit the output by passing Section as an argument. E.g.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| 127.0.0.1:6379> INFO Server
# Server
redis_version:7.0.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:222b5ae120437328
redis_mode:standalone
os:Linux 5.14.0-70.13.1.el9_0.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:11.2.1
process_id:150066
process_supervised:systemd
run_id:322c19ae671727e2dfa240de3f976e30c9840756
tcp_port:6379
server_time_usec:1660008021911324
uptime_in_seconds:74
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:15840853
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
|
Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15 -a "CHANGE_ME_TO_A_STRONG_PASSWORD"
====== PING_INLINE ======
10000 requests completed in 0.23 seconds
15 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Latency by percentile distribution:
0.000% <= 0.055 milliseconds (cumulative count 2)
50.000% <= 0.127 milliseconds (cumulative count 5509)
75.000% <= 0.159 milliseconds (cumulative count 7514)
..........
99.940% <= 0.503 milliseconds (cumulative count 9994)
100.000% <= 0.607 milliseconds (cumulative count 10000)
Summary:
throughput summary: 74074.07 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.159 0.072 0.151 0.239 0.279 0.567
|
For more options and examples, use:
Conclusion
In this guide, we installed and configured Redis 7 on Rocky Linux/AlmaLinux 9 using the Remi repository, enabled the service, and applied common settings like authentication and persistence.