
Redis® (Remote Dictionary Server) is an open-source, in-memory key-value store that functions as a database, cache, or message broker. It integrates with modern web applications to improve performance and reduce server load by storing frequent queries in memory.
This article explains how to install Redis® on Ubuntu 22.04 and access the database to integrate it with other applications on your server.s
Before you begin:
Have an Ubuntu 22.04 server.
Access the server using SSH as a non-root user with sudo privileges.s
Redis® is available in the default package repositories on Ubuntu 22.04. Follow the steps below to install the latest Redis® package on your server.
Update the server's package index.
Install Redis®.
View the installed Redis® version on your server.
Output.
Redis® listens for connections on the default localhost port 6379. In the following steps, configure Redis® to increase the database limit and restrict connections to the 127.0.0.1 localhost address.
Open the main Redis® configuration file using a text editor such as nano.
Find the following bind directive and verify that your localhost IPV4 127.0.0.1 and IPV6 ::1 values are available.
Find the port directive and verify the default Redis® port or modify it to a custom TCP port available on your server.
Find the following daemonize directive and verify that it's set to yes to enable the Redis® service on your server.
Save and close the file.
Enable the Redis® server to automatically start at boot time.
Start the Redis® service.
View the Redis® server status and verify it's running.
By default, Redis® does not require authentication, allowing unrestricted access to its databases. Follow the steps below to enable authentication and secure your Redis® server for authorized user access only.
Open the main Redis® configuration file.
Find the following requirepass directive, uncomment it, and replace foobared with a strong password of your choice.
Save and close the file.
The above configuration secures your Redis® server by enabling password authentication. To allow multiple users with unique passwords, uncomment the aclfile directive.
Restart the Redis® server to apply your configuration changes.
The Redis® server accepts connections via the redis-cli utility or compatible application modules. Follow the steps below to test access by writing sample data to the default database and verify your server configurations.
Connect to the Redis® server.
Test access to the server without authentication.
Verify that your request fails with the following output:
Log in to the Redis® server using a valid password set in your configuration. Replace strong-password with the actual password you set earlier.
Output:
Test access to the database server again.
Output:
Select a database to use on your server. For example 1.
Create a new sample key testkey with a value such as Greetings from Vultr!.
Output:
Query the key value from the database.
Output.
Exit the Redis® CLI.
In this article, you installed Redis® on your Ubuntu 22.04 server and configured it for secure connections. You can now integrate Redis® with your web applications to serve as a database or cache, enhancing both application and server performance.
0 Comments
Be the first to comment and share your perspective with the community.