How to install REDIS in LInux
Last updated on March 12th, 2018 at 08:36 pm
Redis is open source database, precisely, it’s a 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, hyperloglogs 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.
Typical use cases are session caching, full page cache, message queue applications, leaderboards and counting among others.
Before we can proceed with the installation of redis on our Centos/RHEL servers, we need to make sure that following packages must be installed on our systems,
1- CentOS/RHEL 7
We need to install the following packages,
$ yum install wget gcc make
Install the following packages ,
$ yum install tcl wget gcc make
Step 1- Downloading redis
At the time of writing this tutorial, redis 3.2.9 is the latest version. So to download the redis 3.2.9, open your terminal & execute the following command,
$ wget http://download.redis.io/releases/redis-3.2.9.tar.gz
Next, we will extract the downloaded tar package,
$ tar -xvf redis-3.2.9.tar.gz
Step 2- Compiling & installing redis
Now that we have a extracted, we will compile & install redis. Firstly, open the extracted folder,
$ cd redis-3.2.9
& then goto folder ‘deps’,
$ cd deps
Now, we will compile the packages by executing following commands,
$ make hiredis lua jemalloc linenoise
$ make geohash-int
Next, we will move back to the main directory i.e. ‘redis-3.2.9’
$ cd ../
& will run ‘make’ & ‘make install’ commands
$ make installation
Once these commands have been executed, we will move onto to installing 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,
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: 
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]
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
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
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 ,
$ 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 terminal & run the command,
Once connected, you will get prompt like
We can now issue ‘Ping’ command & if the redis service is up, we will get ‘PONG ‘ as response,
Step 6 (OPTIONAL) Accessing redis from 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 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 login to redis from a remote system, login to remote system first & enter the following command from 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 redis installation. For any queries or questions , you are most welcome to contact us using the comment box below.