How To Install Redis On CentOS 7

In this article , We have explained how to Install Redis on Centos 7.

I have also published articles which covers Installation and Configuration of Database engines on Ubuntu operating systems.Check it out.

Install MySQL & Configure on Ubuntu

Install MongoDB on Ubuntu

Install PostgreSQL on Ubuntu

Okay , Lets get started with the installation of Redis on Centos 7.

What Is Redis?

Redis is an open source , in-memory data structure store, used as a database, cache and message broker.

It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

In addition to being fully in-memory, Redis enables data persistence and high availability through replication and backups.

Installing Redis On Centos 7

Before proceeding further , Make sure you have root or sudo privileges to the system.

Update the default package repository to the latest available version using the below command.

sudo yum update -y

We have to add EPEL repository to the system in order to install Redis on the system.

sudo yum install epel-release

Then update the system using the below command.

sudo yum update

Lets install redis on the system using the command,

sudo yum install redis -y

By default , While installing redis It will automatically configure systemd service file for us to easily manage the redis service.

You can find the redis.service file under /usr/lib/systemd/system folder.

cat /usr/lib/systemd/system/redis.service

To start the redis service , Execute the below command.

systemctl start redis

To check the status of the redis service,

systemctl status redis

Enable the redis service to automatically start on system reboot.

systemctl enable redis

To check the version of redis installed on the system , Execute the following commands.

redis-server --version
redis-cli --version

By default , Redis will be running on localhost and listening on port 6379.

Using the below command , You can check the same.

sudo netstat -nltp |grep redis

To allow connections from the remote hosts , We need to edit redis.conf file and configure as shown below.

sudo vi /etc/redis.conf

Replace bind 127.0.0.1 to 0.0.0.0 , Save and close the file.

Install redis on Ubuntu

For the changes the take effect , We need to restart the redis service.

sudo systemctl restart redis

Now If you run the below command , You can see that redis will accept connections from any host.

netstat -nltp |grep redis

Connecting Redis

We use redis-cli , the Redis command line interface , using which we can send command to the redis server and we can read the replies sent by the server from the terminal.

Run the below command to test the connectivity with the Redis server.

redis-cli

And run ping to test the connectivity from the redis shell.You should get a response as PONG.

From this , We can confirm that the redis server is working as expected.

The more useful redis-cli command.

From the redis shell , run info to get the overall status of the redis server.

127.0.0.1:6379> info

You can check the details such as Number of clients connected with the redis server , Replication status , Memory & CPU used , Cluster status and much more.

To exit from the redis-cli shell , Execute the command.

127.0.0.1:6379> exit

Running Redis On Custom Port

As we know that Redis by default runs on the port 6379.For security reasons , If you wish to run redis server on different port.

Open the redis.conf file.

sudo nano /etc/redis.conf

and change the port number.

After changing the port , Save and close the file and restart the redis service for the changes to take effect.

After changing the port If you face issue as shown below,

Creating Server TCP listening socket 0.0.0.0:12111: bind: Permission denied

Run the following command and then restart the redis service.

semanage port -a -t redis_port_t -p tcp 12111

Replace 12111 with the port number you have configured on redis.conf file.

Now If you run the below command , You can see that the redis server is running on the port that you have configured.

Removing Redis From Centos7

If you wish to remove redis from the Centos 7 after testing , You can run the below command.

yum remove redis -y

But the above command will not completely remove redis from the system.

To find the file and folders of redis , Run the below command.

find / -name redis

And then remove all the files and folder of redis service.

We have successfully installed and configured Redis on Centos 7.

That’s all for this tutorial.Thanks for reading.

Hope you find it helpful.