In this tutorial we are going to learn how to install and configure Redis 6 on Rocky Linux 8 using Ansible. This guide will also work on other RHEL 8 based servers like Oracle Linux and Alma Linux.
Redis is an in-memory data structure store, used as a distributed, in-memory key-value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.
Related Content:
- How to install and configure Redis 6 on Ubuntu 22.04
- Using Ansible to install and configure Redis 6 on Debian 11
- How to install & configure Redis 6 on Rocky Linux/Centos 8
- How to using Ansible to install and configure Redis 6 on Ubuntu 20.04
Prerequisites
To follow along, ensure that you have:
- An updated Rocky Linux 8 server
- Access to the Internet
- Root access to the server or user with sudo access
Ansible tasks to ensure the server is up to date
Before proceeding, let us make sure that the server is up to date using these tasks:
|
|
Enabling the Remi Release repo
The Rocky Linux repos has redis in it’s default repos. But it is not the latest version. We are going to use the Remi repos to get the latest version of redis. Add the remi repo using this task
|
|
Enable the redis version 6 module
Redis is available in different versions. To enable the latest version of redis, we use dnf module enable. This task achieves that.
|
|
Install Redis 6 server
Finally we can install redis.
|
|
We are using dnf to ensure that we have latest redis installed. Since we enabled the module for redis 6.2, that will be installed.
Configuring Redis 6 server
Next we are to configure the server to be production ready.
Add a line to allow the server to write to a pid file
|
|
In the above, we are updating the redis config file to append the line pidfile /var/run/redis/redis-server.pid
so it can write a pid file. We are also setting up a handler to restart the service when the playbook is done executing.
Next, let us set up a password for out redis server to boost security.
|
|
In the above, we are updating the redis config file to append the line requirepass {{ redis_password }}
so it can set the password to be the value set. We are also setting up a handler to restart the service when the playbook is done executing.
Finally, let us bind the service to 0.0.0.0 so it is accessible externally using bind 0.0.0.0
|
|
Setting up the handlers
Let us set up the handlers listed above. Handlers are just like normal tasks in an Ansible playbook but they run only when if the Task contains a notify
directive. It also indicates that it changed something.
|
|
Those handlers will be run after the tasks to restart and enable the service.
The whole playbook to install and set up Redis 6
This is the final playbook. I have the file saved as setup-redis-rocky.yaml
|
|
Creating the hosts file
Create a hosts.yaml
file with this content. Ensure that you can connect to the server added here.
|
|
Running the playbook
You need Ansible installed locally. To install Ansible, you can use the OS package manager or using pip. Use this pip command to install ansible:
|
|
To run the playbook use this command:
|
|
Conclusion
In this guide, we learnt how to use ansible to install and configure Redis 6 in Rocky Linux 8.