注:如下安裝步驟以centos6.5系統爲例。php
http://www.memcached.org/nginx
目前最新版本是http://www.memcached.org/files/memcached-1.4.24.tar.gzcentos
因爲memcached依賴於libevent庫,所以須要安裝libevent
#yum install libevent libevent-develmemcached
#useradd -d /var/run/memcached/ -s /sbin/nologin -c "Memcached daemon" memcachedphp-fpm
#tar zxvf memcached-1.4.24.tar.gz工具
#cd memcached-1.4.24
#./configure --prefix=/usr/local/memcached
#make && make install測試
-m memcache最大可用內存數(單位:M)
-u 用戶
-l 監聽IP
-p 端口號rest
#vi /etc/rc.d/init.d/memcachedcode
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached/memcached.pidip
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
IP=127.0.0.1
PORT=11211
USER=memcached
MAXCONN=1024
CACHESIZE=64
OPTIONS=""
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
pidfile=${PIDFILE-/var/run/memcached/memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/memcached}
start () {
echo -n $"Starting $prog: " # Ensure that /var/run/memcached has proper permissions if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then chown $USER /var/run/memcached fi daemon --pidfile ${pidfile} /usr/local/memcached/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
echo -n $"Stopping $prog: " killproc -p ${pidfile} /usr/local/memcached/bin RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f ${lockfile} ${pidfile} fi
}
restart () {
stop start
}
# See how we were called.
case "$1" in
start)
start ;;
stop)
stop ;;
status)
status -p ${pidfile} memcached RETVAL=$? ;;
restart|reload|force-reload)
restart ;;
condrestart|try-restart)
[ -f ${lockfile} ] && restart || : ;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force- reload|condrestart|try-restart}" RETVAL=2 ;;
esac
#/etc/rc.d/init.d/memcached start
默認memcached服務監聽在127.0.0.1:11211
#telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 12246
STAT uptime 2444
STAT time 1442302696
STAT version 1.4.24
STAT libevent 2.0.22-stable
STAT pointer_size 64
STAT rusage_user 0.089986
STAT rusage_system 0.027995
STAT curr_connections 5
STAT total_connections 7
memcached-tool是memcached監控工具,是一個perl腳本,能夠直接運行。命令用法以下。
Usage: memcached-tool <host[:port]> [mode]
memcached-tool 10.0.0.5:11211 display # shows slabs memcached-tool 10.0.0.5:11211 # same. (default is display) memcached-tool 10.0.0.5:11211 stats # shows general stats memcached-tool 10.0.0.5:11211 dump # dumps keys and values
memcache-3.0.8.tgz
#tar zxvf memcache-3.0.8.tgz
#cd memcache-3.0.8
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make && make install
添加 extension=memcache.so
Registered save handlers files user memcache