Maison >développement back-end >tutoriel php >源码安装memcached和php memcache扩展
源码安装memcached和php memcache扩展
注:以下安装步骤以centos6.5系统为例。
http://www.memcached.org/
目前最新版本是http://www.memcached.org/files/memcached-1.4.24.tar.gz
由于memcached依赖于libevent库,因此需要安装libevent
#yum install libevent libevent-devel
#useradd -d /var/run/memcached/ -s /sbin/nologin -c "Memcached daemon" memcached
#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 端口号
#vi /etc/rc.d/init.d/memcached
#! /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.pid
# 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 permissionsif [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then chown $USER /var/run/memcachedfidaemon --pidfile ${pidfile} /usr/local/memcached/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONSRETVAL=$?echo[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
echo -n $"Stopping $prog: "killproc -p ${pidfile} /usr/local/memcached/binRETVAL=$?echoif [ $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} memcachedRETVAL=$?;;
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
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