Memcache安装使用 linux系统

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

sudo systemctl start memcached

启动memcached 服务,在终端输入

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

查看memcached 监听情况

 lsof -i tcp:11211   
输出
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
memcached 5821 vagrant   26u  IPv6  42350      0t0  TCP localhost:memcache (LISTEN)
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

 

[Memcache]
extension=/usr/lib64/php/modules/memcached.so

 

然后重启php-fpm

sudo systemctl restart php-fpm

phpinfo()中能够看到memcached

测试:

<?php

$mem = new Memcached;

$mem->connect("127.0.0.1", 11211);

$mem->set('key', 'hello test!', 0, 60);

$val = $mem->get('key');

echo $val;

?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值