Redis is an open source storage program that stores key-value pair data in memory. It can be used as a database, cache, information temporary storage, and supports various data structures, such as strings, hash values, lists, collections, and so on. Redis provides high availability through the automatic block processing of multiple Redis nodes in Redis Sentinel and Redis clusters.
This guide covers installing and configuring Redis on CentOS 8.
Redis 5.0 is included in the CentOS 8 source repository. To install it, run the following command directly as root or another user with sudo privileges:
sudo dnf install redis-server
Once the installation is complete, enable and start the Redis service:
sudo systemctl enable --now redis
To check whether the Redis server is running, enter:
sudo systemctl status redis
● 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 2020-02-0820:54:46 UTC; 7s ago
that's it. You have installed and running Redis on your CentOS 8 server.
By default, Redis does not allow remote connections. You can only connect to the Redis server from 127.0.0.1 (localhost)-the machine where the Redis server is running.
If you are using a single machine, the database is also on this machine, you do not need to enable remote access.
To configure Redis to accept remote access, open the Redis configuration file with your text editor:
sudo nano /etc/redis.conf
Locate the line starting with bind 127.0.0.1
and add your server's LAN IP address after 127.0.0.1
.
bind 127.0.0.1192.168.121.233
Make sure to replace 192.168.121.233
with your own IP address. Save the file and close the text editor.
If you want Redis to listen to all network interfaces, just comment out this line.
Restart the Redis service to make the application take effect:
sudo systemctl restart redis
Use the following ss
command to verify that the Redis server is listening on port 6379
:
ss -an | grep 6379
You should see a message similar to the following:
tcp LISTEN 0128192.168.121.233:63790.0.0.0:*
tcp LISTEN 0128127.0.0.1:63790.0.0.0:*
Next, you will need to configure your firewall to allow network traffic through TCP port 6379
.
Usually you want to allow access to the Redis server from a specified IP address or a specified IP range. For example, to allow connections from 192.168.121.0/24
, run the following command:
sudo firewall-cmd --new-zone=redis --permanent
sudo firewall-cmd --zone=redis --add-port=6379/tcp --permanent
sudo firewall-cmd --zone=redis --add-source=192.168.121.0/24--permanent
sudo firewall-cmd --reload
The above command creates a zone named redis
, opens the port 6379
and allows access from the LAN.
At this point, the Redis server will accept remote connections from the 6379 TCP port.
Make sure your firewall is configured to only accept access from trusted IP ranges.
To verify that all settings are set up, you can try to use redis-cli
to ping the Redis server from your remote machine.
redis-cli -h <REDIS_IP_ADDRESS> ping
This command will return a response: PONG
PONG
We have shown you how to install Redis on CentOS 8. To learn more about how to use Redis, please visit their Official Documentation Page.
Original: https://linuxize.com/post/how-to-install-and-configure-redis-on-centos-8/
Recommended Posts