How to Install and Configure Redis on CentOS 8

By 

Published on

3 min read

Install and Configure Redis on CentOS 8

Redis is an open-source in-memory key-value data store. It can be used as a database, cache and, message broker and supports various data structures such as Strings, Hashes, Lists, Sets, and more. Redis provides high availability via Redis Sentinel and automatic partitioning across multiple Redis nodes with Redis Cluster.

This guide covers the installation and configuration of Redis on CentOS 8.

Installing Redis on CentOS 8

Redis version 5.0.x is included in the default CentOS 8 repositories. To install it run the following commands as root or user with sudo privileges :

Terminal
sudo dnf install redis-server

Once the installation is completed, enable and start the Redis service:

Terminal
sudo systemctl enable --now redis

To check whether the Redis server is running, type:

Terminal
sudo systemctl status redis
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 2020-02-08 20:54:46 UTC; 7s ago

That’s it. You have Redis installed and running on your CentOS 8 server.

Configure Redis Remote Access

By default, Redis doesn’t allow remote connections. You can connect to the Redis server only from 127.0.0.1 (localhost) - the machine where Redis is running.

If you are using a single server setup, where the client connecting to the database is also running on the same host, you should not enable remote access.

To configure Redis to accept remote connections open the Redis configuration file with your text editor:

Terminal
sudo nano /etc/redis.conf

Locate the line that begins with bind 127.0.0.1 and add your server private IP address after 127.0.0.1.

/etc/redis.confini
bind 127.0.0.1 192.168.121.233

Make sure you replace 192.168.121.233 with your IP address. Save the file and close the editor.

Info
If you want Redis to listen to all the interfaces, just comment the line.

Restart the Redis service for changes to take effect:

Terminal
sudo systemctl restart redis

Use the following ss command to verify that the Redis server is listening on your private interface on port 6379:

Terminal
ss -an | grep 6379

You should see something like below:

output
tcp    LISTEN    0    128    192.168.121.233:6379    0.0.0.0:*
tcp    LISTEN    0    128    127.0.0.1:6379          0.0.0.0:*

Next, you’ll need to configure your firewall to enable traffic on TCP port 6379.

Typically you would want to allow access to the Redis server only from a specific IP address or IP range. For example, to allow connections only from 192.168.121.0/24, run the following commands:

Terminal
sudo firewall-cmd --new-zone=redis --permanent
sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
sudo firewall-cmd --zone=redis --add-source=192.168.121.0/24 --permanent
sudo firewall-cmd --reload

The commands above create a new zone named redis, opens the port 6379 and allows access from the private network.

At this point, the Redis server will accept remote connections on TCP port 6379.

Make sure your firewall is configured to accept connections only from trusted IP ranges.

To verify that everything is set up properly, you can try to ping the Redis server from your remote machine using the redis-cli utility which provides a command-line interface to a Redis server:

Terminal
redis-cli -h <REDIS_IP_ADDRESS> ping

The command should return a response of PONG:

output
PONG

Conclusion

We’ve shown you how to install Redis on CentOS 8. To learn more about how to use Redis, visit their official documentation page.

If you have questions, feel free to leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page