How Install Redis on CentOS 8

Install Redis on CentOS 8
Redis is a in memory key-value data structure store mainly used as a database, message broker or as a cache. Redis supports wide languages with flexibility and high performance. It supports different data structures like strings, lists, sets, maps, spatial indexes, and bitmaps. In this tutorial, you are going to learn How to Install Redis on CentOS 8.
Prerequisites
Before you start to install Redis on CentOS 8. You must have a non-root user account on your server with sudo privileges and IPv6 should be enabled on your server otherwise Redis service won’t start.
Install Redis
Update dnf package manager index by typing following command:
sudo dnf update
To install Redis run below command:
sudo dnf install redis
After installing Redis, it will not start automatically so to start redis service run below command:
sudo systemctl start redis
And enable Redis service so it will automatically start after boot running below command:
sudo systemctl enable redis
Check the status of Redis service by running below command:
sudo systemctl status redis-server
The output should look like:
● 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
Binding Redis
By default, you can not access Redis from another host because its by default bound to localhost
only. To confirm its bound to localhost(127.0.0.1), follow below instructions:
First, run below command and open Redis configuration file:
sudo nano /etc/redis.conf
Now uncomment bind 127.0.0.1
line by removing #
from the beginning. Now it’s bound to localhost only.
bind 127.0.0.1
If you want to access Redis from remote host then you can replace YOUR_IP_ADDRESS
with your servers IP Address:
bind 127.0.0.1 YOUR_IP_ADDRESS
Now save the and close it by pressing CTRL+x
.
To take changes effect, restart Redis server by running below command:
sudo systemctl restart redis-server
Now run below command to confirm 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, we will setup FirewallD for accessing Redis from a remote host:
Create a zone names redis by using below command:
sudo firewall-cmd --new-zone=redis --permanent
Now open port 6379 permanently using below command:
sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
Run the following command by replacing YOUR_CLIENT_IP_ADDRESS
with IP Address of the machine from which you want to access Redis:
sudo firewall-cmd --zone=redis --add-source=YOUR_CLIENT_IP_ADDRESS --permanent
Finally, reload FirewallD to tale changes effect:
sudo firewall-cmd --reload
Now to check everything is ok, start redis-cli
using below command:
redis-cli
Above command will start redis-cli
shell. So to check everything works fine run below command:
ping
You should see exact below output:
PONG
Exit the redis-cli shell using below command:
exit
Testing Using redis-client
To start testing Redis, run redis-cli
using below command:
redis-cli
It will open redis-cli shell, Now store a value with the key myname
with value John
run below command inside it:
set myname "John"
The output should be:
OK
Now run below command to check the value of myname
:
get myname
You should see the following output:
John
Exit the redis-cli
shell using below command:
exit
Conclusion
You have successfully learned how to install Redis on CentOS 8. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to Install Anaconda on Linux Mint 19
-
How to Set Up Cron Job on CentOS 8
-
How to Add User to Group in Linux
-
How to Install Git on CentOS 8
-
How to Install PhpStorm on CentOS 8
-
How to Install Google Chrome on CentOS 8
-
Secure Nginx with Let’s Encrypt SSL on Ubuntu 18.04
-
How to Install WebStorm on Debian 10
-
How to Reboot Linux System with Command Line
-
How to Install Opera Browser on CentOS 7
-
How to Install MariaDB 10 on CentOS 7
-
How to Install PHP 7.2 on Debian 10