linux memcached

时间:2022-08-10 20:05:36

依赖库

yum install libevent libevent-deve 

云安装

yum install memcached

源代码安装

wget http://memcached.org/latest                    下载最新版本
tar -zxvf memcached-.x.x.tar.gz 解压源码
cd memcached-.x.x 进入目录
./configure --prefix=/usr/local/memcached 配置
make && make test 编译
sudo make install 安装

如果./configure 编译不通过

// 报错如下
checking for libevent directory… configure: error: libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
If it’s already installed, specify its path using –with-libevent=/dir/ // 则 ...,再编辑,即可通过。。
yum install libevent-devel

作为后台服务运行

# /usr/local/memcached/bin/memcached -p  -m 64m -d
或者
# /usr/local/memcached/bin/memcached -d -m 64M -u root -l 0.0.0.0 -p 11211 -c 256 -P /tmp/memcached.pid
#/usr/local/memcached/bin/memcached -d -m 64M -u root -l 0.0.0.0 -p 11211
# /usr/local/memcached/bin/memcached -d -m 64M -u root -l 192.168.0.200 -p 11211 -c 256 -P /tmp/memcached.pid 

链接

telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
// 以上为正常状态 // 这是一条完整的创建命令
set foot
bar
// 记得按回车键 End set foo 保存命令
bar 数据
STORED 结果
get foo 取得命令
VALUE foo 数据
bar 数据
END 结束行
quit 退出

监听状态

netstat -tnlp

修改监听端口为0.0.0.0

/usr/local/memcached/bin/memcached -d -m  -u root -l 0.0.0.0 -p  -c  -P /tmp/mem