In this tutorial we will share step by step instructions to install redis server on Rocky Linux 9. But before we start, let us understand basics about Redis server and how it is used.
Introduction
Redis (Remote Dictionary Server) is an open source (BSD licensed), in-memory data structure repository used by millions of developers as a database, cache, streaming engine, and message broker. Redis provides data structures such as arrays, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlogs, geospatial indexes, and streams
The Redis project was developed and maintained by Salvatore Sanfilippo starting in 2009. In 2021, after the original author and main caregiver separated, Redis Labs renamed Labs and is now known simply as "Redis".
By the end of this article you will have installed Redis on Rocky Linux 9.
Different methods to Install Redis Server
Operating systems contain packages that they consider stable in their own repositories. They allow packages beyond their control to be installed by adding different repositories.
Rocky Linux 9 for Redis has a stable version in the base repository. There is a more recent version in the Remi repository. Let's first explain the installation steps from the base repository, then the steps to install the new version by adding the remi repository.
Method -1- Install Redis from Base repository
The redis package is in the rocky Linux 9 base repository:
[foc@rocky9 ~]$ sudo dnf search redis
============================================ Name Exactly Matched: redis =============================================
redis.x86_64 : A persistent key-value database
Install the package:
[foc@rocky9 ~]$ sudo dnf -y install redis
Enable the Redis service:
[foc@rocky9 ~]$ sudo systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
Start the Redis service:
[foc@rocky9 ~]$ sudo systemctl start redis
Stable Redis version in the Rocky Linux 9 repository:
[foc@rocky9 ~]$ redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9664d239a7dd0d5e
Redis stores its configuration files in /etc/redis/. Let's edit the /etc/redis/redis.conf file as follows:
- To allow remote access to Redis
- Password is set for Redis
- Add a pid file to Redis
- "
appendonly
" line is changed to yes
[foc@rocky9 ~]$ sudo vi /etc/redis/redis.conf #bind 127.0.0.1 -::1 bind 0.0.0.0 requirepass P@ssw0rd #pidfile /var/run/redis_6379.pid pidfile /var/run/redis/redis-server.pid #appendonly no appendonly yes
Then save and exit. Restart the Redis service:
[foc@rocky9 ~]$ sudo systemctl restart redis
Log into the Redis shell. We will use the password we defined above:
[foc@rocky9 ~]$ redis-cli
127.0.0.1:6379> auth P@ssw0rd
OK
127.0.0.1:6379> exit
Get information about the Redis server we set up:
[foc@rocky9 ~]$ redis-cli
127.0.0.1:6379> auth P@ssw0rd
OK
127.0.0.1:6379> info
# Server
redis_version:6.2.6
...
os:Linux 5.14.0-70.13.1.el9_0.x86_64 x86_64
...
# Memory
used_memory:895904
When we try to access from remote server:
foc@fedora:~$ telnet 192.168.122.238 6379
Trying 192.168.122.238...
telnet: connect to address 192.168.122.238: No route to host
We can see that the service is not accessed remotely. Let's define the following firewall rule:
[foc@rocky9 ~]$ sudo firewall-cmd --add-port=6379/tcp --permanent success [foc@rocky9 ~]$ sudo firewall-cmd --reload success
Try remote access again:
foc@fedora:~$ telnet 192.168.122.238 6379
Trying 192.168.122.238...
Connected to 192.168.122.238.
Escape character is '^]'.
Now we can access with port 6379. Congratulations. Installation from package base repository completed successfully.
Method -2- Install Redis from Remi repository
Version 7 appears to be up to date on the Redis official page. Let's install this version from the Remi repository. First, add the remi repository to the system:
[foc@rocky9 ~]$ sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
List the redis modules in the repository:
[foc@rocky9 ~]$ sudo dnf module list redis
Last metadata expiration check: 0:00:32 ago on Thu 22 Sep 2022 10:19:42 AM +03.
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:
[foc@rocky9 ~]$ sudo dnf module enable -y redis:remi-7.0
Install Redis package:
[foc@rocky9 ~]$ sudo dnf -y install redis
Show the installed version:
[foc@rocky9 ~]$ redis-server --version
Redis server v=7.0.5 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=d4c00522fab6a4be
Enable and start the Redis service:
[foc@rocky9 ~]$ sudo systemctl enable redis && sudo systemctl start redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
Edit the /etc/redis/redis.conf
file as follows:
- To allow remote access to Redis
- Password is set for Redis
- Add a pid file to Redis
- "
appendonly
" line is changed to yes
[foc@rocky9 ~]$ sudo vi /etc/redis/redis.conf #bind 127.0.0.1 -::1 bind 0.0.0.0 requirepass P@ssw0rd pidfile /var/run/redis/redis-server.pid appendonly yes
Restart the Redis service:
[foc@rocky9 ~]$ sudo systemctl restart redis
Let's give firewall access to port 6379:
[foc@rocky9 ~]$ sudo firewall-cmd --add-port=6379/tcp --permanent success [foc@rocky9 ~]$ sudo firewall-cmd --reload success
Login to Redis CLI and get info:
[foc@rocky9 ~]$ redis-cli
127.0.0.1:6379> auth P@ssw0rd
OK
127.0.0.1:6379> info
# Server
redis_version:7.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:d4c00522fab6a4be
redis_mode:standalone
os:Linux 5.14.0-70.13.1.el9_0.x86_64 x86_64
We have successfully completed the installation of Redis 7.0.5 (Current version).
How to test Redis performance?
Run the comparison with 10 parallel connections for a total of 5 thousand requests against the Redis we set up to test:
[foc@rocky9 ~]$ sudo redis-benchmark -h 127.0.0.1 -p 6379 -n 5000 -c 10 -a P@ssw0rd [sudo] password for foc: ====== PING_INLINE ====== 5000 requests completed in 0.07 seconds 10 parallel clients 3 bytes payload keep alive: 1 host configuration "save": 3600 1 300 100 60 10000 host configuration "appendonly": yes multi-thread: no ... Cumulative distribution of latencies: 54.480% <= 0.103 milliseconds (cumulative count 2724) 99.920% <= 0.207 milliseconds (cumulative count 4996) 100.000% <= 0.303 milliseconds (cumulative count 5000) Summary: throughput summary: 86206.90 requests per second latency summary (msec): avg min p50 p95 p99 max 0.105 0.032 0.103 0.151 0.175 0.223
Summary
For detailed information about using Redis, you can refer to the manual pages:
[foc@rocky9 ~]$ man redis-server
On the Redis community page, there is information about the environments where you can find instant and quick answers to your questions.