[lindows@B2Cmonitor ~]$ /usr/local/bin/memcached -h
memcached 1.4.5
-p <num> TCP port number to listen on (default: 11211)
-U <num> UDP port number to listen on (default: 11211, 0 is off)
-s <file> UNIX socket path to listen on (disables network support)
-a <mask> access mask for UNIX socket, in octal (default: 0700)
-l <ip_addr> interface to listen on (default: INADDR_ANY, all addresses)
-d run as a daemon
-r maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num> max memory to use for items in megabytes (default: 64 MB)
-M return error on memory exhausted (rather than removing items)
-c <num> max simultaneous connections (default: 1024)
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u <username> user;
under sh this is done with 'ulimit -S -l NUM_KB').
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-vvv extremely verbose (also print internal state transitions)
-h print this help and exit
-i print memcached and libevent license
-P <file> save PID in <file>, only used with -d option
-f <factor> chunk size growth factor (default: 1.25)
-n <bytes> minimum space allocated for key+value+flags (default: 48)
-L Try to use large memory pages (if available). Increasing
the memory page size could reduce the number of TLB misses
and improve the performance. In order to get large pages
from the OS, memcached will allocate the total item-cache
in one large chunk.
-D <char> Use <char> as the delimiter between key prefixes and IDs.
This is used for per-prefix stats reporting. The default is
":" (colon). If this option is specified, stats collection
is turned on automatically; if not, then it may be turned on
by sending the "stats detail on" command to the server.
-t <num> number of threads to use (default: 4)
-R Maximum number of requests per event, limits the number of
requests process for a given connection to prevent
starvation (default: 20)
-C Disable use of CAS
-b Set the backlog queue limit (default: 1024)
-B Binding protocol - one of ascii, binary, or auto (default)
-I Override the size of each slab page. Adjusts max item size
(default: 1mb, min: 1k, max: 128m)
lindowsmatoMacBook-Pro:~ lindows$telnet 192.168.100.149 11211
Trying 192.168.100.149...
Connected to 192.168.100.149.
Escape character is '^]'.
ERROR
stats
STAT pid 21251
STAT uptime 12550645
STAT time 1320139198
STAT version 1.4.5
STAT pointer_size 64
STAT rusage_user 10126.795493
STAT rusage_system 21859.064917
STAT curr_connections 216
STAT total_connections 5374458
STAT connection_structures 426
STAT cmd_get 684113237
STAT cmd_set 2941276
STAT cmd_flush 0
STAT get_hits 683389325
STAT get_misses 723912
STAT delete_misses 520993
STAT delete_hits 51931
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 22365116565
STAT bytes_written 960876073524
STAT limit_maxbytes 3145728000
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 313173
STAT curr_items 260
STAT total_items 2941276
STAT evictions 0
STAT reclaimed 467616
END
ERROR quit
Connection closed by foreign host.
lindowsmatoMacBook-Pro:~ lindows$
[iyunv@B2Cmonitor lib]# ls -l/usr/local/lib
total 4980
lrwxrwxrwx 1 root root 21 Jun 9 10:48 libevent-2.0.so.5 -> libevent-2.0.so.5.1.0
-rwxr-xr-x 1 root root 946708 Jun 9 10:48 libevent-2.0.so.5.1.0
-rw-r--r-- 1 root root 1541136 Jun 9 10:48 libevent.a
lrwxrwxrwx 1 root root 26 Jun 9 10:48 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.0
-rwxr-xr-x 1 root root 555297 Jun 9 10:48 libevent_core-2.0.so.5.1.0
-rw-r--r-- 1 root root 930318 Jun 9 10:48 libevent_core.a
-rwxr-xr-x 1 root root 977 Jun 9 10:48 libevent_core.la
lrwxrwxrwx 1 root root 26 Jun 9 10:48 libevent_core.so -> libevent_core-2.0.so.5.1.0
lrwxrwxrwx 1 root root 27 Jun 9 10:48 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.0
-rwxr-xr-x 1 root root 413593 Jun 9 10:48 libevent_extra-2.0.so.5.1.0
-rw-r--r-- 1 root root 610890 Jun 9 10:48 libevent_extra.a
-rwxr-xr-x 1 root root 984 Jun 9 10:48 libevent_extra.la
lrwxrwxrwx 1 root root 27 Jun 9 10:48 libevent_extra.so -> libevent_extra-2.0.so.5.1.0
-rwxr-xr-x 1 root root 942 Jun 9 10:48 libevent.la
lrwxrwxrwx 1 root root 30 Jun 9 10:48 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.0
-rwxr-xr-x 1 root root 18094 Jun 9 10:48 libevent_pthreads-2.0.so.5.1.0
-rw-r--r-- 1 root root 18678 Jun 9 10:48 libevent_pthreads.a
-rwxr-xr-x 1 root root 1005 Jun 9 10:48 libevent_pthreads.la
lrwxrwxrwx 1 root root 30 Jun 9 10:48 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.0
lrwxrwxrwx 1 root root 21 Jun 9 10:48 libevent.so -> libevent-2.0.so.5.1.0
drwxr-xr-x 2 root root 4096 Jun 9 10:48 pkgconfig
[iyunv@B2Cmonitor lib]# ls -l /usr/local/lib/pkgconfig/
total 8
-rw-r--r-- 1 root root 333 Jun 9 10:48 libevent.pc
-rw-r--r-- 1 root root 370 Jun 9 10:48 libevent_pthreads.pc http://pecl.php.net/package/memcache
http://downloads.php.net/pierre/
http://sunney2010.iyunv.com/blog/656905
http://hi.baidu.com/%D6%B0%B3%A1%D0%C2%CA%D6%B9%FE%B9%FE/blog/item/1765f3d6c7763ad4a144dfda.html
http://www.cnblogs.com/daviyang/archive/2010/04/16/1859385.html
http://hi.baidu.com/baijunhui/blog/item/e395ddd40804b90ca08bb769.html/cmtid/ddde05433540ce1f9213c6cc
http://pecl.php.net/package/memcache
http://www.360doc.com/content/10/1210/15/59865_76785815.shtml
http://www.it118.org/Specials/c1b83237-8710-472c-8ceb-dd3059340f7d/9ff63b86-6629-4a99-8162-84506ccf3c06.htm
http://hi.baidu.com/lzyu/blog/item/05eac813dba80d045baf5364.html
http://hi.baidu.com/%D2%BB%D2%B3%B0%C9/blog/item/1ec6ed79ced80de20bd18759.html
http://hi.baidu.com/baijunhui/blog/item/e395ddd40804b90ca08bb769.html
http://my.oschina.net/wdlinux/blog/8993
http://www.monkey.org/~provos/libevent/ http://www.danga.com/memcached/apis.bml
Java API
A Java API is maintained by Greg Whalinfrom Meetup.com. You can find that library here:
http://www.whalin.com/memcached/-- Java API for memcached
An improved Java API maintained by Dustin Sallings is alsoavailable. Aggressively optimised, ability to run async, supportsbinary protocol, etc. See site for details:
http://bleu.west.spy.net/~dustin/projects/memcached/-- Improved Java API for memcached
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是100MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.36.200,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,我们这里统一使用11211
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定。
-P是设置保存Memcache的pid文件,我这里是保存在/tmp/memcached.pid,
2)、如果要结束Memcache进程,执行:
[iyunv@localhost]# kill cat /tmp/memcached.pid
6、 监测是否启动成功方式
我们可以使用telnet来对我们的memcache服务器进行访问
例如:telnet 192.168.36.199 11211 (访问的是192.168.36.199这个ip的11211端口)
连接上后,直接敲击stats命令看当前缓存服务器状态
7、 设定memcache的telnet访问限制
请限定telnet的访问,使之只能在中转机上访问
8、 memcache的常见概念
memcached会预先分配内存,memcached分配内存方式称之为allocator,首先,这里有3个概念:
1 slab
2 page
3 chunk
解释一下,一般来说一个memcahced进程会预先将自己划分为若干个slab,每个slab下又有若干个page,每个page下又有多个chunk,如果我们把这3个咚咚看作是object得话,这是两个一对多得关系。再一般来说,slab得数量是有限得,几个,十几个,或者几十个,这个跟进程配置得内存有关。而每个slab下得page默认情况是1m,也就是说如果一个slab占用100m得内存得话,那么默认情况下这个slab所拥有得page得个数就是100,而chunk就是我们得数据存放得最终地方。
9、 Memcache的常用命令
Memcache常见的命令都在协议文件上:安装文件的的doc目录下的protocol.txt文件中有详细说明
1)、查询状态命令:stats:
Name Type Meaning
----------------------------------
pid 32u Process id of this server process
uptime 32u Number of seconds this server has been running
time 32u current UNIX time according to the server
version string Version string of this server
pointer_size 32 Default size of pointers on the host OS
(generally 32 or 64)
rusage_user 32u:32u Accumulated user time for this process
(seconds:microseconds)
rusage_system 32u:32u Accumulated system time for this process
(seconds:microseconds)
curr_items 32u Current number of items stored by the server
total_items 32u Total number of items stored by this server
ever since it started
bytes 64u Current number of bytes used by this server
to store items
curr_connections 32u Number of open connections
total_connections 32u Total number of connections opened since
the server started running
connection_structures 32u Number of connection structures allocated
by the server
cmd_get 64u Cumulative number of retrieval requests
cmd_set 64u Cumulative number of storage requests
get_hits 64u Number of keys that have been requested and
found present
get_misses 64u Number of items that have been requested
and not found
evictions 64u Number of valid items removed from cache
to free memory for new items
bytes_read 64u Total number of bytes read by this server
from network
bytes_written 64u Total number of bytes sent by this server to
network
limit_maxbytes 32u Number of bytes this server is allowed to
use for storage.
threads 32u Number of worker threads requested.
(see doc/threads.txt)
2)、查询版本号 version
3)、退出命令 quit
4)、显示各个slab的信息,包括chunk的大小、数目、使用情况等:stats slabs5)、显示各个slab中item的数目和最老item的年龄(最后一次访问距离现在的秒数):stats items
6)、显示内存分配:stats malloc
7)、清空缓存数据(其实是将所有缓存数据标记为过期):flush_all
end