Redis on Centos

2 Jul

Setup Latest Redis

  • Download and build latest redis
    1. cd /opt/redis
    2. Dowload the latest stable version from http://redis.io
      *

      {info:title=Make Note}

      As of this writing the latest Redis version is 2.2.7. Ensure you are installing the appropriate Redis version before

      proceeding.

      {info}

       

    3. tar xzf redis-2.2.7.tar.gz
    4. cd redis-2.2.7
    5. make
  • Create the “latest version” symlink
    1. cd /opt/redis
    2. ln -s redis-2.2.7 latest
  • Start Redis Server
    1. cd src
    2. ./redis-server

Test CLI interface

  • Open another terminal window to test CLI interface
  1. cd /opt/redis
  2. ./redis-cli -h localhost -p 6379

Setup Redis Service Management

  • Create the file /etc/init.d/redis and enter the script commands below:
    #!/bin/sh
    #
    # redis this script starts and stops the redis daemon
    #
    # chkconfig: - 85 15
    # description: redis is a non-relational database storage system.
    # processname: redis
    # config: /opt/redis/latest/conf
    # binary: /opt/redis/latest/src/redis-server
    
    PATH=/opt/redis/latest/src:$PATH
    NAME=redis
    
    test -x $DAEMON || exit 0
    
    set -e
    
    case "$1" in
      start)
            echo -n "Starting Redis... \n"
            echo  "\n"
             /opt/redis/latest/src/redis-server &> /dev/null &
            RETVAL=$?
            echo
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/redis
            ;;
    stop)
            echo -n "Stopping Redis... \n"
            echo  "\n"
            #killall -q /opt/redis/latest/src/redis-server
            /opt/redis/latest/src/redis-cli -p 6379 shutdown
            RETVAL=$?
            echo
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/redis
            ;;
          *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop}" >&2
                exit 1
                ;;
        esac

     

  • chmod +x /etc/init.d/redis
  • chkconfig –add redis
  • chkconfig redis on
  • service redis stop
  • service redis start
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: