Stay on Top with latest happenings: Subscribe Now

How to Install & Configure Redis-Server on Centos/Fedora Server

How to Install & Configure Redis-Server on Centos/Fedora Server

Redis

‘Redis’ is an Open source key-value data store, shared by multiple processes, multiple applications, or multiple Servers. Key values are more complex types like Hashes, Lists, Sets or Sorted Sets.

Let’s have a quick look on the installation steps of “Redis

Here we go…

Step – 1

First of all we need to switch to superuser & install dependencies:

su
yum install make gcc wget tcl

Step-2
Download Redis Packages & Unzip. This guide is based on installing Redis 2.8.3:

wget http://download.redis.io/releases/redis-2.8.3.tar.gz
tar xzvf redis-2.8.3.tar.gz

Step-3
Compiling and Installing Redis from the source:

cd redis-2.8.3
make
make install

Step- 4

Starting Redis server by executing the following command without any argument:

redis-server

Step-5

Check if Redis is working. To check, send a PING command using redis-cli. This will return ‘PONG’ if everything is fine.

redis-cli ping
PONG

Step-6

Add Redis-server to init script. Create a directory to store your Redis config files & data:

mkdir -p /etc/redis
mkdir -p /var/redis

Also we need to create a directory inside “/var/redis” that works as data &  a working directory for this Redis instance.

mkdir /var/redis/redis

Step-7

Copy the template configuration file you’ll find in the root directory of Redis distribution into /etc/redis/

cp redis.conf /etc/redis/redis.conf

Edit the configuration file, make sure to perform the following changes:

  • Set daemonize to yes (by default it’s set to ‘No’).
  • Set the pidfile to /var/run/redis.pid
  • Set your preferred loglevel
  • Set the logfile to /var/log/redis.log
  • Set the dir to /var/redis/redis
  • Save and exit from the editor

Step-8 
Add the Redis init script.

vi /etc/init.d/redis

And paste the following codes to it

#!/bin/sh
#
# chkconfig: 345 20 80
# description: Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker.

# Source function library.
. /etc/init.d/functions

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
            $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
            echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
exit 0

Save the file and exit from the editor.

Step-9
Give appropriate permission to the init script

chmod u+x /etc/init.d/redis

Step-10
To run the Redis server at startup we need to add it to the chkconfig list.

chkconfig --add redis
chkconfig --level 345 redis on

Step-11
Finally we are ready to start the Redis Server.

/etc/init.d/redis start

The redis server will start automatically on system boot.

Conclusion:

‘Redis’ also supports datatypes such as Transitions, Publish and Subscribe. ‘Redis’ is considered more powerful than ‘Memcache’. It would be smart to bring ‘Redis’ into practice and put ‘Memcache’ down for a while.

We provide one-stop solution by utilizing Redis server with Rails , PHP applications and deploy in cloud services such as AWS to make sure that the application is fully scalable.

You can also check the compression of Memcached vs Redis, to know more information on which one to pick for Large web apps?

Do you have anything to add here? Share your thoughts with comments.

It’s always pleasure to hear from you and for5 any assistance and support on AWS you can write us at info@andolasoft.com.

Shares