Redis is a highly optimized, in-memory data store known for its exceptional performance, making it a popular choice for use cases such as caching, real-time analytics, session management, and message brokering. Redis supports a variety of complex data structures, including strings, hashes, lists, and sets, which allows it to handle diverse workloads with minimal latency. Additionally, Redis is designed to operate with persistence, meaning it can store data on disk, which is crucial for applications requiring data durability. With features like Lua scripting, built-in replication, and high availability with Redis Sentinel, Redis provides a robust solution for modern applications requiring scalable, reliable, and high-speed data management.
On Fedora 40 or 39, Redis can be installed using Fedora’s AppStream, which offers a stable version suitable for most users. For those who need access to the latest features and improvements, the Remi RPM repository provides Redis versions 6.0, 6.2, 7.0, and 7.2, allowing you to select the version that best matches your performance and compatibility needs. This guide will explain how to install Redis using both methods, ensuring you have the optimal setup for your Fedora system.
Method 1: Install Redis via Default Appstream
Update Fedora Before Redis Installation
To ensure a smooth Redis installation, it’s crucial to start by updating your Fedora system. This step helps prevent conflicts by aligning your system’s packages with the latest updates.
Execute the following command in your terminal to update your system:
sudo dnf upgrade --refresh
This command refreshes the repository metadata and upgrades all your system’s packages to their latest versions. It’s a good practice to perform this step before installing any new software to maintain system integrity and security.
Install Redis via DNF Command
Fedora’s default repository typically includes the most recent version of Redis. This availability makes the installation process straightforward and reliable.
To install Redis on your Fedora system, use the command below:
sudo dnf install redis
This command will download and install Redis and any required dependencies from the Fedora repository. It’s important to note that the version available in the Fedora repository might not always be the absolute latest released by the Redis developers. However, it is usually updated and stable, making it suitable for most applications.
Method 2: Install Redis via Remi RPM
Import Remi RPM for Redis
Using the Remi RPM repository is a reliable alternative for installing the latest or specific long-term supported versions of Redis on Fedora Linux. This method is more straightforward than Red Hat Enterprise Linux (RHEL) and its derivatives, as it does not require the preliminary installation of Extra Packages for Enterprise Linux (EPEL).
Selecting the correct version of the Remi repository that matches your Fedora version is crucial to ensure compatibility.
Use one of the following commands based on your Fedora version:
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-40.rpm -y
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-39.rpm -y
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-38.rpm -y
These commands add the Remi repository to your system, paving the way for installing the desired version of Redis.
List Redis Modules from Remi RPM
With the Remi repository integrated into your system, you can explore the available Redis versions. To view the list of Redis modules offered in the Remi repository, execute the following command:
sudo dnf module list redis:remi*
This command displays various versions of Redis that are available for installation, allowing you to choose the one that best suits your needs.
Enable Redis-Specific Version
After identifying the desired Redis version from the list, the next step is to enable that specific version. Use the command below, replacing {version} with your chosen version number:
sudo dnf module enable redis:remi-{version}
For example, to enable Redis version 7.2, the command would be:
sudo dnf module enable redis:remi-7.2 -y
This command sets your system to install the selected Redis version from the Remi repository.
Install Redis via DNF Command from Remi RPM
Once the desired Redis module is enabled, you can install it. To install the specified version of Redis or to update an existing installation to the newest version available in the Remi repository, use the following:
sudo dnf install redis
This command ensures your selected Redis version is installed on your Fedora system, leveraging the Remi RPM repository’s offerings.
Enable Redis Service
Starting and Enabling Redis Service
To ensure Redis runs automatically at system startup, start and enable the Redis service using the following command:
sudo systemctl enable redis --now
This command starts Redis immediately and sets it to launch on boot, ensuring Redis is always available when your system is running.
Verifying Redis Service Status
After starting Redis, confirming that the service is operational and error-free is essential. Check the status of the Redis service with:
systemctl status redis
This check provides insights into the service’s current state, including whether it’s active and running without issues.
Confirming Redis Listening Port
Redis typically listens on localhost, port 6379, by default. To verify this, execute the following command:
ps -ef | grep redis
Expected output:
redis 2969 1 0 11:17 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379 joshua 3175 3095 0 11:19 pts/0 00:00:00 grep --color=auto redis
This output confirms that Redis is running and listening on the correct port.
Performing a Ping Test
To test the connectivity to your Redis service, initiate a ping test. First, connect to the Redis CLI with:
redis-cli
Once connected, the terminal will show (127.0.0.1:6379). Then, ping the Redis service:
ping
Expected output:
PONG
This simple test ensures that the Redis service is responsive and functional.
Retrieving Redis Server Information
For detailed information about the Redis server, use the INFO command. To focus on specific details, such as server information, use:
INFO SERVER
This command comprehensively overviews the Redis server’s current configuration and status.
Exiting the Redis CLI
Once you’ve completed your checks or configurations, exit the Redis instance with the command:
exit
Examples to Configure Redis
Configuring Redis for Caching
Redis is often used for caching and enhancing web application performance. Begin by opening the Redis configuration file with the following:
sudo nano /etc/redis/redis.conf
This file, located at /etc/redis/redis.conf, contains settings crucial for customizing Redis behavior.
Configure Max Memory
Add these lines at the end of the file to allocate memory for Redis. Adjust the memory value according to your server’s capacity and your application’s requirements.
maxmemory 500mb
maxmemory-policy allkeys-lru
In this example, Redis is configured to use 500MB of memory. This setting is suitable for a server with ample RAM. The maxmemory-policy allkeys-lru directive specifies that when the maximum memory is reached, Redis will remove keys following the Least Recently Used (LRU) algorithm, optimizing memory usage.
Configure Network Access
Redis allows network access to be configured for different scenarios.
Listening to All Network Interfaces
To make Redis listen on all network interfaces, comment out the bind line (line 69) in the configuration file:
# bind 127.0.0.1 ::1
Alternatively, explicitly bind to all interfaces:
bind 0.0.0.0/0
Ensure robust internal network security when using this configuration.
Binding to a Specific IP Address
For a more secure setup, bind Redis to a specific, static IP address:
bind 192.150.5.2
Binding to a Network Subnet
To bind Redis to a subnet:
bind 192.150.5.0/24
It is highly recommended that Redis be secured with a password, primarily when binding to broader network interfaces or subnets.
Configure Password for Security
Securing your Redis instance with a password adds layer of protection.
Navigate to line 507 and uncomment the “requiredpass” line, setting a strong password:
requiredpass APASSWORD
Choose a robust password with a mix of numbers, letters, special symbols, and capitals to prevent brute-force attacks.
Accessing Redis with a Password
When accessing Redis with Redis-CLI, use the command:
auth THEPASSWORDSET
Replace “THEPASSWORDSET” with the password you set.
Users attempting to access without the correct password will encounter an error:
(error) NOAUTH Authentication required.
A successful login will display:
OK
Configuring Snapshotting (RDB)
For regular snapshotting, which saves the dataset at specified intervals, adjust these settings:
save 900 1
save 300 10
save 60 10000
In this configuration, Redis will save the dataset:
- Every 900 seconds if at least 1 key changed.
- Every 300 seconds if at least 10 keys changed.
- Every 60 seconds if at least 10000 keys changed.
This method is effective for balancing data safety and performance.
Enabling Append Only File (AOF)
To enhance data durability with AOF, which logs every write operation, add:
appendonly yes
This setting turns on AOF, ensuring every change to your data is stored immediately. This method provides a higher level of data safety, as it allows recovery from the most recent write operation.
Setting Log Levels
Configuring the log level helps in monitoring and troubleshooting:
loglevel notice
Options include:
- debug: Extensive logging, useful for development.
- verbose: Fairly detailed, but less than debug.
- notice: Moderately detailed, suitable for production.
- warning: Only logs warnings and errors.
Configuring Eviction Policies
To manage memory more efficiently, set an eviction policy:
maxmemory-policy volatile-lru
Options include:
- volatile-lru: Evicts the least recently used keys out of all keys with an expiry set.
- allkeys-lru: Evicts any least recently used key, regardless of expiry.
- volatile-random: Randomly evicts keys with an expiry set.
- allkeys-random: Randomly evicts keys regardless of expiry.
- volatile-ttl: Evicts keys with the shortest remaining time to live.
- noeviction: Returns an error when the memory limit is reached.
Securing Redis with TLS
To enable TLS for encrypted connections:
tls-port 6379
tls-cert-file /path/to/cert.pem
tls-key-file /path/to/privkey.pem
Replace /path/to/cert.pem and /path/to/privkey.pem with the actual paths to your TLS certificate and private key. This setup enhances security, especially when Redis is accessible over a network.
Adjusting Database Numbers
You can specify the number of databases Redis uses:
databases 16
This setting, for example, configures Redis to use 16 databases numbered from 0 to 15.
Saving Changes and Restarting Redis
After configuring Redis, save your changes (CTRL+O) and exit the editor (CTRL+X). To apply these changes, restart the Redis service:
sudo systemctl restart redis
This restart ensures that all your configuration changes take effect, securing and optimizing your Redis instance.
Configure Firewall for Redis
Setting Up a Dedicated Firewalld Zone for Redis
For enhanced security, it’s crucial to establish specific firewall rules for Redis. Initially, there were no default rules set for Redis in Fedora’s firewall. Setting up these rules is vital to prevent unauthorized access and potential attacks.
Create a new zone dedicated to Redis in firewalld using:
sudo firewall-cmd --permanent --new-zone=redis
This command adds a ‘redis’ zone in firewalld, laying the groundwork for more detailed rules.
Allowing Specific IP Addresses Access to Redis
Next, define which IP addresses are authorized to access Redis. This step is crucial for controlling access and ensuring that only trusted sources can interact with your Redis server.
To add an allowed IP address to the Redis zone, use:
sudo firewall-cmd --permanent --zone=redis --add-source=1.2.3.4
Replace 1.2.3.4 with the actual IP address you wish to permit. This setting ensures that only specified IP addresses can access your Redis installation.
Opening the Redis Port in the Firewall
By default, Redis communicates over TCP port 6379. To enable network communication with Redis, you’ll need to open this port in the firewall.
Use the following command to open the default Redis port:
sudo firewall-cmd --permanent --zone=redis --add-port=6379/tcp
If you’ve changed the default Redis port in your configuration, remember to adjust the port in this command accordingly.
Reloading the Firewall to Apply New Rules
After setting up the rules, reload firewalld to implement the changes:
sudo firewall-cmd --reload
Successful execution of this command should return:
success
Verifying Firewall Rules with Redis
To ensure your firewall configuration is practical, test the connectivity to your Redis service, particularly with the new IP restrictions in place.
Test the connection using:
redis-cli -h <ip address> ping
Replace <ip address> with the allowed IP address. A successful setup will respond with:
pong
This response indicates that your firewall is correctly configured, allowing access to Redis only from specified sources.
Conclusion
To conclude, installing Redis on Fedora via the AppStream repository is a straightforward and stable option for most users. However, if you need access to the latest features and optimizations, the Remi RPM repository is the way to go. Both methods provide reliable integration of Redis into your system, ensuring that your Fedora setup can efficiently handle high-performance data operations. Be sure to keep Redis updated to maintain its efficiency and reliability as a crucial component of your system.
Useful Links
Here are some valuable links related to using Redis:
- Redis Official Website: Visit the official Redis website for information about the in-memory data structure store, features, and download options.
- Redis Documentation: Access comprehensive documentation for detailed guides on installing, configuring, and using Redis.
- Remi’s RPM Repository: Explore Remi’s RPM repository for Redis packages and other related software for Fedora.
- Remi’s RPM Forum: Join Remi’s RPM forum to discuss issues, share solutions, and get support from other users.