天天看點

Linux下memcached-1.4.20安裝 , 檢視狀态

一:安裝

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

  1. [email protected]:/home/shirdrn# tar -xvzf libevent-2.0.16-stable.tar.gz   
  2. [email protected]:/home/shirdrn# cd libevent-2.0.16-stable/  
  3. [email protected]:/home/shirdrn/libevent-2.0.16-stable# ./configure   
  4. [email protected]:/home/shirdrn/libevent-2.0.16-stable# make  
  5. [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

  1. lrwxrwxrwx  1 root root       21 2011-12-15 14:52 libevent-2.0.so.5 -> libevent-2.0.so.5.1.4  
  2. -rwxr-xr-x  1 root root  1072325 2011-12-15 14:52 libevent-2.0.so.5.1.4  
  3. -rw-r--r--  1 root root  1683924 2011-12-15 14:52 libevent.a  
  4. lrwxrwxrwx  1 root root       26 2011-12-15 14:52 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.4  
  5. -rwxr-xr-x  1 root root   646606 2011-12-15 14:52 libevent_core-2.0.so.5.1.4  
  6. -rw-r--r--  1 root root  1045954 2011-12-15 14:52 libevent_core.a  
  7. -rwxr-xr-x  1 root root      974 2011-12-15 14:52 libevent_core.la  
  8. lrwxrwxrwx  1 root root       26 2011-12-15 14:52 libevent_core.so -> libevent_core-2.0.so.5.1.4  
  9. lrwxrwxrwx  1 root root       27 2011-12-15 14:52 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.4  
  10. -rwxr-xr-x  1 root root   450238 2011-12-15 14:52 libevent_extra-2.0.so.5.1.4  
  11. -rw-r--r--  1 root root   638042 2011-12-15 14:52 libevent_extra.a  
  12. -rwxr-xr-x  1 root root      981 2011-12-15 14:52 libevent_extra.la  
  13. lrwxrwxrwx  1 root root       27 2011-12-15 14:52 libevent_extra.so -> libevent_extra-2.0.so.5.1.4  
  14. -rwxr-xr-x  1 root root      939 2011-12-15 14:52 libevent.la  
  15. lrwxrwxrwx  1 root root       29 2011-12-15 14:52 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.4  
  16. -rwxr-xr-x  1 root root    97847 2011-12-15 14:52 libevent_openssl-2.0.so.5.1.4  
  17. -rw-r--r--  1 root root   131388 2011-12-15 14:52 libevent_openssl.a  
  18. -rwxr-xr-x  1 root root     1010 2011-12-15 14:52 libevent_openssl.la  
  19. lrwxrwxrwx  1 root root       29 2011-12-15 14:52 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.4  
  20. lrwxrwxrwx  1 root root       30 2011-12-15 14:52 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.4  
  21. -rwxr-xr-x  1 root root    22414 2011-12-15 14:52 libevent_pthreads-2.0.so.5.1.4  
  22. -rw-r--r--  1 root root    19526 2011-12-15 14:52 libevent_pthreads.a  
  23. -rwxr-xr-x  1 root root     1002 2011-12-15 14:52 libevent_pthreads.la  
  24. lrwxrwxrwx  1 root root       30 2011-12-15 14:52 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.4  
  25. 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

  1. [email protected]:/home/shirdrn# tar -xvzf memcached-1.4.10.tar.gz  
  2. [email protected]:/home/shirdrn# cd memcached-1.4.10/  
  3. [email protected]:/home/shirdrn/memcached-1.4.10# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local  
  4. [email protected]:/home/shirdrn/memcached-1.4.10# make  
  5. [email protected]:/home/shirdrn/memcached-1.4.10# make install  

2、測試memcached-1.4.10安裝是否成功:

[plain]  view plain copy

  1. [email protected]:/usr/local# ls -al /usr/local/memcached/bin/mem*  
  2. -rwxr-xr-x 1 root root 365926 2011-12-15 14:54 /usr/local/memcached/bin/memcached  

啟動memcached服務:

[plain]  view plain copy

  1. /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

  1. [email protected]:/home/shirdrn/memcached-1.4.10# /usr/local/memcached/bin/memcached -help  
  2. memcached 1.4.10  
  3. -p <num>      TCP port number to listen on (default: 11211)  
  4. -U <num>      UDP port number to listen on (default: 11211, 0 is off)  
  5. -s <file>     UNIX socket path to listen on (disables network support)  
  6. -a <mask>     access mask for UNIX socket, in octal (default: 0700)  
  7. -l <addr>     interface to listen on (default: INADDR_ANY, all addresses)  
  8.               <addr> may be specified as host:port. If you don't specify  
  9.               a port number, the value you specified with -p or -U is  
  10.               used. You may specify multiple addresses separated by comma  
  11.               or by using -l multiple times  
  12. -d            run as a daemon  
  13. -r            maximize core file limit  
  14. -u <username> assume identity of <username> (only when run as root)  
  15. -m <num>      max memory to use for items in megabytes (default: 64 MB)  
  16. -M            return error on memory exhausted (rather than removing items)  
  17. -c <num>      max simultaneous connections (default: 1024)  
  18. -k            lock down all paged memory.  Note that there is a  
  19.               limit on how much memory you may lock.  Trying to  
  20.               allocate more than that would fail, so be sure you  
  21.               set the limit correctly for the user you started  
  22.               the daemon with (not for -u <username> user;  
  23.               under sh this is done with 'ulimit -S -l NUM_KB').  
  24. -v            verbose (print errors/warnings while in event loop)  
  25. -vv           very verbose (also print client commands/reponses)  
  26. -vvv          extremely verbose (also print internal state transitions)  
  27. -h            print this help and exit  
  28. -i            print memcached and libevent license  
  29. -P <file>     save PID in <file>, only used with -d option  
  30. -f <factor>   chunk size growth factor (default: 1.25)  
  31. -n <bytes>    minimum space allocated for key+value+flags (default: 48)  
  32. -L            Try to use large memory pages (if available). Increasing  
  33.               the memory page size could reduce the number of TLB misses  
  34.               and improve the performance. In order to get large pages  
  35.               from the OS, memcached will allocate the total item-cache  
  36.               in one large chunk.  
  37. -D <char>     Use <char> as the delimiter between key prefixes and IDs.  
  38.               This is used for per-prefix stats reporting. The default is  
  39.               ":" (colon). If this option is specified, stats collection  
  40.               is turned on automatically; if not, then it may be turned on  
  41.               by sending the "stats detail on" command to the server.  
  42. -t <num>      number of threads to use (default: 4)  
  43. -R            Maximum number of requests per event, limits the number of  
  44.               requests process for a given connection to prevent   
  45.               starvation (default: 20)  
  46. -C            Disable use of CAS  
  47. -b            Set the backlog queue limit (default: 1024)  
  48. -B            Binding protocol - one of ascii, binary, or auto (default)  
  49. -I            Override the size of each slab page. Adjusts max item size  
  50.               (default: 1mb, min: 1k, max: 128m)  
  51. -o            Comma separated list of extended or experimental options  
  52.               - (EXPERIMENTAL) maxconns_fast: immediately close new  
  53.                 connections if over maxconns limit  
  54.               - hashpower: An integer multiplier for how large the hash  
  55.                 table should be. Can be grown at runtime if not big enough.  
  56.                 Set this based on "STAT hash_power_level" before a   
  57.                 restart.  

下面看一下,如何檢視memcached程序啟動是否成功,可以通過檢視程序資訊來确定,如下所示:

[email protected]:/home/shirdrn/memcached-1.4.10# ps aux | grep memcached

[plain]  view plain copy

  1. 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  
  2. 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

  1. [email protected]:/home/shirdrn/memcached-1.4.10# netstat -nap | grep 19830  
  2. tcp        0      0 192.168.0.184:19830     0.0.0.0:*               LISTEN      10402/memcached   
  3. 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

  1. [email protected]:/home/shirdrn/memcached-1.4.10# kill `cat /tmp/memcached.pid`  

或者:

直接通過ps擷取到程序号,然後kill掉該程序即可。

轉自: http://blog.csdn.net/shirdrn/article/details/7074303