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
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


注:如果启动时出现“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
      3848:     find library=libevent-1.4.so.2 [0]; 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 [0]; searching
      3848:      search cache=/etc/ld.so.cache
      3848:       trying file=/lib64/libc.so.6
      3848:     
      3848:     find library=libnsl.so.1 [0]; searching
      3848:      search cache=/etc/ld.so.cache
      3848:       trying file=/lib64/libnsl.so.1
      3848:     
      3848:     find library=librt.so.1 [0]; searching
      3848:      search cache=/etc/ld.so.cache
      3848:       trying file=/lib64/librt.so.1
      3848:     
      3848:     find library=libresolv.so.2 [0]; searching
      3848:      search cache=/etc/ld.so.cache
[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


安装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

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

如果出现错误
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

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

提示:如果php找不到so文件,请设置extension_dir。

ps:这篇东西在草稿箱里呆很久了,最后还是决定把一篇分多篇发吧,这样感觉快多了。

参考资料:
http://www.danga.com/memcached/

你可能感兴趣的:(PHP,mysql,nginx,cache,memcached)