您的位置:首页 > 数据库 > Memcache

ubuntu14中 memcached安装与使用

2014-07-23 16:47 435 查看
第一步,先安装lib-event

下载lib-event  的包http://libevent.org/

下载完之后,解压安装

./configure –prefix=/usr (或 ./configure --program-prefix=/usr)  

make  

make install 

第二步,安装memcached

下载memcached的包http://www.memcached.org/downloads

下载完之后,解压安装

1、./configure

2、make

3、make install

通过命令 ls -al /usr/local/bin/mem*检测是否安装成功

默认情况下memcached安装到/usr/local/bin下。

启动memcached server,在安装目录下启动

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

root@chiwei-VirtualBox:/home/chiwei/disk/service# ls

root@chiwei-VirtualBox:/home/chiwei/disk/service# ls -al /usr/local/bin/memcached 

-rwxr-xr-x 1 root root 495978  7月 23 16:16 /usr/local/bin/memcached

root@chiwei-VirtualBox:/home/chiwei/disk/service# cd /usr/local/bin/me

-su: cd: /usr/local/bin/me: 没有那个文件或目录

root@chiwei-VirtualBox:/home/chiwei/disk/service# cd /usr/local/bin/

root@chiwei-VirtualBox:/usr/local/bin# ls

memcached

root@chiwei-VirtualBox:/usr/local/bin# ./memcached -d -c 1024 -l 127.0.0.1 -p 10101 -m 1024 -u root

root@chiwei-VirtualBox:/usr/local/bin# telnet 127.0.0.1 10101

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

stats

stats查看状态,flush_all:清楚缓存

查看memcached状态的基本命令,通过这个命令可以看到如下信息:

STAT pid 22459                             进程ID

STAT uptime 1027046                        服务器运行秒数

STAT time 1273043062                       服务器当前unix时间戳

STAT version 1.4.4                         服务器版本

STAT pointer_size 64                       操作系统字大小(这台服务器是64位的)

STAT rusage_user 0.040000                  进程累计用户时间

STAT rusage_system 0.260000                进程累计系统时间

STAT curr_connections 10                   当前打开连接数

STAT total_connections 82                  曾打开的连接总数

STAT connection_structures 13              服务器分配的连接结构数

STAT cmd_get 54                            执行get命令总数

STAT cmd_set 34                            执行set命令总数

STAT cmd_flush 3                           指向flush_all命令总数

STAT get_hits 9                            get命中次数

STAT get_misses 45                         get未命中次数

STAT delete_misses 5                       delete未命中次数

STAT delete_hits 1                         delete命中次数

STAT incr_misses 0                         incr未命中次数

STAT incr_hits 0                           incr命中次数

STAT decr_misses 0                         decr未命中次数

STAT decr_hits 0                           decr命中次数

STAT cas_misses 0                          cas未命中次数

STAT cas_hits 0                            cas命中次数

STAT cas_badval 0                          使用擦拭次数

STAT auth_cmds 0

STAT auth_errors 0

STAT bytes_read 15785                      读取字节总数

STAT bytes_written 15222                   写入字节总数

STAT limit_maxbytes 1048576                分配的内存数(字节)

STAT accepting_conns 1                     目前接受的链接数

STAT listen_disabled_num 0                

STAT threads 4                             线程数

STAT conn_yields 0

STAT bytes 0                               存储item字节数

STAT curr_items 0                          item个数

STAT total_items 34                        item总数

STAT evictions 0                           为获取空间删除item的总数

启动完之后,测试

telenet  127.0.0.1 10101

连接成功后,可以使用了

关闭memcached服务时,先查看tmp文件夹

root@chiwei-VirtualBox:~# ls

root@chiwei-VirtualBox:~# cd /tmp/

root@chiwei-VirtualBox:/tmp# ls

aptdaemon-WMCJDF                  qtsingleapp-chines-1a7c-3e8-lockfile

bjydJbU3Ux                        rpc%0049d%0043ache.data

deCgyLP7oi                        sms%0043ache.data

fcitx-socket-:0                   sni-qt_chinese-calendar_2043-z3cOqS

hsperfdata_chiwei                 sni-qt_sogou-qimpanel_2248-fTSQLu

hsperfdata_root                   sogou-qimpanel:0.pid

indicator-china-weather-1000.pid  sogou-qimpanelchiwei

jna                               ssh-Wcoq8f0CINjL

memcached.pid                     unity_support_test.1

qtsingleapp-chines-1a7c-3e8

有一个保存memcache的pid文件

kill `cat /tmp/memcached.pid`   键盘左上角的点符号

或者

root@chiwei-VirtualBox:~# ps -ef | grep memcached

root     24915  1584  0 16:36 ?        00:00:00 ./memcached -d -c 1024 -l 127.0.0.1 -p 10101 -m 1024 -u root

root     25011 10370  0 16:41 pts/15   00:00:00 grep --color=auto memcached

root@chiwei-VirtualBox:~# kill 24915

root@chiwei-VirtualBox:~# telnet 127.0.0.1 10101

Trying 127.0.0.1...

telnet: Unable to connect to remote host: Connection refused

root@chiwei-VirtualBox:~# 

memcached具体的使用,参照http://www.cnblogs.com/czh-liyu/archive/2010/04/27/1722084.html

memcached 协议  点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  存储 缓存 memcached