由于数据库存储的数据量越来越大,查询速度也就变的越来越慢,因此就有了缓存服务器应用的必要,本文是介绍Memcached缓存服务器的安装以及简单的使用。

本文只介绍memcached缓存服务器的PHP的API,想查看其他关于Memcached缓存服务器的API文档案,请访问 http://www.danga.com/memcached/

缓存服务器在Linux下的应用(linux 缓存)  缓存服务器 第1张

一、环境需求
安装Memcached缓存服务器需要libevent库的支持,所以请在安装Memcached缓存服务器之前检查有没有安装libevent。测试环境还需要PHP的支持,本文假设PHP已经安装到/usr/local/php目录下,也就是在编译PHP的时候使用perfix参数指定目录(--prefix=/usr/local/php)

二、下载相关软件

Memcached缓存服务器下载地址:http://www.danga.com/memcached/
memcache PHP模块下载地址: http://pecl.php.net/package/memcache 推荐使用1.5版
libevent 下载地址: http://www.monkey.org/~provos/libevent/

本文不再讲述如何安装libevent

三、安装和配置

1、安装Memcached

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

安装完之后要启动服务

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

参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行

2、安装memcache PHP模块

root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install

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

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/

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

extension_dir = "./"

修改为

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"

并添加一行

extension=memcache.so

3、测试脚本

自己写一个PHP程序测试一下吧。

转载请说明出处
知优网 » 缓存服务器在Linux下的应用(linux 缓存)

发表评论

您需要后才能发表评论