您的位置:首页 > 数据库 > Memcache

安装memcached服务器和php中添加memcache拓展模块

2013-09-12 18:40 686 查看
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。

首先需要先安装libevent,memcached是基于libevent做为事件触发的
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make && make install

接下来安装memecahed:
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install

安装php扩展模块memcache:
wget http://pecl.php.net/get/memcache-2.2.6.tgz tar xzvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize -----执行phpize扩展安装程序,如果没有安装phpize 运行yum install php-devel
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
make && make install

安装成功会有类似下面的提示
Installing shared extensions: /usr/local/php/lib/php/extensions/xxxxxxx。。。

在php.ini文件,在zend之前加入如下代码:
[memcache]
extension_dir = "/usr/local/php/lib/php/extensions/xxxxxxxx"
extension=memcache.so

启动memcached:
/usr/local/memcached/bin/memcached -d -u root -m 1024 -p 11211 -c 10240

如果php运行环境是apache需要重启apache,如果是nginx需要重启php这样能重新加载php配置文件来支持 memcache

启动参数说明:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB
-M return error on memory exhausted (rather than removing items)
-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址,默认为所有网卡。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024
-P 是设置保存Memcache的pid文件

参考文档 http://blog.sina.com.cn/s/blog_70f91c2f01010tt0.html http://www.centos.bz/2011/11/linux-install-php-memcache/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: