memcached安装配置 

     安装memcached需要libevent的支持,所以先安装libevent;

一、安装libevent

  1.下载

   cd /usr/local/src

   wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz

   2.安装

     # tar zxvf libevent-2.0.20-stable.tar.gz

     # cd libevent-2.0.20-stable

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

     # make && make install

  libevent已经安装完成;


二、安装memcached

  1.下载

     # wget http://memcached.org/files/memcached-1.4.22.tar.gz

     官网:http://memcached.org

  2.安装

     # cd /usr/local/src

     # tar zxvf memcached-1.4.22.tar.gz

     # cd memcached-1.4.22

     # ./configure --prefix=/usr/local/memcached  

     //执行此上时会出现找不到libevent的路径,需要编辑configure(vi configure) 找到 trylibeventdir="" 更改为 trylibeventdir="/usr/local/libevent" 即可;

     # make && make install

  3.启动memcached

     # /usr/local/memcached/bin/memcached -m 64m -p 11211 -d -u root -P /var/run/memcached.pid -c 256

    * -m 最大内存大小,默认为64m;

    * -p 使用tcp/ip端口,默认为11211;

    * -d 作为守护进程在后台运行;

    * -u 指定用户启动memcached程序;

    * -P 设置保存memcached的pid文件的位置;

    * -l 监听的服务器ip,如果有多个地址;

    * -c 最大运行的并发连接数,默认为1024,要按照服务器的负载量来设定;

  4.关闭memcached1

     # kill `cat /var/run/memcached`

  5.查看memcached的信息状态

     #telnet ip(memcached服务器ip) 11211

    输入:stats 即可查看到memcached的相关信息;


三、安装memcached的php扩展

  1.下载

     # wget http://pecl.php.net/get/memcache-3.0.5.tgz

     # tar zxvf memcache-3.0.5.tgz

     # cd memcache-3.0.5

     # /usr/local/php/bin/phpize    //生成configure文件

     执行此命令如下:

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

   此信息提示需要安装autoconf,

     # yum install -y autoconf

   再次执行此命令:/usr/local/php/bin/phpize 如下显示即可:

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

   2.安装

     # ./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-20121212/

   修改php.ini文件  

     # vim /etc/php.ini   

      找到;extension_dir = "./" 修改为 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/"

    再在php.ini中添加如下一行代码:extension=memcache.so

   退出保存即可。

至此已安装配置完成;