Learn how to install Redis on Linux with this simple tutorial. Redis is an open-source database, precisely, it's an in-memory data structure store that can be used as a database, cache & message broker. It does not possess the limits offered by the relational database & can be used to store a vast amount of data, with support for a number of data structures like strings, hashes, lists, sets, sorted sets, bitmaps, hyper logs, etc.

Redis also provides a number of features like built-in replication (master-slave replication), Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence & also provides high availability.

install redis on linux

Typical use cases are session caching, full page cache, message queue applications, leaderboards, and counting among others.

Recommended Read: Installing MEMCACHED in Ubuntu & RHEL/CentOS

Also Read: Install Varnish Cache for Apache Web Server to Speed up Website


Install Redis on Linux


Pre-requisites

Before we can proceed with the installation of Redis on our Centos/RHEL servers, we need to make sure that the following packages must be installed on our systems,

1- CentOS/RHEL 7

We need to install the following packages,

$ yum install wget gcc make

2- CentOS/RHEL6

Install the following packages,

$ yum install tcl wget gcc make


Step 1- Downloading Redis

At the time of writing this tutorial, Redis 6.0.10 is the latest version. So to download the redis 6.0.10, open your terminal & execute the following command,

$ wget https://download.redis.io/releases/redis-6.0.10.tar.gz

Next, we will extract the downloaded tar package,

$ tar -xvf redis-6.0.10.tar.gz


Step 2- Compiling & Installing Redis

Now that we have extracted the package, we will compile & install Redis. Firstly, open the extracted folder,

$ cd redis-6.0.10

& then goto folder 'deps',

$ cd deps

Now, we will compile the packages by executing the following commands,

$ make hiredis lua jemalloc linenoise

$ make geohash-int

Next, we will move back to the main directory i.e. 'redis-6.0.10'

$ cd ../

& will run 'make' & 'make install' commands

$ make

$ make installation

Once these commands have been executed, we will move onto to installing the 'init' script.


Step 3- Installing init scripting

Init script will setup a redis service with port number, config file, log file & a data directory. To run run init script,

$ cd utils\

& run the install_server.sh script,

$ ./install_server.sh

We will now be asked with some information regarding redis server, as shown below,

Welcome to the redis service installer

This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]

Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]

Selected default - /etc/redis/6379.conf

Please select the redis log file name [/var/log/redis_6379.log]

Selected default - /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]

Selected default - /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]

Selected config:

Port : 6379

Config file : /etc/redis/6379.conf

Log file : /var/log/redis_6379.log

Data dir : /var/lib/redis/6379

Executable : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/6379.conf => /etc/init.d/redis_6379

Installing service...

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server...

Installation successful!

For this installation, we have used all the default settings, but we can modify any settings as per our need.

Note:- We can also set up a number of redis instances by running this script again & changing the port number for the new redis instance.


Step 4- Starting the Redis service

To start the Redis service, the command is

$ service redis_6379 start

OR, run,

$ systemctl start redis_6379

If you are using more than one redis instance or have changed the port number for redis instance, then you can replace 6379 with the port number you have chosen to stop/start the redis service.


Step 5- Checking if the Redis service is working

To login to redis server & check if redis is working fine, open the terminal & run the command,

$ redis-cli

Once connected, you will get prompt like

127.0.0.1:6379>

We can now issue 'Ping' command & if the redis service is up, we will get 'PONG ' as a response,

127.0.0.1:6379> ping

PONG


Step 6 (OPTIONAL) Accessing redis from the remote system

By default, redis is accessible from localhost but if you wish to access redis server from a remote location then we need to make some changes in the configuration file. Open the configuration file for the instance, i.e. /etc/6379.conf,

$ vi /etc/redis/6379.conf

& look for 'bind 127.0.0.1'. We can either replace 127.0.0.1 with 0.0.0.0 or add IP address of our server to it. It should look like

bind 0.0.0.0

or

bind 127.0.0.1 192.168.1.100

Now exit the file after saving the changes & restart the service for changes to take effect.

$ service redis_6379 restart

Remember if using multiple or different port numbers, changes are to made to all the configuration files for respective port numbers.

Now to check if we can log in to redis from a remote system, log in to remote system first & enter the following command from the terminal,

$ redis-cli -h 192.168.1.100 -p 6379

where 192.168.1.100 is the IP address of the Redis server with 6379 as the Redis instance port number.

This completes our tutorial on how to install Redis on Linux. For any queries or questions, you are most welcome to contact us using the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.