一:安裝
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、按Enter鍵
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的過程如下所示:
[plain] view plain copy
- [email protected]:/home/shirdrn# tar -xvzf libevent-2.0.16-stable.tar.gz
- [email protected]:/home/shirdrn# cd libevent-2.0.16-stable/
- [email protected]:/home/shirdrn/libevent-2.0.16-stable# ./configure
- [email protected]:/home/shirdrn/libevent-2.0.16-stable# make
- [email protected]:/home/shirdrn/libevent-2.0.16-stable# make install
安裝完成以後,通過下面的方式來驗證是否安裝成功:
[email protected]:/usr/local# ls -al /usr/local/lib | grep libevent
[plain] view plain copy
- 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的過程,如下所示:
[plain] view plain copy
- [email protected]:/home/shirdrn# tar -xvzf memcached-1.4.10.tar.gz
- [email protected]:/home/shirdrn# cd memcached-1.4.10/
- [email protected]:/home/shirdrn/memcached-1.4.10# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local
- [email protected]:/home/shirdrn/memcached-1.4.10# make
- [email protected]:/home/shirdrn/memcached-1.4.10# make install
2、測試memcached-1.4.10安裝是否成功:
[plain] view plain copy
- [email protected]:/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
啟動memcached服務:
[plain] view plain copy
- /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幫助資訊,如下所示:
[plain] view plain copy
- [email protected]:/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程序啟動是否成功,可以通過檢視程序資訊來确定,如下所示:
[email protected]:/home/shirdrn/memcached-1.4.10# ps aux | grep memcached
[plain] view plain copy
- 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程序占用,如下所示:
[plain] view plain copy
- [email protected]:/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檔案中,可以執行如下指令來終止服務:
[plain] view plain copy
- [email protected]:/home/shirdrn/memcached-1.4.10# kill `cat /tmp/memcached.pid`
或者:
直接通過ps擷取到程序号,然後kill掉該程序即可。
轉自: http://blog.csdn.net/shirdrn/article/details/7074303