In this article, we will have explained the necessary steps to install and configure Redis on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Redis is an open-source in-memory database project implementing a distributed, in-memory key-value store with optional durability. Some of Redis features are built-in transactions, replication, and support for a variety of data structures like strings, hashes, lists, sets and so on. Redis Sentinel makes Redis highly available and it supports automatic partitioning with Redis Cluster.
Install Redis on CentOS
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
Step 2. Install Redis on CentOS 7.
Redis package is not included in the default CentOS repositories. We will be installing Redis version 5.0.2 from the Remi repository:
Redis package is available in default repository in CentOS 7. So to install Redis run below command:
Once the installation is completed, start the Redis service and enable it to start automatically on boot with:
Step 3. Configure Redis Remote Access.
By default, you can not access Redis from another host because its by default bound to localhost only. To confirm its bound to localhost (127.0.0.1), follow below instructions:
Locate the line that begins with bind 127.0.0.1 and add your server private IP address after 127.0.0.1:
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
To take changes effect, restart Redis server by running below command:
Use the following ss command to verify that the Redis server is listening on your private interface on port 6379:
You should see something like below:
tcp LISTEN 0 128 192.168.121.233:6379 *:*
tcp LISTEN 0 128 127.0.0.1:6379 *:*
Next, we will setup FirewallD for accessing Redis from a remote host:
Finally, reload FirewallD to tale changes effect:
To verify that everything is setup 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:
You should see exact below output:
Congratulation, you have learned how to install and configure Redis on CentOS 7. If you have any question, please leave a comment below.