memcached安装

  • 安装memcached依赖libevent
    1. libevent 简介
        libevent是为了取代事件循环发现在事件驱动的网络服务器。一个应用程序只需要调用event_dispatch(),然后添加或删除事件动态而无需更改事件循环。
        libevent 与memcached 的关系?
        libevent 下载地址:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
      
    2. libevent 安装
        wget https://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
        make&make install
      
    3. 输入以下命令,查看是否有目录列出(检查是否安装成功)
        ls -al /usr/lib | grep libevent
      
  • 安装memcached
    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 --with-libevent=/usr
    make && make install
    
  • 编译安装php下的memcache扩展
    1. 下载扩展包
         wget http://pecl.php.net/get/memcache-2.2.7.tgz
      
    2. 编译并安装
          tar vxzf memcache-2.2.7.tgz
          cd memcache-2.2.7
          /usr/local/webserver/php/bin/phpize
          ./configure --enable-memcache --with-php-config=/usr/local/webserver/php/bin/php-config
          make&make install
      
    3. 安装成功的标志(扩展库存放路径)
      /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/
      


    4. 配置php.ini
      • 查找“extension_dir”,修改为如下代码:
             extension_dir='/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/'
        
      • 查找“extension”,任意地方添加如下代码:
             extension=memcache.so
        
  • 配置启动脚本
    #! /bin/sh
    #
    # chkconfig: - 55 45
    # description:  The memcached daemon is a network memory cache service.
    # processname: memcached
    # config: /etc/sysconfig/memcached
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    PORT=11211
    USER=root
    MAXCONN=1024
    CACHESIZE=64
    OPTIONS=""
    PID="/tmp/memcached.pid"
    HOST="127.0.0.1"
    PREFIX=/usr/local/bin/memcached
    
    if [ -f /etc/sysconfig/memcached ];then
        . /etc/sysconfig/memcached
    fi
    
    # Check that networking is up.
    if [ "$NETWORKING" = "no" ]
    then
        exit 0
    fi
    
    RETVAL=0
    
    start () {
        echo "Starting memcached ..."
        # insure that /var/run/memcached has proper permissions
        chown $USER $PREFIX
        $PREFIX -d -l $HOST -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P $PID $OPTIONS
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
    }
    stop () {
        echo "Stopping memcached ..."
        kill `cat /tmp/memcached.pid`
        RETVAL=$?
        if [ $RETVAL -eq 0 ] ; then
            rm -f /var/lock/subsys/memcached
            rm -f $PID
        fi
    }
    restart () {
        stop
        start
    }
    
    
    # See how we were called.
    case "$1" in
        start)
            start
            ;;
        stop)
        stop
        ;;
        status)
        status memcached
        ;;
        restart|reload)
        restart
        ;;
        condrestart)
        [ -f /var/lock/subsys/memcached ] && restart || :
        ;;
        *)
        echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
        exit 1
    esac
    
    exit $?
    
  • 添加为开机启动
    chkconfig --add memcached
    

內容目录

上一个主题

mongodb安装

下一个主题

php-apc安装

快速搜索

输入相关的模块,术语,类或者函数名称进行搜索