How to install and configure Redis on Ubuntu 20.04 LTS Cloud Servers

2021-12-01 By Nathan 4684 Views linux redis
6 reviews

Redis is basically in-memory key-value store known for flexible performance and a wide range of support. It is an open-source database, precisely, data structure store that can be used as a cache for database, intended for quick response for queries and messages. Application of Redis varies from use in session caching, full page cache, message queue applications and leader boards.


The following steps will install and configure Redis in Ubuntu 20.04LTS.


  1. As the first step we save a repository, adding the PPA to the system's Software Sources.

    # add-apt-repository ppa:chris-lea/redis-server
    

    redisubuntu1

  2. Update the package lists.

    # apt-get update
    

    redisubuntu2

  3. Start to install Redis using the command.

    # apt-get install redis-server -y
    

    redisubuntu3

  4. Once Redis is installed, enable the process so that it starts automatically at boot time.

    # systemctl enable redis-server.service
    

    redisubuntu4

  5. Installation is done, now start the configuration of Redis by following steps.

    # vi  /etc/redis/redis.conf
    


    Normal installation of Redis in an application server: This is the default configuration that connects to loopback IP to allow the connections:

    bind 127.0.0.1 ::1
    

    redisubuntu5

    In case if the server uses any private networking between the Redis server and the application server, the above line should be of the format.

    bind 127.0.0.1 ::1 <private-ip>
    


    Further customizing the Redis Configuration file, there is an option to reserve memory capacity for Redis. When you scroll down, you would be able to see the variable maxmemory.

    The capacity can be defined here:

    redisubuntu6

    The memory reuse method is to be defined for Redis. Here we use the Least Recently Used Algorithm for the purposes. When maxmemory reaches the limit, Redis has to remove the least recently used item from the memory and place the new item in the cache memory. Therefore, we look for the variable maxmemory-policy and we assign it as follows:

    redisubuntu7

  6. Now fine-tune the Redis installation, follow the steps below:


    Open the Redis log file using the command:

    # tail /var/log/redis/redis-server.log
    

    redisubuntu8

    The output will be like the screenshot above.

  7. Fix the first warning message.

    # echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
    
    # sysctl -p
    

    redisubuntu9

  8. Now, to fix the second warning, create a new file in the path.

    # vi /etc/rc.local
    


    And paste the code below and save the file and close it.

    #!/bin/bash
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    systemctl restart redis-server.service
    exit 0
    

    redisubuntu10

  9. Finally, fix the permissions of the files.

    # chown root:root /etc/rc.local
    
    # chmod 770 /etc/rc.local
    

    redisubuntu11

  10. Reboot the server and check with the Redis log files once again by the command.

    # tail /var/log/redis/redis-server.log
    


    The output will be like this:

    redisubuntu12

  11. To check the installation whether is successful, give the command.

    # redis-cli
    


    If no errors, the output will be like below:

    redisubuntu13

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.