1. 下载安装包
加速下载地址: https://www.newbe.pro/Mirrors/Mirrors-Memcached/
2. 安装
# tar -zxf memcached-1.x.x.tar.gz
# cd memcached-1.x.x
# ./configure --prefix=/usr/local/memcached
执行出错: checking for libevent directory... configure: error: libevent is required. You can get it from https://www.monkey.org/~provos/libevent/
If it's already installed, specify its path using --with-libevent=/dir/
问题解决: 没有安装 libevent(安装libevent,安装openssl)#make && make test && sudo make install
3. 将memcached添加到path, 修改profile文件
export PATH=$PATH:/usr/local/memcached/bin
4. 启动
memcached -d -m 64 -p 11211 -u root
参数说明: -d 后台启动
5. 基本操作
# memcached -h //查看命令参数信息
# telnet IP地址 端口号 //连接
> stats //查看mc状态
> quit //退出
> set key flag expires byte //写入数据
flag: 是否压缩数据. 0-不压缩, 1-压缩
expires: 指定数据保存时间(秒数/unix时间戳),0代表永久保存
byte: 保存值得字节数
> get key //数据读取