
Redis® is a fast in-memory database popularly used for caching, processing queues in message-broker applications, displaying analytics data in leaderboards, and more. Unlike relational databases that use structured tables and SQL queries, Redis® is a key-value store that supports a variety of data structures with high-performance features for real-time applications.
This article explains how to install Redis® on Debian 12.
Before you begin:
Redis® is available in the default Debian 12 package repositories. You can also install a specific version using the official PPA repository or by compiling the version directly from source code. Follow the steps below to install Redis® using the APT package manager.
Update the server's package information index.
Install Redis®.
View the installed Redis® version.
Your output should be similar to the one below.
After installing Redis®, the package starts automatically and listens for connections on the localhost port 6379 by default. Follow the steps below to configure the listening port, address, and system service preferences using the main Redis® configuration file.
Open the default Redis® configuration file using a text editor such as nano.
Find the bind directive and verify that the value is set to 127.0.0.1 -::1. This instructs Redis® to only accept internal server connections.
Find the port directive value and verify that it's set to the default port 6379 or modify it based on your needs.
Find the daemonize directive and verify that it's set to yes to enable Redis® to run as a system service.
Save and close the file.
In addition, configure the following directives to set Redis® memory requirements and database limits.
maxmemory: Defines the maximum amount of memory Redis® can use. When Redis® reaches this limit, it evicts keys based on the eviction policy.appendonly: Instructs Redis® to log every write operation received in an append-only file (AOF) when set to yes to enable data durability.appendfilename: Defines the name of the AOF file.logfile: Sets the path to the Redis® log file.databases: Sets the number of Redis® databases to support on the server. By default, 16 databases.requirepass: Sets a password to connect to the Redis® server. Clients need to authenticate using this password when enabled.include: Enables additional configuration files.Restart the Redis® service to apply changes.
Redis® does not require authentication by default, but this setting gives elevated privileges to any connected client. Follow the steps below to enable authentication, create standard users, and disable dangerous Redis® commands for specific user categories on your server.
Open the Redis® configuration file.
Find the requirepass directive.
Uncomment the directive and replace foobared with a strong password for the default user.
Add a user directive to create a new db_client user and disable dangerous Redis® commands. Replace strong_password with your desired password.
The above directive defines a new user with specific permissions, pattern-based key access, and a password with the following details:
user db_client: Specifies a username of the account that can access the redis-cli console.on: Enables the user.+@all: Grants the user access to all commands.-@dangerous: Revokes the user's access to all dangerous commands that can modify the data set, configurations, or the server state in ways that can be harmful. For example, FLUSHALL, FLUSHDB, and SHUTDOWN.~*: Grants the user access to all keys on the server.>strong_password: Modifies the user's password.The new Redis® configuration section should look like the one below.
Save and close the file.
Restart the Redis® service to apply the configuration changes.
Redis® includes the redis-cli utility, a command-line interface (CLI) that allows you to send commands to the Redis® server and read replies. Follow the steps below to use the redis-cli utility.
Access the Redis® CLI.
Ping the database without authentication.
The command should fail with the following message:
Authenticate to the Redis® database server as the default user using the password you set earlier. Replace strong_password with the actual password you set in the configuration.
Your output should look like the one below when successful.
Switch to the db_client standard user account you created earlier. Replace strong_password with the actual user password you set in the configuration.
Output:
Ping the database again.
Your output should look like the one below when successful.
Create a new hello key and set the value to Greetings from Vultr!.
Retrieve the hello key value from the database.
Output:
Test a dangerous command with the db_client user such as FLUSHALL that deletes all keys in existing databases.
The dangerous command should fail with the following output:
Exit from Redis® CLI.
You have installed and configured the Redis® on Debian 12 and enabled secure authentication for all database users. In addition, you've created a standard user and limited user privileges to secure the database server. For more information and configuration options, visit the Redis® documentation.
0 Comments
Be the first to comment and share your perspective with the community.