Introduction
Redis is an in-memory data store used as a database, cache, and message broker. It supports various data structures like strings, hashes, lists, and sets. Known for high performance and scalability, Redis handles real-time tasks efficiently, making it ideal for applications like session management, caching, and real-time analytics.
This guide shows you how to install and configure Redis on Rocky Linux 9.
Prerequisites
Before you begin, ensure you have the following:
- A Rocky Linux 9 server. We recommend a Digital Ocean VPS server.
- A non-root user with sudo privileges.
Update System Packages
Update your system packages to get the latest versions from the repositories. This step ensures applications' security, performance, and compatibility.
-
Update your system's package information index index.
CONSOLE$ sudo dnf update -y
-
Install the
epel-release
package for additional software repositories.CONSOLE$ sudo dnf install epel-release -y
-
Install Redis package.
CONSOLE$ sudo dnf install redis -y
-
Check the Redis version.
CONSOLE$ redis-cli --version
Manage Redis Service
This section explains how to manage the Redis service using systemctl
.
-
Start the Redis service.
CONSOLE$ sudo systemctl start redis
-
Enable the Redis service to start at boot.
CONSOLE$ sudo systemctl enable redis
-
Stop the Redis service.
CONSOLE$ sudo systemctl restart redis
-
Start the Redis service.
CONSOLE$ sudo systemctl start redis
-
Check the status of the Redis service.
CONSOLE$ sudo systemctl status redis
Secure Redis Server with a Password
For added security, configure Redis to require a password.
-
Open the Redis configuration file.
CONSOLE$ sudo nano /etc/redis.conf
-
Find the line that begins with
# requirepass
.INI# requirepass
-
Uncomment it by removing the
#
symbol and set a strong password.INIrequirepass your_secure_password
-
Save the file and exit the text editor.
-
Restart Redis to apply the changes.
CONSOLE$ sudo systemctl restart redis
Understand Redis Directory Structure
This section explains the Redis directory structure, configuration files, error files, and log files.
-
Redis main configuration file.
/etc/redis.conf
-
Redis data directory.
/var/lib/redis
-
Redis Log files.
/var/log/redis
-
Redis error logs.
/var/log/redis/redis.log
Test the Redis Server
This section shows you how to log in to the Redis server, set a key, and retrieve the key.
-
Connect to the Redis server using the Redis CLI.
CONSOLE$ redis-cli
-
Authenticate to the Redis server and enter the password you set earlier.
CONSOLEauth your_secure_password
-
Set a sample
test
key and sethello
as the value.CONSOLEset example hello
-
Retrieve the value of the
test
key.CONSOLEget test
Conclusion
You have successfully installed and configured Redis on Rocky Linux 9. You learned how to update system packages, install Redis, manage the Redis service using systemctl
, secure the Redis server with a password, understand the Redis directory structure, and log in to the Redis server to set and retrieve keys. With Redis up and running, you can now explore its various features and capabilities to enhance your applications.