linux下memcached安装及php扩展安装配置

需要安装的软件包括

libevent  安装 Memcached 服务器所依赖的软件包

libmemcached  是一个 memcached 的库

memcached  Memcached 服务器软件包

memcached  PHP开启 Memcached 扩展的软件包

 

下载所需软件包并解包

安装 libevent

cd libevent-2.0.21-stable/  

./configure --prefix=/usr/local/libevent/  

make && make install

安装 memcached

cd memcached-1.4.15 

./configure --prefix=/usr/local/memcache/ --with-libevent=/usr/local/libevent/ 

make && make install  

安装 libmemcached

cd libmemcached-0.42  ./configure --prefix=/usr/local/libmemcached  --with-memcached 

make && make install  

 安装PHP Memcached扩展

cd memcached-2.1.0 
/usr/bin/phpize 
./configure -enable-memcached -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached
make && make install 

phpize报错,安装php-devel

yum install php-devel 

报错:memcache support requires ZLIB解决办法   
yum install zlib-devel 

报错:error:no,sasl.h is not available 错误就加上这个参数项 --disable-memcached-sasl,即

./configure -enable-memcached -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir --disable-memcached-sasl -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached

编译完成后,这时会生成一个 memcached.so 文件,记录下文件位置,如/usr/lib64/php/modules/

修改php.ini文件

增加extension=/usr/lib64/php/modules//memcached.so

重启apache或者nginx

若phpinfo中出现

说明安装成功

 

启动memcached

/usr/local/memcache/bin/memcached -d -m 256 -u root -p 11211 -c 1024 –P /tmp/memcached.pid

启动参数说明:

-d 选项是启动一个守护进程。

-u root 表示启动memcached的用户为root。

-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB。

-M return error on memory exhausted (rather than removing items)。

-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。

-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口。

-c 选项是最大运行的并发连接数,默认是1024。

-P 是设置保存Memcache的pid文件。

 -t <num>       number of threads to use, default 4

如果有此项,说明已经支持了线程,就可以在启动的时候使用 -t 选项来启动多线程

然后启动的时候必须加上你需要支持的线程数量:

/usr/local/memcache/bin/memcached -t 1024 

 

posted on 2015-04-17 13:58  lchecho  阅读(262)  评论(0编辑  收藏  举报

导航