1.安装libevent,你已经安装过了,就可以忽略
wget http://monkey.org/~provos/libevent-1.4.12-stable.tar.gz (请在安装时选择最新稳定版)
tar -xvf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable
./configure –prefix=/usr/local/libevent
make
make install
安装好之后开始安装Memcached
wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
tar -xvf memcached-1.4.1.tar.gz
cd memcached-1.4.1
./configure –prefix=/usr/local/memcached –with-libevent=/usr/local/libevent
make
make install
运行 /usr/local/memcached/bin/memcached -d -m 16 -p 11211 -u memcached -l 127.0.0.1
然后就会出来一个提示
error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
原因是找不到libevent-1.4.so.2类库,下面是解决办法
cd /usr/lib64
ln -s /usr/local/libevent/lib/libevent-1.4.so.2.1.3 /usr/lib64/libevent-1.4.so.2
—–这个只适合64位系统,如果是32位系统的话要换下
cd /usr/lib64
ln -s /usr/local/libevent/lib/libevent-1.4.so.2.1.3 /usr/lib/libevent-1.4.so.2
下面再运行 /usr/local/memcached/bin/memcached -d -m 16 -p 11211 -u memcached -l 127.0.0.1
如果提示你没有安装memcache,那么你还要继续看下去
安装php的memcache
$ wget http://pecl.php.net/get/memcache-2.2.5.tgz (请在安装时选择最新稳定版)
$ tar -xvf memcache-2.2.5.tgz
$ cd memcache-2.2.5
/usr/local/php/bin/phpize (phpize 命令是用来准备 PHP 外挂模块的编译环境的)
./configure -enable-memcache -with-php-config=/usr/local/php/bin/php-config
make
make install
然后会有提示Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
然后修改php.ini
加入 extension= “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/memcache.so”
启动memcached守护进程
$ /usr/local/memcached/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
下面是参数
-d 启动一个守护进程
-m 限制内存大小,以M为单位,默认64M
-l 监听的服务器IP
-p 监听的端口,默认 11211
-c 并发连接数,默认是1024
-P 保存进程编号的文件
可以用
connect(‘127.0.0.1’, 11211);
$mem->set(‘key’, ‘this is a test’, 0, 60);
$val = $mem->get(‘key’);
echo $val;
?>
保存为test.php 然后运行,显示this is a test 那么就成功了
参考文章 http://www.ningoo.net/html/2009/install_memcached_on_linux_64.html