一、安装
安装依赖包
libevent 是安装 memcached 的唯一前提条件。它是 memcached所依赖的异步事件通知库。
1. 下载依赖软件libevent:
[root@matser ~]#wget http://jaist.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
2. 解压压缩包:
[root@matser~]#tar -zxvf libevent-2.0.22-stable.tar.gz -C /usr/
3. 切换到解压目录:
[root@matser ~]#cd/usr/libevent-2.0.22-stable
4. 编译:
[root@matser libevent-2.0.22-stable]#./configure
5. 安装:
[root@matserlibevent-2.0.22-stable]# make&make install
安装memcache
1. 下载Memcached安装压缩包:
[root@matser ~]#wget http://www.memcached.org/files/memcached-1.4.22.tar.gz
2. 解压压缩包:
[root@matser ~]#tar -zvxf memcached-1.4.22.tar.gz -C /usr/local/
3. 切换目录到解压目录:
[root@matser ~]#cd /usr/local/memcached-1.4.22/
4. 编译:
[root@matsermemcached-1.4.22]# ./configure
5. 安装:
[root@matsermemcached-1.4.22]# make&make install
二、启动
1. 启动Memcache服务:
[root@matsermemcached-1.4.22]# memcached -d -m 128 -u root -l 192.168.1.133 -p 11211 -c 1024 -P /tmp/memcached.pid
相关参数说明:
-d 表示启动一个守护进程
-m 是分配给memcached使用的内存
-u 运行memcached的用户
-l 是memcached监听的ip
-p 是memcached监听的端口
-c memcache运行的最大并发连接数
-P 是设置memcache的pid文件
三、连接测试
Set命令创建新的键值对;
Get命令获取userID键值。