zoukankan      html  css  js  c++  java
  • memcached/memcache安装

    memcached安装

    查找memcached:        yum  search  memcached
    安装 memcached             yum  -y install memcached
    验证安装memcached       memcached -h
    修改配置:
    [root@localhost ~]# vi /etc/sysconfig/memcached

    PORT="11211"        #启动端口
    USER="memcached"    #启动用户
    MAXCONN="1024"        #最大连接数
    CACHESIZE="1024"    #占用最大内存,MB
    OPTIONS=""        #其他选项,本人还不知道怎么用

    使用memcached-tool检测memcached服务
    [root@localhost ~]# memcached-tool 127.0.0.1:11211 stats
    #127.0.0.1:11211   Field       Value
             accepting_conns           1
                   auth_cmds           0
                 auth_errors           0
                       bytes          72
                  bytes_read          44
               bytes_written         802
                  cas_badval           0
                    cas_hits           0
                  cas_misses           0
                   cmd_flush           0
                     cmd_get           1
                     cmd_set           1
                 conn_yields           0
       connection_structures          11
            curr_connections          10
                  curr_items           1
                   decr_hits           0
                 decr_misses           0
                 delete_hits           0
               delete_misses           0
                   evictions           0
                    get_hits           1
                  get_misses           0
                   incr_hits           0
                 incr_misses           0
              limit_maxbytes  1073741824
         listen_disabled_num           0
                         pid        3438
                pointer_size          64
               rusage_system    0.074988
                 rusage_user    0.048992
                     threads           4
                        time  1464744573
           total_connections          13
                 total_items           1
                      uptime        2780
                     version       1.4.4


    启动配置文件: /etc/sysconfig/memcached
    PID文件: /var/run/memcached/memcached.pid

    若要允许其他服务器访问,需开启防火墙中相应端口。


    服务启动、停止、重启命令
    service memcached start|stop|restart
    这些命令对应:cat /etc/init.d/memcached
    需要手工加启动:vi /etc/rc.d/rc.local

    若要启动第二个实例,需另行运行命令:

    memcached -d -m 内存MB -u 用户 -l IP地址 -p 端口 -c 最大并发 -P PID文件
    memcached -d -m 1024 -u memcached -p 11212 -c 1024 -P /var/run/memcached/memcached.pid


    -d      选项是启动一个守护进程,
    -m      分配给Memcache使用的内存数量,单位是MB,
    -u      运行Memcache的用户,不要用root,
    -l      监听的服务器IP地址,不填为本机,
    -p      设置Memcache监听的端口,默认11211,要用1024以上的端口。(小写的p)
    -c      最大运行的并发连接数,默认是1024,
    -P      设置保存Memcache的pid文件,比如 /tmp/memcached.pid,(大写的P)

    memcache【php扩展】安装

    下载列表:http://pecl.php.net/package/memcache

    原生的Memcache 3.08版:http://pecl.php.net/get/memcache-3.0.8.tgz

    此版不能用在php7中,所以,若在PHP7中运行,需用其他分支版:

    Github的pecl-memcache分支版:https://github.com/websupport-sk/pecl-memcache/archive/php7.zip


    tar zxvf memcache-2.2.4.tgz
    cd memcache-2.2.4

    phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make install


    最后,编辑器php.ini,加入:extension=memcache.so

     [root@localhost ~]# php -i |grep php.ini
    Configuration File (php.ini) Path => /usr/local/php/etc
    Loaded Configuration File => /usr/local/php/etc/php.ini
    [root@localhost ~]# vi  /usr/local/php/etc/php.ini
    [root@localhost ~]#

    启动:service memcached start

    写一个测试PHP文件:

    <?php  
    $memcache = new Memcache; //创建一个memcache对象  
    $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器  
    $memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test  
    $get_value = $memcache->get('key'); //从内存中取出key的值  
    echo $get_value." ";

    运行,若能打印【test】,则搞定了。

    php.ini中设置:

    memcache.chunk_size=1024*20  将memcache单条数据限制为20K

  • 相关阅读:
    MongoDB使用固定集合
    mongoDB创建用户
    easyuI企业管理系统-实战五 删除功能
    easyuI企业管理系统-实战四 上传图片
    easyuI企业管理系统-实战三 添加功能
    easyuI企业管理系统-实战二 表格引入json数据
    日常记录
    easyui的图标汇总
    easyuI企业管理系统-实战一下拉列表框应用
    想学easyui框架技术的同学们,请注意! 编辑
  • 原文地址:https://www.cnblogs.com/fazo/p/5548490.html
Copyright © 2011-2022 走看看