安装 memcached

yum install memcached

需要 libevent 库,如未装则运行如下

yum install libevent libevent-devel

安装 php memcache 扩展

PHP memcache

http://pecl.php.net/package/memcache

PHP memcached

http://pecl.php.net/package/memcached
wget http://pecl.php.net/get/memcache-3.0.8.tgz
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
make
make install

php.ini 中加入扩展 extension=memcache.so

vim /usr/local/php5/lib/php.ini

重启 php-fpm,查看 phpinfo 

开机启动 (更改端口号如 11811)(如果使用 yum 方式安装,默认自启动)

vim /etc/sysconfig/memcached
PORT="11811"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

编译方式安装的,在 /etc/rc.d/rc.local 中加入 (先 which memcached)

/usr/local/bin/memcached -u www -d -p 11811 -P /tmp/memcached.pid

或者创建 /etc/init.d/memcached

#!/bin/sh 
# 
# memcached:    MemCached Daemon 
# 
# chkconfig:    - 90 25
# description:  MemCached Daemon 
# 
# Source function library.
. /etc/rc.d/init.d/functions 
. /etc/sysconfig/network 
#[ ${NETWORKING} = "no" ] && exit 0
#[ -r /etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund 
#[ -z "$DUNDARGS" ] && exit 0
MEMCACHED="/usr/bin/memcached"
SERVER_IP="127.0.0.1"
SERVER_PORT="11811"
[ -f $MEMCACHED ] || exit 1
start() 
{ 
        echo -n $"Starting memcached: "
        daemon $MEMCACHED -u daemon -d -m 2048 -l $SERVER_IP -p $SERVER_PORT -P /tmp/memcached.pid
        echo 
} 
stop() 
{ 
        echo -n $"Shutting down memcached: "
        killproc memcached 
        echo 
}
  
# See how we were called. 
case "$1" in 
  start) 
        start 
        ;; 
  stop) 
        stop 
        ;; 
  restart) 
        stop 
        sleep 3
        start 
        ;; 
    *) 
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac 
exit 0
#  chmod 755 /etc/init.d/memcached
#  chkconfig --add memcached
#  chkconfig memcached on
#  service memcached start
#  chkconfig --list memcached  #查看是否设置成功

启动

memcached -u root -d -p 11811

1 Comment

回复 misswell 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注