memcached 以及 php客户端 安装
web2.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
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]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./configuremakemake install
2.安装memcached
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]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.gzcd memcached-1.2.6./configure --enable-threadsmakemake 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所寻找的路径
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]# whereis libevent
[*]libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a
[*]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less
[*] 3848: find library=libevent-1.4.so.2 ; searching
[*] 3848: search cache=/etc/ld.so.cache
[*] 3848: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/
[*]usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
[*](system search path)
[*] 3848: trying file=/lib64/tls/x86_64/libevent-1.4.so.2
[*] 3848: trying file=/lib64/tls/libevent-1.4.so.2
[*] 3848: trying file=/lib64/x86_64/libevent-1.4.so.2
[*] 3848: trying file=/lib64/libevent-1.4.so.2
[*] 3848:
[*] 3848: find library=libc.so.6 ; searching
[*] 3848: search cache=/etc/ld.so.cache
[*] 3848: trying file=/lib64/libc.so.6
[*] 3848:
[*] 3848: find library=libnsl.so.1 ; searching
[*] 3848: search cache=/etc/ld.so.cache
[*] 3848: trying file=/lib64/libnsl.so.1
[*] 3848:
[*] 3848: find library=librt.so.1 ; searching
[*] 3848: search cache=/etc/ld.so.cache
[*] 3848: trying file=/lib64/librt.so.1
[*] 3848:
[*] 3848: find library=libresolv.so.2 ; searching
[*] 3848: search cache=/etc/ld.so.cache
[*]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/
# whereis libeventlibevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less 3848: find library=libevent-1.4.so.2 ; searching 3848: search cache=/etc/ld.so.cache 3848: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64 (system search path) 3848: trying file=/lib64/tls/x86_64/libevent-1.4.so.2 3848: trying file=/lib64/tls/libevent-1.4.so.2 3848: trying file=/lib64/x86_64/libevent-1.4.so.2 3848: trying file=/lib64/libevent-1.4.so.2 3848: 3848: find library=libc.so.6 ; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/libc.so.6 3848: 3848: find library=libnsl.so.1 ; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/libnsl.so.1 3848: 3848: find library=librt.so.1 ; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/librt.so.1 3848: 3848: find library=libresolv.so.2 ; searching 3848: search cache=/etc/ld.so.cache# 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
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]# tar zxvf libmemcached-0.26.tar.gz
[*]# cd libmemcached-0.26
[*]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/
[*]# make
[*]# make install
# tar zxvf libmemcached-0.26.tar.gz# cd libmemcached-0.26# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/# make# make install
安装php memcached客户端
下载地址:http://pecl.php.net/get/memcached
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]# tar zxvf memcached-0.1.4.tgz
[*]# cd memcached-0.1.4
[*]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/
[*]# make
[*]# make install
# tar zxvf memcached-0.1.4.tgz# cd memcached-0.1.4# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/# make# make install
修改php.ini添加extension = "memcached.so"就可以了。
如果出现错误
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]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
Java代码 http://willko.javaeye.com/images/icon_copy.gif
[*]# tar zxvf memcache-3.0.3.tgz
[*]# cd memcache-3.0.3
[*]# /usr/local/php/bin/phpize
[*]# ./configure --with-php-config=/usr/local/php/bin/php-config
[*]# make
[*]# make install
# tar zxvf memcache-3.0.3.tgz # cd memcache-3.0.3# /usr/local/php/bin/phpize# ./configure --with-php-config=/usr/local/php/bin/php-config# make# make install
修改php.ini添加extension = "memcache.so"就可以了。
提示:如果php找不到so文件,请设置extension_dir。
ps:这篇东西在草稿箱里呆很久了,最后还是决定把一篇分多篇发吧,这样感觉快多了。
参考资料:
http://www.danga.com/memcached/
http://willko.javaeye.com/blog/332993
页:
[1]