(转)memcache 安装 笔记

一、环境需求
安装Memcached需要libevent库的支持,所以请在安装Memcached之前检查有没有安装libevent。测试环境还需要PHP的支持。

我的是CentOS5.4的系统,装好了apache、php。

二、下载相关软件

Memcached下载地址:http://www.danga.com/memcached/
memcache PHP模块下载地址: http://pecl.php.net/package/memcache
libevent 下载地址: http://www.monkey.org/~provos/libevent/

我下载的版本分别是:‍memcached-1.4.5.tar.gz、‍memcache-3.0.5.tgz、libevent-2.0.9-rc.tar.gz

我在Windows系统下下载,然后samba上传到服务器。当然也可以用ftp。


三、安装

1、安装libevent

root@wxlccsu:# tar vxzf libevent-2.0.9-rc.tar.gz
root@wxlccsu:# cd libevent-2.0.9
root@wxlccsu:# ./configure  
root@wxlccsu:# make
root@wxlccsu:# make install

2、安装Memcached


root@wxlccsu:# tar vxzf memcached-1.4.5.tar.gz
root@wxlccsu:# cd memcached-1.4.5
root@wxlccsu:# ./configure --prefix=/usr/local/memcached
root@wxlccsu:# make
root@wxlccsu:# make install

安装完之后要启动服务


root@wxlccsu:# cd /usr/local/memcached/bin
root@wxlccsu:# ./memcached -d -m 50 -p 11211 -u root

启动memcached出现状况

error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

在网上查了下
解决这个问题有如下方法:
1>首先 find / -name libevent-2.0.so.5 找到缺少的链接文件到底在那儿。
2> LD_DEBUG=libs /usr/local/memcached/‍bin/memcached -v
3> 从Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib/libevent-2.0.so.5 而我的链接库的实际存储位置是 /usr/local/lib/libevent-2.0.so.5

4>做一个软连接 ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.

5>搞定.


3、安装memcache PHP模块


root@wxlccsu:# tar vxzf memcache-3.0.5.tgz
root@wxlccsu:# cd memcache-3.0.5

root@wxlccsu:# find / -name phpize
‍/usr/bin/phpize
root@wxlccsu:# /usr/bin/phpize

root@wxlccsu:# find / -name php-config

/usr/bin/php-config
root@wxlccsu:# ./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir
root@wxlccsu:# make
root@wxlccsu:# make install

注:find / -name phpize find / -name php-config

这两个文件视具体路径而定

安装完后会有类似这样的提示:


Installing shared extensions:     /usr/lib/php/modules/

把这个记住,然后修改php.ini,把


extension_dir = "./"

修改为


extension_dir = "/usr/lib/php/modules"

并添加一行


extension=memcache.so

重启apache

root@wxlccsu:# /etc/init.d/http.d restart

四、测试脚本
自己写一个PHP程序测试一下吧


<?php
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'this is a test by wxlccsu !'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;

phpinfo();
?>

通过浏览器查看此页面可以看到:‍this is a test by wxlccsu !

并且在php模块信息中可以看到memcache的相关信息。

猜你喜欢

转载自cjb.iteye.com/blog/1074231