zoukankan      html  css  js  c++  java
  • linux系统安装Memcache

    Linux系统安装memcached 首先要先安装libevent库。

    centos  下执行

    yum install libevent libevent-devel

    查看memcached 是否已经安装  

    which  memcached    //如果已经安装  输出类似“/usr/bin/memcached”

    安装memcached 执行:

    yum install memcached  

    安装php memcached 扩展 php-pecl-memcached 

    yum -y install php72w-pecl-memcached  //我的PHP版本是php7.2的,如果版本不对会报错误:php72w-common conflicts with php-common-5.4.16-45.el7.x86_64错误

    查看是否安装php-pecl-memcached 扩展

    php  -m  |  grep  memcache     // 安装成功会输出memcached, 否则没有输

    设置开机启动

    sudo systemctl enable memcached

    启动memcached

    1
    sudo systemctl start memcached

    启动memcached 服务,在终端输入

    1
    # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 11211 -c 256 -P /tmp/memcached.pid

    查看memcached 监听情况

    1
    lsof -i tcp:11211   <br>输出<br>COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME<br>memcached 5821 vagrant   26u  IPv6  42350      0t0  TCP localhost:memcache (LISTEN)<br>memcached 5821 vagrant   27u  IPv4  42351      0t0  TCP php-site:memcache (LISTEN)

    说明监听11211端口成功

    会在/usr/lib64/php/modules/ 下生成memcached.so

    在php.ini中开启 extension=/usr/lib64/php/modules/memcached.so

    1
    [Memcache]<br>extension=/usr/lib64/php/modules/memcached.so

     在php.ini文件中添加memcache扩展文件后,在xshell中执行会报错,但不影响web浏览器端效果,

    然后重启php-fpm

    1
    sudo systemctl restart php-fpm

    phpinfo()中能够看到memcached

    测试:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?php
     
    $mem = new Memcached;
     
    $mem->connect("127.0.0.1", 11211);
     
    $mem->set('key', 'hello test!', 0, 60);
     
    $val = $mem->get('key');
     
    echo $val;
     
    ?>

    上面测试代码有问题,我的测试代码:

    <?php
    
    $mem = new Memcached;
     
    $mem->addServer("127.0.0.1", 11211);
     
    $mem->set('key', 'hello test!', 10);
     
    $val = $mem->get('key');
     
    echo $val;
    

     

     

  • 相关阅读:
    树莓派4B踩坑指南
    树莓派4B踩坑指南
    树莓派4B踩坑指南
    从java反射到注解再到动态代理,一锅端!
    Lc_551学生出勤记录I
    aop日志测试类
    转载-使用@Async异步注解导致该Bean在循环依赖时启动报BeanCurrentlyInCreationException异常的根本原因分析,以及提供解决方案【享学Spring】
    linux 启动和停止脚本
    mysql 2003
    项目启动连不上mysql, Communications link failure
  • 原文地址:https://www.cnblogs.com/lxwphp/p/11133450.html
Copyright © 2011-2022 走看看