• Memcached 搭建过程


    安装 memcached 服务端
    yum -y install libevent libevent-devel
    #需要 libevent 支持

    cd /opt
    rm -rf memcached-1.2.0.tar.gz
    wget http://192.168.0.97/download/linux/cache/memcached-1.2.0.tar.gz
    rm -rf memcached-1.2.0
    tar -zxf memcached-1.2.0.tar.gz
    cd /opt/memcached-1.2.0
    ./configure –with-libevent=
    make
    make install

    2、安装 memcache 客户端

    cd /opt
    rm -rf memcache-2.2.5.tgz
    wget http://192.168.0.97/download/linux/cache/memcache-2.2.5.tgz
    rm -rf memcache-2.2.5
    tar -zxf memcache-2.2.5.tgz
    cd /opt/memcache-2.2.5
    /usr/local/php/bin/phpize
    ./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
    make
    make install

    # 修改php.ini

    - – - – -
    vi /etc/php.ini
    /extension_dir =
    iextension=memcache.so
    extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
    #
    - – - – - -

    # 重启 apache php生效
    /usr/local/apache2/bin/apachectl restart

    3、一般的维护 开启 关闭 查看状态

    开启memcache 服务端
    /usr/local/bin/memcached -d -m 128 -u root -l 192.168.0.97 -c 256 -P /tmp/memcached.pid

    关闭memcache 服务端
    kill `cat /tmp/memcached.pid`

    写成脚本
    vi /etc/init.d/memcache_start.sh
    i/usr/local/bin/memcached -d -m 128 -u root -l 192.168.0.97 -c 256 -P /tmp/memcached.pid
    chmod a+x /etc/init.d/memcache_start.sh

    vi /etc/init.d/memcache_stop.sh
    ikill `cat /tmp/memcached.pid`
    chmod a+x /etc/init.d/memcache_start.sh

    查看memcache状态
    telnet 192.168.0.98 11211
    输入stats查询状态
    stats
    STAT pid 8601
    STAT uptime 696
    STAT time 1245832689
    STAT version 1.2.0
    STAT pointer_size 64
    STAT rusage_user 0.007998
    STAT rusage_system 0.030995
    STAT curr_items 1
    STAT total_items 1
    STAT bytes 76
    STAT curr_connections 2
    STAT total_connections 4
    STAT connection_structures 3
    STAT cmd_get 1
    STAT cmd_set 1
    STAT get_hits 1
    STAT get_misses 0
    STAT bytes_read 97
    STAT bytes_written 620
    STAT limit_maxbytes 134217728
    END

    -d选项是启动一个守护进程,
    -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
    -u是运行Memcache的用户,我这里是root,
    -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.22.200,
    -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
    -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
    -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

    4、在客户端使用php测试

    1 <?php
    2 $mem=new Memcache;
    3 $mem->connect(“192.168.0.97″,11211);
    4 $mem->set(‘key’,'This is a test!’, 0, 60);
    5 $val=$mem->get(‘key’);
    6 echo $val;
    7 ?>

  • 相关阅读:
    电商概念
    Linux知识点(二)
    linux知识点
    笔记8月20日
    考勤运行提示‘Length of values (115) does not match length of index (116) >>> ’
    数据透视表+数据条
    CCRC软件开发评审-材料应该怎么准备
    python os.walk函数
    httprunner 断言报错 expect_value 和check_value类型不一致
    自动化-Yaml文件读取函数封装
  • 原文地址:https://www.cnblogs.com/zsmynl/p/3539139.html
Copyright © 2020-2023  润新知