码迷,mamicode.com
首页 > 系统相关 > 详细

01.安装Memcached

时间:2015-10-02 13:39:35      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:


1.安装Memcached

1.下载Memcached及其依赖
下载memcached-1.4.24.tar.gz和libevent-2.0.22-stable.tar.gz文件并解压如下:
  1. [lizhiwei@localhost libevent]$ tar -zxvf libevent-2.0.22-stable.tar.gz
  2. [lizhiwei@localhost Memcached]$ tar -zxvf memcached-1.4.24.tar.gz
2.安装memcached
先安装libevent:
  1. [lizhiwei@localhost libevent-2.0.22-stable]$ cd /home/lizhiwei/SoftWare/libevent/libevent-2.0.22-stable
  2. [lizhiwei@localhost libevent-2.0.22-stable]$ ./configure -prefix=/home/lizhiwei/InstallSoft/libevent
  3. [lizhiwei@localhost libevent-2.0.22-stable]$ make
  4. [lizhiwei@localhost libevent-2.0.22-stable]$ make install
安装memcached,同时需要安装中指定libevent的安装位置:
  1. [lizhiwei@localhost libevent-2.0.22-stable]$ cd /home/lizhiwei/SoftWare/Memcached/memcached-1.4.24
  2. [lizhiwei@localhost memcached-1.4.24]$ ./configure -prefix=/home/lizhiwei/InstallSoft/memcached -with-libevent=/home/lizhiwei/InstallSoft/libevent/
  3. [lizhiwei@localhost memcached-1.4.24]$ make
  4. [lizhiwei@localhost memcached-1.4.24]$ make install
此时memcached安装完成,安装路径:/home/lizhiwei/InstallSoft/memcached

2.启动Memcached

1.启动memcached并参看服务
  1. [lizhiwei@localhost memcached]$ cd /home/lizhiwei/InstallSoft/memcached/bin/
  2. [lizhiwei@localhost bin]$ ll
  3. total 356
  4. -rwxr-xr-x. 1 lizhiwei lizhiwei 360894 Oct 1 20:52 memcached
  5. [lizhiwei@localhost bin]$ ./memcached -d -m 10 -u lizhiwei -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid
  6. [lizhiwei@localhost bin]$ ps -ef | grep memcached
  7. lizhiwei 24004 1 0 20:59 ? 00:00:00 ./memcached -d -m 10 -u lizhiwei -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid
  8. lizhiwei 24018 14869 0 21:00 pts/2 00:00:00 grep memcached
  9. [lizhiwei@localhost bin]$ cat /tmp/memcached.pid
  10. 24004
  11. [lizhiwei@localhost bin]$
./memcached -d -m 10 -u lizhiwei -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid 启动命令说明:
-d 选项是启动一个守护进程
-m 是分配给Memcache使用的内存数量,单位是MB,我这里是10MB
-u 是运行Memcache的用户,我这里是lizhiwei
-l 是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1
-p 是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定
-P 是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
2.停止Memcache服务
使用kill -9 进程PID 命令停止Memcache服务
  1. [lizhiwei@localhost bin]$ ps -ef | grep memcached
  2. lizhiwei 24004 1 0 20:59 ? 00:00:00 ./memcached -d -m 10 -u lizhiwei -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid
  3. lizhiwei 24069 14869 0 21:07 pts/2 00:00:00 grep memcached
  4. [lizhiwei@localhost bin]$ kill -9 24004
  5. [lizhiwei@localhost bin]$ ps -ef | grep memcached
  6. lizhiwei 24072 14869 0 21:07 pts/2 00:00:00 grep memcached
  7. [lizhiwei@localhost bin]$
3.连接Memcache服务
  1. [lizhiwei@localhost ~]$ telnet 127.0.0.1 11211
  2. Trying 127.0.0.1...
  3. Connected to 127.0.0.1.
  4. Escape character is ‘^]‘.
  5. set name 0 64 5
  6. abcde
  7. STORED
  8. get name
  9. VALUE name 0 5
  10. abcde
  11. END
  12. quit
  13. Connection closed by foreign host.
  14. [lizhiwei@localhost ~]$
telnet 使用说明:
telnet 127.0.0.1 11211 连接到IP地址127.0.0.1,端口号11211
set name 0 64 5 格式:<command name> <key> <flags> <exptime> <bytes>
    <command name> :set/add/replace
    <key> :查找关键字
    <flags> :整型参数,客户机使用它存储关于键值对的额外信息
    <exptime> :该数据的存活时间(以秒为单位,0 表示永远) 
    <bytes> :存储字节数,注意:设置了存储大小就必须存储一样大小的数据,否则会操作失败
-------------------------------------------------------------------------------------------------------------------------------




01.安装Memcached

标签:

原文地址:http://www.cnblogs.com/LiZhiW/p/4852103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!