Redis is quickly becoming an industry standard for an in-memory data structure store due to its open-source design, comprehensive list of supported data structures, and scalability through automated partitioning across nodes. The following tutorial will teach you how to install Redis on a Fedora Linux workstation or server using the terminal command line and some basic setup instructions to get you started using the command line terminal.
Table of Contents
Before installing Redis, start by ensuring the packages on your system are up-to-date to avoid any conflicts during the installation using the following command.
sudo dnf upgrade --refresh
The Fedora repository, by default, contains most times the latest version of Redis, making the installation straightforward.
Use the following command to install.
sudo dnf install redis -y
Now, start and enable the Redis service on the system boot.
sudo systemctl enable redis --now
Next, verify the status and make sure Redis is running and, more importantly, with no errors.
systemctl status redis
Note that Reddis actively listens to localhost on the default port 6379. To confirm this type, the following:
ps -ef | grep redis
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
While testing, everything is working and operational, connecting to your Redis service is good, and then performing a ping test.
To perform the test, enter the following command:
Once connected, your terminal will display (127.0.0.1:6379). Now ping the Redis service as follows:
You can also find the general information using the INFO command.
The list is long, so ideally, you would use specifics such as the example blowing printing the info on the Redis server.
Type the following to exit the Redis instance.
How to Configure Redis
Redis can be configured in a few ways. The most notable action of why people use Redis is for caching purposes. To do this, you need to open the “/etc/redis/redis.conf” file using the nano editor.
sudo nano /etc/redis.conf
Configure Max Memory
Now, add the following to the end of the file. Note that you can change the memory value to whatever you like or, more importantly, optimal for your web application and server hardware.
maxmemory 500mb maxmemory-policy allkeys-lru
As you can see, the setting in the guide has 500MB dedicated to Redis, as it is on a dedicated host with lots of RAM to spare. Once the 500MB is exhausted, Redis removes any key as per the LRU algorithm.
Configure Network Access
Another option is to listen to all services or set an IP address/subnet if you like your Redis service.
First, find line 69 in the configuration file.
First, to listen to all network interfaces, Comment “#” the line bind to IP.
# bind 127.0.0.1 ::1
Ensure your internal network is trustworthy and has appropriate security controls.
To bind to an IP address, make sure it is a static IP address.
To bind a network subnet.
Note that it is highly suggested to set a password when using a subnet or to access all interfaces to listen to.
Another security feature to further harden Redis is to set a password on the Redis instance.
Navigate to line 507, uncomment the “# requiredpass” line, and set a password.
Make sure this password is robust, with randomized numbers, letters, special symbols, and capitals, as Redis servers can be brute forced on a decent box.
Next, when invoking the Redis-CLI, use the following command with the password that was set for the user.
“THEPASSWORDSET” is the password that was created.
Users who fail to log in will see the following error message.
(error) NOAUTH Authentication required.
When a user successfully logs in, they will see the following message.
Once done, save your changes CTRL+O then exit CTRL+X. Now restart the Redis service by typing:
sudo systemctl restart redis-server
Configure Firewalld for Redis
By default, no rules are set up for Redis. This means you will need to create allow rules which are essential to stop attacks on Redis, failure to secure Redis will lead to issues down the track, so do not skip this unless you have other means to protect your Redis installation.
First, add a new dedicated zone for Redis firewalld policy.
sudo firewall-cmd --permanent --new-zone=redis
Next, specify the allowed IP addresses permitted to access the Redis.
sudo firewall-cmd --permanent --zone=redis --add-source=22.214.171.124
Replace 126.96.36.199 with the IP address that will be added to the allow list.
Once you have finished adding the IP addresses, open the port of the Redis. By default, this is TCP port 6379.
sudo firewall-cmd --permanent --zone=redis --add-port=6379/tcp
Note that you can change the default port in your configuration file if you change the firewall port open rule above to the new value.
After running those commands, reload the firewall to implement the new rules.
sudo firewall-cmd --reload
Example output if successful:
Now, as you tested at the start of the guide by pinging your Redis service to ensure it was operational, you can try the firewall rules and changes in IP by using the “redis-cli” command.
redis-cli -h <ip address> ping
If setup correctly, the output should be:
How to Remove (Uninstall) Redis
When you need to remove Redis, use the following command.
sudo dnf remove redis
The guide taught you how to install Redis on Fedora Linux using its default repositories through the DNF package manager. You have learned how to test the service by pinging it and changing the memory limit and network interface to suit various setups.
To find more information about managing your Redis installation, visit the Redis documentation page.