一:安装
1启动命令里的ip需要改,否则启动不起来 可能还得加到启动脚本里.
/usr/local/memcached/bin/memcached -d -m 200 -u root -l 10.0.2.100 -p 11211 -c 5000 -P /tmp/memcached.pid
2包有所更新
memcached-1.4.20.tar.gz
libevent-2.0.21-stable.tar.gz
二:查看
1连接
telnet 10.0.2.100 11211
2全部状态
telnet登陆后, 键入:
stats
STAT pid 22362 //memcache服务器的进程ID
STAT uptime 1469315 //服务器已经运行的秒数
STAT time 1339671194 //服务器当前的unix时间戳
STAT version 1.4.9 //memcache版本
STAT libevent 1.4.9-stable //libevent版本
STAT pointer_size 64 //当前操作系统的指针大小(32位系统一般是32bit,64就是64位操作系统)
STAT rusage_user 3695.485200 //进程的累计用户时间
STAT rusage_system 14751.273465 //进程的累计系统时间
STAT curr_connections 69 //服务器当前存储的items数量
STAT total_connections 855430 //从服务器启动以后存储的items总数量
STAT connection_structures 74 //服务器分配的连接构造数
STAT reserved_fds 20 //
STAT cmd_get 328806688 //get命令(获取)总请求次数
STAT cmd_set 75441133 //set命令(保存)总请求次数 www.2cto.com
STAT cmd_flush 34 //flush命令请求次数
STAT cmd_touch 0 //touch命令请求次数
STAT get_hits 253547177 //总命中次数
STAT get_misses 75259511 //总未命中次数
STAT delete_misses 4 //delete命令未命中次数
STAT delete_hits 565730 //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 touch_hits 0 //touch命令未命中次数
STAT touch_misses 0 //touch命令命中次数
STAT auth_cmds 0 //认证命令处理的次数
STAT auth_errors 0 //认证失败数目
STAT bytes_read 545701515844 //总读取字节数(请求字节数)
STAT bytes_written 1649639749866 //总发送字节数(结果字节数)
STAT limit_maxbytes 2147483648 //分配给memcache的内存大小(字节)
STAT accepting_conns 1 //服务器是否达到过最大连接(0/1)
STAT listen_disabled_num 0 //失效的监听数
STAT threads 4 //当前线程数
STAT conn_yields 14 //连接操作主动放弃数目
STAT hash_power_level 16 //
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 30705763
STAT evicted_unfetched 0
STAT bytes 61380700 //当前存储占用的字节数
STAT curr_items 28786 //当前存储的数据总数
STAT total_items 75441133 //启动以来存储的数据总数
STAT evictions 0 //为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)
STAT reclaimed 39957976 //已过期的数据条目来存储新数据的数
3.单条
stats items //输出各个slab中的item信息。
stats slabs//输出slab中更详细的item信息
stats sizes//输出所有item的大小和个数
四: 清空
1、连接:telnet 127.0.0.1 11211
2、按回车键
3、flush_all 后回车
控制台显示OK,表示操作成功
转自: http://blog.csdn.net/shirdrn/article/details/7074303
=========================================================================
memcache是一款流行的缓存产品,它分为两个部分:一个是运行在服务器端的memcached进程,一个是在客户端进行调用获取缓存中数据客户端,例如比较常用的PHP客户端。这里,记录一下安装服务器端的memcached的过程,比较容易。
准备软件包
- libevent-2.0.16-stable.tar.gz [http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz]
- memcached-1.4.10.tar.gz [http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz]
- memcache-3.0.6.tgz [http://pecl.php.net/get/memcache-3.0.6.tgz]
安装配置
安装libevent-2.0.16
安装libevent-2.0.16的过程如下所示:
- root@dev2:/home/shirdrn# tar -xvzf libevent-2.0.16-stable.tar.gz
- root@dev2:/home/shirdrn# cd libevent-2.0.16-stable/
- root@dev2:/home/shirdrn/libevent-2.0.16-stable# ./configure
- root@dev2:/home/shirdrn/libevent-2.0.16-stable# make
- root@dev2:/home/shirdrn/libevent-2.0.16-stable# make install
安装完成以后,通过下面的方式来验证是否安装成功:
root@dev2:/usr/local# ls -al /usr/local/lib | grep libevent
- lrwxrwxrwx 1 root root 21 2011-12-15 14:52 libevent-2.0.so.5 -> libevent-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 1072325 2011-12-15 14:52 libevent-2.0.so.5.1.4
- -rw-r--r-- 1 root root 1683924 2011-12-15 14:52 libevent.a
- lrwxrwxrwx 1 root root 26 2011-12-15 14:52 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 646606 2011-12-15 14:52 libevent_core-2.0.so.5.1.4
- -rw-r--r-- 1 root root 1045954 2011-12-15 14:52 libevent_core.a
- -rwxr-xr-x 1 root root 974 2011-12-15 14:52 libevent_core.la
- lrwxrwxrwx 1 root root 26 2011-12-15 14:52 libevent_core.so -> libevent_core-2.0.so.5.1.4
- lrwxrwxrwx 1 root root 27 2011-12-15 14:52 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 450238 2011-12-15 14:52 libevent_extra-2.0.so.5.1.4
- -rw-r--r-- 1 root root 638042 2011-12-15 14:52 libevent_extra.a
- -rwxr-xr-x 1 root root 981 2011-12-15 14:52 libevent_extra.la
- lrwxrwxrwx 1 root root 27 2011-12-15 14:52 libevent_extra.so -> libevent_extra-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 939 2011-12-15 14:52 libevent.la
- lrwxrwxrwx 1 root root 29 2011-12-15 14:52 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 97847 2011-12-15 14:52 libevent_openssl-2.0.so.5.1.4
- -rw-r--r-- 1 root root 131388 2011-12-15 14:52 libevent_openssl.a
- -rwxr-xr-x 1 root root 1010 2011-12-15 14:52 libevent_openssl.la
- lrwxrwxrwx 1 root root 29 2011-12-15 14:52 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.4
- lrwxrwxrwx 1 root root 30 2011-12-15 14:52 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.4
- -rwxr-xr-x 1 root root 22414 2011-12-15 14:52 libevent_pthreads-2.0.so.5.1.4
- -rw-r--r-- 1 root root 19526 2011-12-15 14:52 libevent_pthreads.a
- -rwxr-xr-x 1 root root 1002 2011-12-15 14:52 libevent_pthreads.la
- lrwxrwxrwx 1 root root 30 2011-12-15 14:52 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.4
- lrwxrwxrwx 1 root root 21 2011-12-15 14:52 libevent.so -> libevent-2.0.so.5.1.4
安装memcached-1.4.10
1、安装memcached-1.4.10的过程,如下所示:- root@dev2:/home/shirdrn# tar -xvzf memcached-1.4.10.tar.gz
- root@dev2:/home/shirdrn# cd memcached-1.4.10/
- root@dev2:/home/shirdrn/memcached-1.4.10# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local
- root@dev2:/home/shirdrn/memcached-1.4.10# make
- root@dev2:/home/shirdrn/memcached-1.4.10# make install
- root@dev2:/usr/local# ls -al /usr/local/memcached/bin/mem*
- -rwxr-xr-x 1 root root 365926 2011-12-15 14:54 /usr/local/memcached/bin/memcached
- /usr/local/memcached/bin/memcached -d -m 10 -u root -l 192.168.0.184 -p 19830 -c 5000 -P /tmp/memcached.pid
执行上面的命令行,将启动memcached服务进程,并且进程号存储在/tmp/memcached.pid文件中。
上述命令行中选项的含义简介如下:
- -d 指定memcached进程作为一个守护进程启动
- -m 指定分配给memcached使用的内存,单位是MB
- -u 指定运行memcached的用户
- -l 指定监听的服务器IP地址,如果有多个地址的话,使用逗号分隔,格式可以为“IP地址:端口号”,例如:-l 192.168.0.184:19830,192.168.0.195:13542;端口号也可以通过-p选项指定
- -p 指定memcached监听的端口,要保证该端口号未被占用
- -c 指定是最大运行的并发连接数,默认是1024
- -P 指定保存memcached进程的pid文件
你也可以通过如下命令行获取memcached帮助信息,如下所示:
- root@dev2:/home/shirdrn/memcached-1.4.10# /usr/local/memcached/bin/memcached -help
- memcached 1.4.10
- -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 <addr> interface to listen on (default: INADDR_ANY, all addresses)
- <addr> may be specified as host:port. If you don't specify
- a port number, the value you specified with -p or -U is
- used. You may specify multiple addresses separated by comma
- or by using -l multiple times
- -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)
- -o Comma separated list of extended or experimental options
- - (EXPERIMENTAL) maxconns_fast: immediately close new
- connections if over maxconns limit
- - hashpower: An integer multiplier for how large the hash
- table should be. Can be grown at runtime if not big enough.
- Set this based on "STAT hash_power_level" before a
- restart.
下面看一下,如何查看memcached进程启动是否成功,可以通过查看进程信息来确定,如下所示:
root@dev2:/home/shirdrn/memcached-1.4.10# ps aux | grep memcached
- root 10402 0.0 0.0 126740 1060 ? Ssl 15:03 0:00 /usr/local/memcached/bin/memcached -d -m 10 -u root -l 192.168.0.184 -p 19830 -c 5000 -P /tmp/memcached.pid
- root 10411 0.0 0.0 12692 1068 pts/7 S+ 15:04 0:00 grep --color=auto memcached
可见当前存在memcached进程,进程号为10402。
再查看一下memcached监听的端口是否被memcached进程占用,如下所示:
- root@dev2:/home/shirdrn/memcached-1.4.10# netstat -nap | grep 19830
- tcp 0 0 192.168.0.184:19830 0.0.0.0:* LISTEN 10402/memcached
- udp 0 0 192.168.0.184:19830 0.0.0.0:* 10402/memcached
可见,memcached可以通过端口19830向外部(memcache客户端)提供缓存服务。
3、终止memcached服务
因为我们已经将memcached的进程号存储到/tmp/memcached.pid文件中,可以执行如下命令来终止服务:
- root@dev2:/home/shirdrn/memcached-1.4.10# kill `cat /tmp/memcached.pid`
直接通过ps获取到进程号,然后kill掉该进程即可。