Redis is a flexible open-source, key-value data store, used as a database, cache and message broker. Redis allows the user to store vast amounts of data without the limits of a relational database. Redis was designed for use by trusted clients in a trusted environment, and has no robust security features of its own. Redis does, however, have a few security features that include a basic unencrypted password and command renaming and disabling.
This tutorial provides both instructions for deploying the Redis Server, and an overview of best practices for maintaining Redis instances on CentOS 7. Note that this guide does not address situations where the Redis server and the client applications are on different hosts or in different data centers. Let’s get started with the installation of Redis on your CentOS 7 server.
Connect via SSH
Connect to your Linux server via SSH, resynchronize the package index files from their sources and install the newest versions of all packages that are currently installed on your server by using the following commands:
$ sudo yum update
Redis is not available in the default CentOS repositories. We need to install the repo in order to fetch the Redis packages.
$ sudo yum install epel-release
Installing Redis on an CentOS VPS is simple. Run the command below to install Redis on your machine:
$ sudo yum install redis
Now, we are ready to start the Redis server.
Start the Redis Service
Start up the systemd service by typing:
$ sudo systemctl start redis
Optional: To automatically start Redis on boot:
sudo systemctl enable redis
Check that the service had no errors by running:
$ sudo systemctl status redis
You should see something that 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 Sun 2018-03-18 16:34:02 CDT; 23s ago Main PID: 1025 (redis-server) CGroup: /system.slice/redis.service └─1025 /usr/bin/redis-server 127.0.0.1:6379 . . .
Test the Redis Service
Finally, let’s experiment our Redis setup by running:
$ redis-cli ping
This should print a
PONG as the response. If this is the case, you now have Redis running on your server.
Another way to test our setup is with the “redis-benchmark” command used to check redis performances.
Following is the basic syntax of Redis benchmark
$ redis-benchmark [option] [option value]
For more information on running benchmarks for Redis, typing redis-benchmark –help in your terminal will print useful information with examples.
Configure Redis Server
Two important redis server configuration file’s path
We need to check
/etc/redis.conf configuration file and ensure that Redis is bound to the local IP. Unless you are running a full Redis cluster, which is beyond the scope of this tutorial, this is the best way to secure your Redis store from unauthorized access.
Make sure that the following line is added, and if already exists make sure it is uncommented:
Listening Port Of Redis Server
Redis Server listens by default at port number 6379.
PS. If you liked this post, on how to install and configure Redis on CentOS 7, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.