zoukankan      html  css  js  c++  java
  • 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基础操作及概念
    监督学习和非监督学习
    基于仿生算法的智能系统I
    9.Dijkstra求最短路 II 堆优化的Dijkstra
    8.Dijkstra求最短路 I 朴素Dijkstra
    7.有向图的拓扑序列 拓扑排序
    6.树与图的广度优先遍历 图中点的层次
    5.树的重心 树与图的深度优先遍历
    4.八数码 BFS
  • 原文地址:https://www.cnblogs.com/zsmynl/p/3539139.html
Copyright © 2011-2022 走看看