Linux安装memcache

  1. 作者QQ:67065435 QQ群:821635552

  2. 安装mencached服务及memcache扩展

    yum install \
    vim \
    memcached \
    firewalld \
    -y
    
  3. 将memcache加入systemd

    chkconfig --level 2345 memcached on
    
  4. 修改配置文件

    vim /etc/sysconfig/memcached
    
    PORT="11211"
    USER="memcached"
    MAXCONN="1024"
    CACHESIZE="64"
    OPTIONS=""
    
    ESC
    :wq
    
  5. 添加运行用户memcached

    useradd memcached
    
  6. 开启防火墙11211端口

    systemctl enable firewalld
    systemctl start firewalld
    firewall-cmd --zone=public --add-port=11211/tcp --permanent
    firewall-cmd --reload
    
  7. 启动并设置开机启动

    # 启动
    systemctl start memcached
    # 开机启动
    systemctl enable memcached
    # 停止
    systemctl stop memcached
    # 重启
    systemctl restart memcached
    
  8. 安装PHP-memcache扩展(参考php安装文档附录)

  9. 测试服务及扩展安装是否成功

    vim /xxx/test.php
    
    <?php
    $mem = new Memcache();
    $mem->connect("127.0.0.1",11211);
    $mem->set('key','This is first value',0,60);
    echo $val=$mem->get('key');
    
    ESC
    :wq
    
    php /xxx/test.php
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2012-12-31 12:00:00

results matching ""

    No results matching ""