How to Install Redis on CentOS 7

A well-known means to improve the efficiency of modern computer applications is by enabling caching. Caching simply means keeping active data in a temporary store to make it easier and faster to access and Redis is one of the most popular caching solutions out there which supports most programming languages including Node.js, Python, PHP, Java, C, and much more.

Redis is an advanced and feature-rich key-value store that works in most POSIX systems such as Linux (which is the recommended platform for production deployment), *BSD, and OS X without external dependencies. It has three major uses: as a database, cache and message broker. It supports various data structures including strings, lists, sets, hashes, sorted sets with range queries, bitmaps and much more.

Read Also: How to Install Redis in RHEL 8

Some of its key features include built-in replication, cluster mode, partitioning (distributing data among multiple instances), transactions, notifications of key-space events, Lua scripting, mass insertion of data in a Redis instance in a short time, memory optimization, and so much more. Importantly, it supports an API which allows you to extend Redis functionality using external modules.

In this article, we will explain to you how to install, configure and test a Redis server on CentOS 7 Linux.

Installing Redis Server on CentOS 7

1. To install Redis package on CentOS 7, you need to install the EPEL repository on your system using the YUM package manager as shown.

# yum install epel-release
Install Epel in CentOS 7

Install Epel in CentOS 7

2. Once EPEL has been installed, you can now install Redis package from the repository as follows.

# yum install redis 
Install Redis in CentOS 7

Install Redis in CentOS 7

3. Once you have installed the package, you need to set up your server to achieve high performance when using Redis. You need to perform some settings in the kernel as explained.

First, ensure that you have set up swap space in the server. It is recommended to set up as much as swap as memory.

4. Next, set the Linux kernel overcommit memory setting to 1 by adding vm.overcommit_memory = 1 to /etc/sysctl.conf configuration file.

# sysctl vm.overcommit_memory=1
Set Kernel Parameter for Redis

Set Kernel Parameter for Redis

and then apply the change by rebooting the system Or enable the setting immediately by running the following command.

# sysctl vm.overcommit_memory=1
Set Kernel Parameter Using Sysctl Command

Set Kernel Parameter Using Sysctl Command

Also make sure that the transparent huge pages kernel feature is disabled because it negatively has an impact on both memory usage and latency using the following echo command.

# echo never > /sys/kernel/mm/transparent_hugepage/enabled

Configuring Redis Server on CentOS 7

5. The default configuration for Redis is /etc/redis.conf. Before you can edit it, create a back up of it as follows. This enables you to revert to the back up of the default configurations in case of any mistakes.

# cp /etc/redis.conf /etc/redis.conf.orig

6. Then open the original Redis configuration file for editing using your any of your favorite text-based editors as shown.

# vi /etc/redis.conf 

There are several configuration directives, and their meaning and intended usage is available and well explained in the file.

A typical configuration example is allowing remote access to the Redis server. By default, Redis is configured to accept connections only on the local server where it is running, i.e on the loopback interface ( and it listens on port 6379.

7. To allow remote access, you can set it to listen to a specific interface or multiple selected interfaces using the "bind" configuration directive, followed by one or more IP addresses as follows.


8. To accept connections on a different port, change the value of the port directive.

port 5000
Configure Redis in CentOS 7

Configure Redis in CentOS 7

After making all the necessary changes, save the file and exit it.

9. At this point, you have set up your server to efficiently run Redis and configured the Redis server to work the way you want. Now you need to start the Redis service, for now, enable it to automatically start every time the system is rebooted, and check its status using the systemctl utility as shown.

# systemctl start redis
# systemctl enable redis
# systemctl status redis
Verify Redis Status

Verify Redis Status

10. To check the interface and port the Redis server is listening on, use the netstat command.

# netstat -tlpn
Check Redis Port

Check Redis Port

11. If you have the firewalld service running on your system, you need to open port 6379 in the firewall configuration to allow external connections to the Redis server.

# firewall-cmd --permanent --zone=public --add-port=6379/tcp 
# firewall-cmd  --reload
Open Redis Port

Open Redis Port

Testing Connectivity to Redis Server

12. To test connectivity to the Redis server, you can open the Redis client program and run a test command (in this case list connected clients) as follows.

# redis-cli
> client list	#list clients connected to the server
Test Redis Connection

Test Redis Connection

Now you can build fast, dynamic and modern applications on your CentOS 7 server using Redis. Consult the Redis documentation for more information and configuration options. If you have any queries or thoughts to share, use the feedback form below to reach us.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.