5.4 C
Friday, March 5, 2021

“it’s time to ban our Princes from marrying American women” – Piers Morgan

Before Prince Harry, who stepped back from his royal duties to protect his wife, there was King Edward VIII who abdicated his throne so...

    Latest Posts

    How to Install and Configure Redis on Linux [CentOS 7]

    Time needed: 5 minutes.

    Redis is an open-source in-memory data structure store. It can be used as a database, cache and message broker and supports various data structures such as Strings, Hashes, Lists, Sets, etc. Redis provides high availability via Redis Sentinel including monitoring, notifications Automatic failover. It also provides automatic partitioning across multiple Redis nodes with Redis Cluster. This tutorial explains how to install and configure Redis on a CentOS 7 server.
    Redis package is not included in the default CentOS repositories. We will be installing Redis version 5.0.2 from the Remi repository.

    The installation is pretty straightforward, just follow the steps below:

    1. Start by enabling the Remi repository by running the following commands in your SSH terminal:

      sudo yum install epel-release yum-utilssudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpmsudo yum-config-manager --enable remi

    2. Install the Redis package by typing:

      sudo yum install redis

    3. Once the installation is completed, start the Redis service and enable it to start automatically on boot with:

      sudo systemctl start redissudo systemctl enable redisCreated symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
      To check the status of the service enter the following command
      sudo systemctl status redis
      You should see something like the following:
      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 2018-11-24 15:21:55 PST; 40s ago Main PID: 2157 (redis-server) CGroup: /system.slice/redis.service └─2157 /usr/bin/redis-server

    Redis service will fail to start if IPv6 is disabled on your server.

    Congratulations, at this point you have Redis installed and running on your CentOS 7 server.

    Configure Redis Remote Access

    Redis doesn’t allow remote connections. You can connect to the Redis server only from (localhost) – the machine where Redis is running.

    Perform the following steps only if you want to connect to your Redis server from remote hosts. If you are using a single server setup, where the application and Redis are running on the same machine then you should not enable remote access.

    To configure Redis to accept remote connections open the Redis configuration file with your text editor:

    sudo nano /etc/redis.conf

    Locate the line that begins with bind and add your server private IP address after

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Make sure you replace with your IP address. Save the file and close the editor.

    Restart the Redis service for changes to take effect:

    sudo systemctl restart redis

    Use the following ss command to verify that the Redis server is listening on your private interface on port

    ss -an | grep 6379

    You should see something like below:

    tcp    LISTEN     0      128            *:*
    tcp    LISTEN     0      128                  *:*

    Next, you’ll need to add a firewall rule that enables traffic from your remote machines on TCP port 6379.

    Assuming you are using FirewallD to manage your firewall and you want to allow access from the subnet you would run the following commands:

    sudo firewall-cmd --new-zone=redis --permanentsudo firewall-cmd --zone=redis --add-port=6379/tcp --permanentsudo firewall-cmd --zone=redis --add-source= --permanentsudo firewall-cmd --reload

    The commands above create a new zone named redis, opens the port 6379 and allows access from the private network.

    At this point, Redis server will accept remote connections on TCP port 6379.

    Make sure your firewall is configured to accept connections only from trusted IP ranges.

    To verify that everything is set up 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:

    redis-cli -h <REDIS_IP_ADDRESS> ping

    The command should return a response of PONG:



    Congratulations, you have successfully installed Redis on your CentOS 7 server. To learn more about how to use Redis, visit their official documentation page.

    If you have questions, feel free to leave a comment below.

    by Victor CHUKWUKA

    Latest Posts

    Don't Miss