How To Install Redis and Configure Multiple Redis Server on Centos 7

What is Redis

You are reading this post, I assume you already have a bit idea what is Redis. But just a short introduction: Redis is an open source in-memory database. It supports basic data type like strings as well as advanced data structures like lists and hashes.Redis is very simple to setup and use. Below is simple instruction on how to install and configure Redis on CentOS 7.

Redis official documentation here

Installation

Run the command below to stall Redis server on Centos.

If you are running into an error saying “no package available”, make sure you have repo epel installed and enabled because redis is a part of epel on Centos.
You can use the command below to list all the enabled repos:

If you don’t see the epel repo in the list, try the command below to enable it.

or install it

Start the Redis Server

Now you can start Redis server and enable to auto-start on system reboot by using the commands below.

By default, Redis server listens on 6379 port, and you can run commands below to check if it is alive.

Install and Run Multiple Instance of Redis on Centos

Sometimes you will need multiple Redis instances, for example I was configuring a server for Magento 2 hosting, and I need 1 server for page cache, 1 for config cache, 1 for session storage.

You can run multiple Redis instances on different ports. By default Redis is installed under /var/lib/redis. This is considered as the work space for the default Redis insane. Memory dump is stored here. You will see a file named dump.rdb if there is any data dumped from memory.

First, to setup another Redis instance, we will need to duplicate the directory for a new instance. You can do so by running the commands below:

Second, we will need to create a separate configuration file. The default config file is /etc/redis.conf

And update configuration in the file to let the new instance run on different ports.

Lines need to be updated:

As you can see above, this time we are using port 6380 to host the new instance.
Then create separate service file for Centos.

Lines need to be updated in the new service file

Now it is time to start the new instance and enable to auto-start on system reboot just like what we did when we install the first instance.

Check the status or our second instance:

Now we have 2 Redis servers running separately on porst 6379 and 6380.

Linux How to Use du Command to List Files, Directories, and their total sizes

We know we can use ls command to list out all the files and directories under a given directory.

But it doesn’t give us size information. Sometimes, size information is important, for example we are examining a code repository, and need to find out and clean up large files and directories.

Linux List Files, Directories, and Their Total Sizes

du command, short for disk usage, can be useful in case like this. It is used to estimate file space usage.
To list all files, directories, and their total sizes, first cd to the directory, and run the command below.

It will give us an output like below:

List Files, Directories, and their total sizes

Linux List Total Size of Current Directory

To simply list the size of current directory, first cd to the directory, and run the command below.

It will calculate the current directory size:

Linux List Total Size of Current Directory

Linux List Files, Directories, and Their Total Sizes in Descending Order

We’ve already known how to list the size for all files and directories in a certain directory, but can we take one more step further to sort the results.

Then answer is YES! See the command below:

We will need to drop the -h argument, since it will give you human readable output, e.g. 10K, 2.5MB, and they cannot be sorted when we pipe the output to sort command.

Linux List Files, Directories, and Their Total Sizes in Descending Order

Linux Find the Top 10 Largest Files or Directories in Current Directory

We can pass the output from previous command to a head command to accomplish this.

Linux List the Top 10 Largest Files or Directories