Installing Redis, Memcached on CentOS 5.7

Redis:

Install

sudo su
yum install make gcc wget telnet
wget -c http://redis.googlecode.com/files/redis-2.6.7.tar.gz
tar zxfv redis-2.6.7.tar.gz
cd redis-2.6.7
make && make install

Config

mkdir -p /etc/redis /mnt/var/lib/redis
sed -e "s/^daemonize no$/daemonize yes/" -e "s/^dir \.\//dir \/mnt\/var\/lib\/redis\//" -e "s/^loglevel debug$/loglevel notice/" -e "s/^logfile stdout$/logfile \/mnt\/var\/log\/redis.log/" redis.conf > /etc/redis/redis.conf

Manage use init script redis (refer to: a script to start and stop redis daemon)

#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:   - 20 80
# description: Starts and stops the redis daemon.

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

name="redis-server"
exec="/usr/local/bin/$name"
cliexec="/usr/local/bin/redis-cli"
pidfile="/var/run/redis.pid"
REDIS_CONFIG="/etc/redis/redis.conf"
REDIS_PORT="6379"

[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis

lockfile=/var/lock/subsys/redis

start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
    echo -n $"Starting $name: "
    ulimit -n 131072
    daemon "$exec $REDIS_CONFIG"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    pid=$(cat /var/run/redis.pid)
    # echo -n $"Stopping $name: "
    $cliexec -p $REDIS_PORT shutdown
    while [ -x /proc/${pid} ]; do
      echo "Waiting for Redis to shutdown ..."
      sleep 0.5
    done
    retval=$?
    [ $retval -eq 0 ] && rm -f $lockfile && action $"Stopping $name: " /bin/true
    return $retval
}

restart() {
    stop
    start
}

reload() {
    false
}

rh_status() {
    status -p $pidfile $name
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
        exit 2
esac
exit $?

  

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

/sbin/chkconfig --add redis
/sbin/chkconfig --level 345 redis on
/sbin/service redis start

 

Memcached:

Install

yum install libevent libevent-devel

wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
tar zfxv memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure
make && make install

Manage use init script redis 

/etc/sysconfig/memcached:

PORT="11211"
USER="nobody"
MAXCONN="131072"
CACHESIZE="5376"
OPTIONS="-P /var/run/memcached/memcached.pid -t 8"


/etc/init.d/memcached:

#!/bin/bash
#
# Init file for memcached
#
# Written by Dag Wieërs <dag@wieers.com>
#
# chkconfig: - 80 12
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached
# config: /etc/memcached.conf

source /etc/rc.d/init.d/functions

### Default variables
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
SYSCONFIG="/etc/sysconfig/memcached"

### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="memcached"
desc="Distributed memory caching"

start() {
    echo -n $"Starting $desc ($prog): "
    daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

stop() {
    echo -n $"Shutting down $desc ($prog): "
    killproc $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

restart() {
    stop
    start
}

reload() {
    echo -n $"Reloading $desc ($prog): "
    killproc $prog -HUP
    RETVAL=$?
    echo
    return $RETVAL
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  condrestart)
    [ -e /var/lock/subsys/$prog ] && restart
    RETVAL=$?
    ;;
  reload)
    reload
    ;;
  status)
    status $prog
    RETVAL=$?
    ;;
   *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    RETVAL=1
esac

exit $RETVAL

 

chkconfig --add memcached
chkconfig --level 345 memcached on
service memcached start

 

posted on 2013-01-06 14:23  foxracle  阅读(677)  评论(0编辑  收藏  举报