Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

Install Redis on CentOS

Published

Redis is a flexible open-source configurable key-value store that uses the in-memory system data storage model for high performance. You can use the Redis as a cache, database, and message broker, and it also supports different data structures, such as Hashes, Strings, Lists, Sets, and more. Redis offers an array of features, such as automatic failover, transactions, pub/sub, and more.

Redis is widely known for its scalability, flexibility, and performance. It also offers extensive support for languages. The availability and cluster feature of Redis makes sure that the data on the server is safe. The Redis Sentinel offers notifications, automatic failover, and monitoring. Redis also offers automatic partitioning of multiple Redis nodes with the help of Redis Cluster.

In this knowledge base, you will learn how to install and configure Redis on your CentOS 7 server.

Prerequisites

  1. Server running a clean CentOS 7 installation.
  2. A user with sudo privilege.
  3. Access to the server via SSH.

Install Redis on CentOS 7 Server

The default CentOS repositories do not include the Redis package so we first have to add the repository. And before that, we have to install the essential packages.

Execute the following command to install the necessary packages on the server.

$ sudo yum install wget make gcc

Now, install, and enable the Remi repository on your server by executing the following commands.

$ sudo yum install epel-release yum-utils
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo yum-config-manager --enable remi

Execute the following command to install the Redis package.

$ sudo yum install redis

The installation takes some time to complete. Once the installation is complete, start and enable Redis to start the service automatically during the system boot. To do so, run the following systemctl commands.

$ sudo systemctl start redis
$ sudo systemctl enable redis

To verify the status of the Redis service, execute the following command.

$ sudo systemctl status redis

If the Redis service is up and running, you should see an output similar to the one shown below.

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-12-24 15:21:55 PST; 40s ago
Main PID: 2157 (redis-server)
CGroup: /system.slice/redis.service
└─2157 /usr/bin/redis-server 127.0.0.1:6379

Please note that to run the Redis service, you should enable the IPv6 on the CentOS server. Now, the installation of Redis on your CentOS 7 server is successful, and the service is up and running.

Configure Redis Remote Access

By default, Redis does not allow remote access. So, you can only connect to Redis from the local system. If you want to connect to the Redis server remotely, you need to follow the below-given process. Please note that if your application and Redis is running on a single machine, you should not enable the remote access as the connections made are local. Now, Let’s see how to enable remote connections in Redis. First, open the Redis configuration file in edit mode by executing the following command.

$ sudo nano /etc/redis.conf

In the configuration file, locate the line that begins with ‘bind 127.0.0.1’, and then add the private IP address of the server after the IP address of the Redis machine. For example, if the server’s private IP address is 196.35.00.234, then the line should be as follows.

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 196.35.00.234

Please make sure that you replace 196.35.00.234 in the above line with your actual server IP address.

After that, restart the Redis service to make sure that the changes take effect by executing the following command.

$ sudo systemctl restart redis

Run the following ‘ss’ command to verify if the Redis service is listening to the 6379 port on your private interface.

$ sudo ss -an | grep 6379

If the Redis service is listening to the port, then you should see an output similar to the one shown below.

tcp    LISTEN     0      128    196.35.00.234:6379            *:*

tcp    LISTEN     0      128    127.0.0.1:6379                  *:*

If you are using FirewallD to manage your firewall, execute the following set of commands to allow access from the ‘196.35.00.0/24’ subnet to your server.

Execute the following command to create a new zone named Redis.

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

Then, execute the following commands to open the port 6379 and allow the private network to access the server.

$ sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
$ sudo firewall-cmd --zone=redis --add-source= 196.35.00.0/24 --permanent

After that, execute the following command to reload FirewallD to make sure that the changes take effect.

$ sudo firewall-cmd --reload

Then, to verify if everything is properly set up, ping the Redis server by using the ‘redis-cli’ utility from your remote machine. The ‘redis-cli’ utility offers a command-line interface for the Redis server.

$ sudo redis-cli -h <Redis_IP_Address> ping

In the above command, replace the <Redis_IP_Address> with your actual IP address of the Redis server. For example,

$ sudo redis-cli -h 127.0.0.1 ping

The above command should return the following response if the setup is proper.

PONG

 

Conclusion

Redis is a flexible open-source configurable key-value store that uses the in-memory system data storage model for high performance. You can use the Redis as a cache, database, and message broker, and it also supports different data structures, such as Hashes, Strings, Lists, Sets, and more. We hope that this knowledge base was helpful to you. Please comment below for any questions or queries. If you are an InterServer customer, please reach out to our support team for further help.

Account services are unavailable until the production backend is configured.