How to Install Redis on CentOS 8: A Step-by-Step Tutorial

Redis is a blazing-fast, open-source, in-memory key-value store that is commonly used for caching, session management, and as a message broker. If you’re running CentOS 8 and wish to take advantage of Redis for your applications, this step-by-step tutorial will guide you through the installation process.

Posted on

Redis is a blazing-fast, open-source, in-memory key-value store that is commonly used for caching, session management, and as a message broker. If you’re running CentOS 8 and wish to take advantage of Redis for your applications, this step-by-step tutorial will guide you through the installation process.

Prerequisites

Before you begin, make sure you have the following:

  1. A CentOS 8 server with root or sudo access.
  2. An SSH client to connect to your server.
  3. Basic familiarity with Linux command-line operations.

Step 1: Update the System

Start by ensuring your system is up to date. Run the following commands to update your package repository and packages:

sudo dnf -y update

This command will refresh your system’s package list and install any available updates.

Step 2: Install the EPEL Repository

Redis can be installed via the Extra Packages for Enterprise Linux (EPEL) repository, which provides additional software packages not included in the default CentOS repositories. To install EPEL, use the following command:

sudo dnf -y install epel-release

Step 3: Install Redis

With the EPEL repository enabled, you can now proceed to install Redis. Run this command:

sudo dnf -y install redis

This command will download and install Redis along with its dependencies.

Step 4: Start and Enable Redis

To ensure that Redis starts automatically when your server boots up and is currently running, you need to enable and start the Redis service. Execute the following commands:

sudo systemctl start redis
sudo systemctl enable redis

To check the status of the Redis service, use:

sudo systemctl status redis

If Redis is functioning without issues, you should see “active (running)” in the output.

Step 5: Configuring Redis (Optional)

By default, Redis is configured to accept connections only from localhost. If you wish to access Redis from remote servers or modify other configuration settings, you can edit the Redis configuration file. The configuration file is located at /etc/redis.conf.

Use your preferred text editor, such as Nano or Vim, to edit the configuration file:

sudo nano /etc/redis.conf

Make the necessary changes, save the file, and then restart the Redis service for the changes to take effect:

sudo systemctl restart redis

Step 6: Testing Redis

To test if Redis is working correctly, you can utilize the redis-cli tool to connect to the Redis server:

redis-cli

You should see a Redis prompt. From here, you can start executing Redis commands and interacting with the server. For example, you can set a key-value pair:

set mykey "Hello, Redis!"

To retrieve the value, use:

get mykey

If everything is set up correctly, you will see “Hello, Redis!” as the output.

Conclusion

Congratulations, you have successfully installed Redis on your CentOS 8 server, and you’re now prepared to leverage this high-performance data store for your applications. Redis has a wide range of use cases, including caching, real-time analytics, and more. To make the most of this powerful tool, remember to secure your Redis server and configure it according to your specific requirements. Enjoy using Redis on CentOS 8!