日期:2014-05-17  浏览次数:20484 次

memcached 以及 php新客户端memcached 安装(参考)
2010-02-23 11:05web2.0和web1.0不一样,web1.0以内容为中心,所以web1.0做负载只需缓存内容就可以了,使用反向代理缓存页面就可以解决大部分问题了。而web2.0鼓励用户交互,内容都是动

态的,只做反向代理命的话中率低,而且对数据库进行频繁的写,对数据库压力大。所以,web2.0对 web1.0更需要使用内存缓存。

memcached高性能的,分布式的内存对象缓存系统,在动态应用中减少数据库负载,提升访问速度。memcached已经被广泛应用在各种软件中,例如,nginx、mysql

一、服务端安装
使用weget下载libevent和memcached
libevent: http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
memcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz

1.先安装libevent


tar zxvf libevent-1.4.9-stable.tar.gz 
cd libevent-1.4.9-stable  
./configure  
make  
make install  

tar zxvf libevent-1.4.9-stable.tar.gz 
cd libevent-1.4.9-stable
./configure
make
make install



2.安装memcached


tar zxvf memcached-1.2.6.tar.gz  
cd memcached-1.2.6  
./configure --enable-threads  
make  
make install  

tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure --enable-threads
make
make install



注:如果启动时出现“memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open
shared object file: No such file or directory”之类的信息,表示memcached找不到libevent的位置
所以,请先使用whereis libevent得到位置,然后连接到memcached所寻找的路径


[root@localhost tools]# whereis libevent  
libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a  
[root@localhost tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less  
[root@localhost tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/  




二、php安装对memcached的支持

php有两个版本的memcached客户端

1.memcached
这个是新版的客户端基于libmemcached,所以必须要安装libmemcached

先安装libmemcached
下载地址:http://download.tangent.org/libmemcached-0.26.tar.gz


[root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz  
[root@localhost tools]# cd libmemcached-0.26  
[root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/  
[root@localhost libmemcached-0.26]# make  
[root@localhost libmemcached-0.26]# make install  

[root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz
[root@localhost tools]# cd libmemcached-0.26
[root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/
[root@localhost libmemcached-0.26]# make
[root@localhost libmemcached-0.26]# make install



安装php memcached及最新客户端
下载地址:http://pecl.php.net/get/memcached



[root@localhost tools]# tar zxvf memcached-0.1.4.tgz  
[root@localhost tools]# cd memcached-0.1.4  
[root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/  
[root@localhost memcached-0.1.4]# make  
[root@localhost memcached-0.1.4]# make install  

[root@localhost tools]# tar zxvf memcached-0.1.4.tgz
[root@localhost tools]# cd memcached-0.1.4
[root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/
[root@localhost memcached-0.1.4]# make
[root@localhost memcached-0.1.4]# make install


修改php.ini添加extension = "memcached.so"就可以了。

1. checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the 

prefix where libmemcached headers and library are located  

checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix 

where libmemcached headers and library are located


请先用whereis libmemcached找到路径,然后添加选项--with-libmemcached-dir=libmemcached路径


2.memcache
下载地址:http://pecl.php.net/get/memcache


[root@localhost tools]# tar zxvf memcache-3.0.3.tgz 
[root@localhost tools]# cd memcache-3.0.3  
[root@localhost tools]# /usr/local/php/bin/phpize  
[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config  
[root@localhost tools]# make  
[root@localhost tools]# make install  

[root@localhost tools]# tar zxvf memcache-3.0.3.tgz