Home » REDIS Installation on Linux Server
Databases Redis

REDIS Installation on Linux Server

Redis is an open source(BSD Licensed), advanced key-value store which is the best solution for building high performance and scalable web applications.

Redis supports various data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlog logs, geospatial indexes with radius queries and streams. Redis also supports high availability and built-in replication feature. Here in this article, we will discuss about Redis Installation on Linux servers using Package manager as well as Installing from Source. Before moving to Installation steps, we have to be familiar with a few things about redis.

  • Port 6379 will be the default port for Redis service.
  • Redis configurations are stored in /etc/redis/redis.conf
  • Redis is written in ANSI C and works on most POSIX systems like Linux, *BSD, and Mac OS X, without external dependencies.
  • By default, Redis will store all the data in memory. Redis also supports Redis Persistence, where we can persistently store data.
  • The Official Website for Download: https://redis.io/download

1. Installation using Package Manager

Redis package is not included in the default repositories. So we need to add REMI Repository using the following commands:

sudo yum install -y epel-release yum-utils
sudo yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager — enable remi

Now we are good to install redis using YUM package manager.

sudo yum install -y redis

We have finished installing Redis service. But in order to start and make the service available during server reboots, please execute the following commands as well.

sudo systemctl start redis
sudo systemctl enable redis

These are steps for installing redis using YUM package manager. Now we can go through the steps for installing Redis from source.

2. Installing from Source:

Installing a program “from source” means installing a program without using a package manager. We can compile the source code and copy the binaries to respective path inside the server.

In Linux, a command line program called make helps to automate the building process. Make program automates the entire process of converting the source code written in different languages with specific compilers and commands to the corresponding binaries with the help of makefile. The makefile is the file which has all instructions telling it what to do and compile.

Downloading and Installing Redis from source:

We can find all release versions of redis from releases page.

Step 1: Install and update Dependencies

Upgrade the installed packages to the newest versions and install pre-requisite packages necessary for building Redis.

yum update -y
yum install gcc make wget tcl -y

Step 2: Download source code and compile

Download the Redis archive and extract it under /usr/local/src . Then navigate to the Redis source directory and start compilation process using make command.

cd /usr/local/src
wget http://download.redis.io/releases/redis-7.0.0.tar.gz
tar xzf redis-7.0.0.tar.gz
cd redis-7.0.0
make

After successful compilation, run the make test command to make sure everything was built correctly and last step is to install Redis binaries using the make install command which will install the binaries to specific locations so that they can be accessed. Mostly /usr/local/bin is a common default prefix.

make test
make install 

Step 3: User, Group and Data Directory Creation :

Execute the following command for creating a user and group named “redis” along with a data directory for redis to store redis databases (/var/lib/redis) with appropriate permissions.

groupadd redis
useradd --system --no-create-home -g redis -s /sbin/nologin redis
mkdir -p /var/lib/redis
chown redis: /var/lib/redis
chmod 770 /var/lib/redis

Step 4: Setting up redis configuration

Create a configuration directory /etc/redis and copy the redis.conf from the source directory. Change the supervised directive in redis.conf to “systemd” and dir directive and set it to /var/lib/redis .

mkdir /etc/redis
cp /usr/local/src/redis-7.0.0/redis.conf /etc/redis/
vim /etc/redis/redis.conf

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.

supervised systemd
dir /var/lib/redis

Step 5: Creating a systemd unit file for Redis service

Now, Redis is installed and configured. Our last step is to create a systemd unit file so that we can manage the Redis service as a regular systemd service.

vim /etc/systemd/system/redis.service[Unit]
Description=Redis Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

After creating systemd unit file, we can start and enable the redis service.

systemctl enable redis
systemctl start redis

For verifying the status of redis service, use

systemctl status redis

The output should look like this:

Finally, to verify that the Redis service is functioning correctly, run the following command which will return a PONG:

redis-cli PING

And finally, you now have a working Redis instance that is configured and ready to be used.

You can find the Redis official documentation here!

Please leave your thoughts and comments for this post.

Saludos …………………..! 🙂

Add Comment

Click here to post a comment