How to install Redis on CentOS 8
Install Redis on CentOS 8
Redis is an in-memory key-value data structure store used primarily as a database, message broker, or cache. Redis supports a wide range of languages with flexibility and high performance. It supports various data structures, such as strings, lists, sets, maps, spatial indexes, and bitmaps. In this tutorial, you will learn how to install Redis on CentOS 8.
Prerequisites
Before you start installing Redis on CentOS 8, you need a non-root user account on the server with sudo privileges and enable IPv6 on the server. Otherwise, the Redis service will not start.
Install Redis
Update the dnf package manager index by entering the following command:
sudo dnf update
To install Redis, execute the following command.
sudo dnf install redis
After installing Redis, the Redis service is not started automatically, so execute the following command to start the redis service.
sudo systemctl start redis
Then, enable the Redis service so that it will start automatically when you run the following command after startup.
sudo systemctl enable redis
Execute the following command to check the status of the Redis service.
sudo systemctl status redis-server
The output looks like this:
● redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: active (running) since Sat 2019-12-21 15:12:03 PST; 39s ago Main PID: 2157 (redis-server) CGroup: /system.slice/redis.service └─2157 /usr/bin/redis-server 127.0.0.1:6379
Redis Binding
By default, Redis is not accessible from another host because it is bound by default localhost
only. To check the binding to localhost (127.0.0.1), follow these steps:
First, execute the following command to open the Redis configuration file.
sudo nano /etc/redis.conf
Uncomment now bind 127.0.0.1
Line by removing #
From the beginning. Currently bound only to localhost.
bind 127.0.0.1
If you access Redis from a remote host, you can replace it YOUR_IP_ADDRESS
Server IP address:
bind 127.0.0.1 YOUR_IP_ADDRESS
Save and close CTRL+x
.
For the changes to take effect, restart the Redis server by running the following command:
sudo systemctl restart redis-server
Run the following command to confirm the above changes:
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 14222/redis-server tcp6 0 0 153.168.93.106:6379 *:* LISTEN 14222/redis-server
Next, set up FirewallD to access Redis from a remote host.
Create the zone name redis using the following command.
sudo firewall-cmd --new-zone=redis --permanent
Use the following command to permanently open port 6379:
sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
Replace and run the following command YOUR_CLIENT_IP_ADDRESS
The IP address of the machine accessing Redis:
sudo firewall-cmd --zone=redis --add-source=YOUR_CLIENT_IP_ADDRESS --permanent
Finally, reload FirewallD to see the effect of the change.
sudo firewall-cmd --reload
Now start to make sure everything is fine redis-cli
Use the following command:
redis-cli
The above command is started redis-cli
shell. So, to make sure everything works, run the following command:
ping
The following output is displayed exactly:
PONG
Exit the redis-cli shell using the following command.
exit
Test using redis-client
To start testing Redis, run redis-cli
Use the following command:
redis-cli
redis-cli shell opens and saves value with key myname
Worthwhile John
Execute the following command internally:
set myname "John"
The output looks like this:
OK
Execute the following command to check the value of myname
:
get myname
The following output is displayed.
John
Ends redis-cli
Shell using the following command:
exit
Conclusion
You have learned how to install Redis on CentOS 8. If you have any questions, don’t forget to comment them out.