准备安装包:
libevent-2.0.21-stable.tar.gz //Memcached服务端的依赖包
memcached-1.4.29.tar.gz //Memcached服务端
libmemcached-1.0.18.tar.gz //Memcached扩展的依赖包
memcached-2.2.0.tgz //php的Memcached扩展
memcache-2.2.7.tgz //php的Memcache扩展
1、安装libevent
[root@localhost src]# tar -zxvf libevent-2.0.21-stable.tar.gz [root@localhost src]# cd libevent-2.0.21-stable [root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent [root@localhost libevent-2.0.21-stable]# make [root@localhost libevent-2.0.21-stable]# make install
2、安装Memcached服务端
[root@localhost src]# tar -zxvf memcached-1.4.29.tar.gz [root@localhost src]# cd memcached-1.4.29 [root@localhost memcached-1.4.29]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent [root@localhost memcached-1.4.29]# make [root@localhost memcached-1.4.29]# make install
3、启动Memcached服务
[root@localhost /] /usr/local/memcached/bin/memcached -d -m 256 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB.
-u是运行Memcache的用户.
-l是监听的服务器IP地址,我这里没有填.
-p是设置Memcache监听的端口.
-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定.
-P是设置保存Memcache的pid文件.
4、安装Memcached扩展的依赖包
[root@localhost src]# tar -zxvf libmemcached-1.0.18.tar.gz [root@localhost src]# cd libmemcached-1.0.18 [root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached [root@localhost libmemcached-1.0.18]# make
make的时候出现:./libtool: line 1125: g++: command not found 错误
[root@localhost /]# yum -y install gcc+ gcc-c++
然后重新安装
[root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached [root@localhost libmemcached-1.0.18]# make [root@localhost libmemcached-1.0.18]# make install
5、安装Memcached PHP扩展
[root@localhost src]# tar -zxvf memcached-2.2.0.tgz [root@localhost src]# cd memcached-2.2.0 [root@localhost memcached-2.2.0]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 [root@localhost memcached-2.2.0]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached ... ... ---------------------------------------------------------------------- Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
安装Memcache PHP扩展
[root@localhost src]# tar -zxvf memcache-2.2.7.tgz [root@localhost src]# cd memcache-2.2.7[root@localhost memcache-2.2.7]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 [root@localhost memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir [root@localhost memcache-2.2.7]# make [root@localhost memcache-2.2.7]# make test Build complete. Don't forget to run 'make test'. ===================================================================== PHP : /usr/local/php/bin/php PHP_SAPI : cli PHP_VERSION : 5.5.36 ZEND_VERSION: 2.5.0 PHP_OS : Linux - Linux localhost.localdomain 2.6.32-573.el6.i686 #1 SMP Thu Jul 23 12:37:35 UTC 2015 i686 INI actual : /usr/local/src/memcache-2.2.7/tmp-php.ini More .INIs : CWD : /usr/local/src/memcache-2.2.7 Extra dirs : VALGRIND : Not used ===================================================================== TIME START 2016-07-15 13:12:21 ===================================================================== No tests were run. [root@localhost memcache-2.2.7]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
6、配置php.ini
extension=memcached.so
extension=memcache.so
7、重启服务器