安装Memcached

安装Memcached服务端


#!/bin/bash

yum -y install gcc make wget

wget http://mogu-lamp.qiniudn.com/libevent-2.0.21-stable.tar.gz
wget http://mogu-lamp.qiniudn.com/memcached-1.4.20.tar.gz

tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr
make && make install
cd ..

tar zxvf memcached-1.4.20.tar.gz
cd memcached-1.4.20
./configure --prefix=/usr/local/memcached
make && make install
cd ..

ln -s /usr/lib/libevent-2.0.so.5  /lib/libevent-2.0.so.5
ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached

ldconfig

echo '#! /bin/bash
#
# memcached:    MemCached Daemon
#
# chkconfig:    - 90 25
# description:  MemCached Daemon
#
### BEGIN INIT INFO
# Provides:          memcached
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:        $local_fs
# Should-Stop:        $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:    memcached - Memory caching daemon
# Description:        memcached - Memory caching daemon
### END INIT INFO

PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=64
OPTIONS=""

RETVAL=0
prog="memcached"

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

stop () {
    echo -n $"Stopping $prog: "
    kill `cat /var/run/memcached.pid`
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ] ; then
        rm -f /var/lock/subsys/memcached
        rm -f /var/run/memcached.pid
    fi
}

restart () {
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|reload}"
    exit 1
esac

exit $?' > /etc/init.d/memcached

chmod +x /etc/init.d/memcached

# 设置开机启动
chkconfig memcached --add
chkconfig memcached on

service memcached start

客户端


#!/bin/bash

wget http://pecl.php.net/get/memcache-2.2.7.tgz

tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..

/*
[Memcache]
extension = memcache.so
*/

发表评论