zoukankan      html  css  js  c++  java
  • MemCached 安装

    1、安装Memcached
    2、安装memcache PHP模块
    3、测试脚本

    一、环境需求 装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/

    # tar vxzf libevent-1.3e.tar.gz
    # cd libevent-1.1a
    # ./configure
    # make
    # make install
    建立一个符号连接:#ls -s /usr/local/lib/libevent-1.1.so.1 /usr/lib
    2、安装Memcached
    # tar memcached-1.2.8.tar.gz
    # cd memcached-1.2.8
    # ./configure --prefix=/usr/local/memcached
    --with-libevent=/usr
    # make
    # make install

    # cd /usr/local/php/modules/memcached/bin
    # ./memcached -d -m 50 -p 11211 -u root
    参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行

    然后重启web服务器即可。如果安装成功,则通过phpinfo()可以获得该扩展的相关信息:

    memcache support enabled
    Active persistent connections 0
    Version 2.2.5
    Revision $Revision: 1.111 $
    Directive Local Value Master Value
    memcache.allow_failover 1 1
    memcache.chunk_size 8192 8192
    memcache.default_port 11211 11211
    memcache.default_timeout_ms 1000 1000
    memcache.hash_function crc32 crc32
    memcache.hash_strategy standard standard
    memcache.max_failover_attempts 20 20


    3、安装memcache PHP模块

    # tar vxzf memcache-2.0.4.tgz
    # cd memcache-2.0.4
    # /usr/local/php/bin/phpize

    如果出现:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
    environment variable is set correctly and then rerun this script.

    错误原因是没有安装autoconf,你必须安装以下两个rpm:

    rpm -ivh /media/cdrom/Server/imake-1.0.2-3.i386.rpm

    rpm -ivh /media/cdrom/Server/autoconf-2.59-12.noarch.rpm

    #./configure --with-php-config=/usr/local/php/bin/php-config --with-apxs=/usr/local/apache/bin/apxs --with-gettext --enable-socket --enable-memcache --enable-sysvshm --enable-shmop


    # make
    # make install

    然后修改php.ini

    extension_dir = "./"
    修改为
    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
    并添加一行
    extension=memcache.so
    3、测试脚本
    自己写一个PHP程序测试一下吧

    Code

    运行后输出如下:

    Server's version: 1.2.8
    Store data in the cache (data will expire in 10 seconds)
    Data from the cache: object(stdClass)#3 (2)
    { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }
  • 相关阅读:
    内存泄露检测工具之DMalloc
    五年后你在何方
    程序员技术练级攻略
    Windows编程革命简史
    su的时候密码认证失败的解决方法
    ruby 元编程 meta programming
    内存对齐分配策略(含位域模式)
    Ruby 之 Block, Proc, Lambda 联系区别,转载
    c++异常处理机制示例及讲解
    ruby 常见问题集 1 不断更新中
  • 原文地址:https://www.cnblogs.com/wangbin/p/1439601.html
Copyright © 2011-2022 走看看