English
+370 5 205 5502 sales@monovm.com

How to install Redis on CentOS 8

How to install Redis on CentOS 8, Redis, or Remote Dictionary Server is an in-memory data structure project. In this tutorial, we will go through the installation and setup processes of Redis on CentOS 8.

09 Sep, 21 by Susith Nonis 13 min Read

List of content you will read in this article:

Have you ever wanted to have a database but didn’t want to have to learn SQL? Well, there are databases out there that do not use SQL, such as Redis. Today, we will teach you how to install Redis on CentOS with a few simple steps. Before getting into that, however, let us first explain what Redis is and why you might want to pick it over other similar platforms.

 

According to Redis's official site, “Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.”

 

You might have heard and been aware of MySQL, the fully managed database to deploy cloud-native applications. But Redis is a NoSQL database. The important property of Redis that it stores data as a key-value pair whereas in regular databases, you have to create rows. 

The regular databases use columns and tables to associate them with each other and define different filters and titles to every record. You have to manually add the information in each row to fill the whole database with information. Unlike relational databases like MySQL, Redis is a NoSQL database that stores data as a key-value pair.

The data feeding process in Redis has made it very easy, simple, and straightforward. The whole system is quite flexible and intelligently connected. Redis gives you maximum productivity without taking any substantial effort from you.

The most significant use of Redis is that people use it as a catching system. It is a flexible database, yet it provides you the persistence and connectivity in high fidelity to all data written on it.

The storage and retrieval processes, are super-fast making it possible to write and retrieve data like a flash. The cache system is robust and can outrun interruptions and withstand failures.

Ships are connected with the master and slave data connectivity processes. When you made a change into the master node, the master-slave replication feature applies the single change on the master node to all the slave nodes connected. Redis astounds programmers and data analysts with a staggering storage ability to handle large keys and value pairs up to 512 MB.

Raspberry Pi and Arduino to support IoT apps easily install and handle Redis because of its very small footprint. This is a cross-platform system, which is the most productive, efficient, and flexible database; you can even install it on Windows, Mac, and Linux server.

 

Abstract Data Structures that Redis Supports:

There are various kinds of abstract data structures which it supports flexibility, some of these are:

  • Strings
  • Lists
  • Maps
  • Sets
  • Sorted sets
  • HyperLogLogs
  • Bitmaps
  • Streams
  • Spatial indexes

Salvatore Sanfilippo developed this project in 2019, and Redis Labs sponsored this project; that's why it is called Redis. 

 

This key value-data structure is mainly used as a database. People also use it as a message broker or as a cache. This database supports a wide variety of languages with high-performance flexibility. In this tutorial, you would learn how to install Redis on CentOS 8.

Prerequisites:

Before you can start the Redis installation process on CentOS 8, make sure that you have a non-root user account on your server with Sudo privileges. Always enable IPv6 on your server, or you will not have the installation started.

Redis Installation Tutorial

This package is not readily available in CentOS 8. You need to install the Redis from other repositories. Like:

Install Yum-utils and Epel-release packages. Use the following command to complete the installation:

sudo yum install epel-release yum-utils

Then Add the Remi repository using this command:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Enable this repository by running the following command:

sudo yum-config-manager --enable remi

Now install Redis run give this command:

sudo yum install redis

You will have to start Redis using this command manually:

sudo systemctl start redis

Then enable Redis service with:

sudo systemctl enable redis

Type this to check the status of Redis:

sudo systemctl status redis-server

This command should give you the following 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 Sat 2019-03-21 15:12:03 PST; 39s ago
Main PID: 2157 (redis-server)
CGroup: /system.slice/redis.service
        └─2157 /usr/bin/redis-server 127.0.0.1:6379

If you receive the output mentioned above, it means you have completed one process of installation. Now it's time to move on to the next step.

Binding Redis

Redis is not accessible by other hosts because of the default feature. You need to bind it to the localhost (127.0.0.1). To do so, you have to take the following steps.

Open the Redis configuration file by typing:

sudo nano /etc/redis.conf

Bind it by removing the hash(#) from the beginning of the following line:

# bind 127.0.0.1

So that it looks like this:

bind 127.0.0.1

Now replace your IP address with the server:

bind 127.0.0.1 YOUR_IP_ADDRESS

Pressing CTRL+X will save the commands and close the interface.

Restart Redis and type this command:

sudo systemctl restart redis-server

Now run the below command to make the confirmation for changes:

tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      14222/redis-server 
tcp6       0      0 153.168.93.106:6379           *:*               LISTEN      14222/redis-server 

Setup FirewallD from remote host using:

sudo firewall-cmd --new-zone=redis –permanent

Now it’s time to open port 6379 permanently:

sudo firewall-cmd --zone=redis --add-port=6379/tcp –permanent

Replace your client IP address with the machine by giving it the following command:

sudo firewall-cmd --zone=redis --add-source=YOUR_CLIENT_IP_ADDRESS –permanent

Reload the firewall and confirm the changes took effect by typing:

sudo firewall-cmd –reload

To confirm everything has gone as planned, type the following command:

redis-cli

Redis shell will open before you, and to confirm the authenticity, type the following word:

ping

You must see this exact output after the previous command:

PONG

If you receive the output mentioned above, now it's time to exit the Redis-cli shell by using this command:

exit

Testing Using Redis-client

Run Redis-cli to start testing by typing:

redis-cli

In order to find out the authentic execution, first of all, store a value with the key myname to store value "John". Thus, use the following command:

set myname "John"

You must see the following output:

OK

Now to fetch the value of myname, run the following command:

get myname

In response, you must have the following output:

John

It is time to exit the Redis-cli by typing:

exit

Configure Redis Authentication

Configure Redis Authentication to require AUTH before the client can make any processing:

requirepass 

Example:

requirepass StrongPassword

Set Persistent Store for Recovery

Change the appendonlyvalue to yes by:

appendonly yes
appendfilename "appendonly.aof"

Restart Redis service:

sudo systemctl restart redis

For active firewalld service, allow port 6379:

sudo firewall-cmd --add-port=6379/tcp --permanenent
sudo firewall-cmd –reload

Check redis service status:

$ sudo systemctl status redis

You will have the following 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 Sat 2018-12-29 10:11:56 EAT; 9s ago
Process: 30485 ExecStop=/usr/libexec/redis-shutdown (code=exited, status=0/SUCCESS)
Main PID: 30500 (redis-server)
Tasks: 4 (limit: 11510)
Memory: 6.4M
CGroup: /system.slice/redis.service
            └─30500 /usr/bin/redis-server 0.0.0.0:6379
Dec 29 10:11:56 rhel8.local systemd[1]: Stopped Redis persistent key-value database.
Dec 29 10:11:56 rhel8.local systemd[1]: Starting Redis persistent key-value database…
Dec 29 10:11:56 rhel8.local systemd[1]: Started Redis persistent key-value database.

Connect to Redis

Confirm your local connectivity by:

$ redis-cli
127.0.0.1:6379> INFO

NOAUTH Authentication required.

Test authenticate:

127.0.0.1:6379> AUTH

If everything is fine, you will have the following output:

OK

Check Redis information.

127.0.0.1:6379>  INFO

You will see the following output:

127.0.0.1:6379> INFO Server
 Server
 redis_version:4.0.10
 redis_git_sha1:00000000
 redis_git_dirty:0
 redis_build_id:fdf31b4ab3504500
 redis_mode:standalone
 os:Linux 4.18.0-32.el8.x86_64 x86_64
 arch_bits:64
 multiplexing_api:epoll
 atomicvar_api:atomic-builtin
 gcc_version:8.2.1
 process_id:30500
 run_id:d8c5ba56a0735a6831a0b3467c3efa95ac174cdd
 tcp_port:6379
 uptime_in_seconds:222
 uptime_in_days:0
 hz:10
 lru_clock:2563866
 executable:/usr/bin/redis-server
 config_file:/etc/redis.conf

 

Built-in tool the Redis-benchmark allows you to see the system’s performance statistics. You can have access to data transfer rate, throughput or latency are a few capabilities from a long list of possibilities.

Some of the command options are as follow:

-n:

  • Defines the number of requests
  • The default is 100000

-c:     

  • Defines the number of parallel connections
  • The default value is 50

-p:    

  • Redis port
  • Which by default is 6379

-h:    

  • Used to define the host
  • The default value is set to localhost (127.0.0.1)

-a:     

  • Accustomed to prompt for a password
  • If the server needs authentication

-q:     

  • Stands for quiet mode
  • Displays the number of average requests made per second

-t:      

  • Used to run a combination of tests

-P:    

  • Used for pipelining
  • Also, for enhanced performance

-d:

  • Specifies the data size
  • Bytes for getting and SET values
  • By default, this is set to 3 bytes

Perform Redis Benchmarking

For 10 parallel connections, for a total of 100k requests:

# redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 10

The screen would show this entire result:

..................................................
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 show connected clients, use:

127.0.0.1:6379> client list

The result would be:

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

 

Congratulations, you have successfully installed and configured Redis on CentOS 8. If you find any difficulty in installation, contact our support team. While SQL-based databases are still the way to go, there are still other options available on the market such as Redis that require absolutely no SQL knowledge. If you found this tutorial useful or have any questions, please leave them in the comment section below.

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way possible. Not a fan of coffee, a sweet addict and a self accredited 'master chef'.