1、下載, memcached需要先安裝libevent
   memcached的下載地址:http://danga.com/memcached/download.bml
   libevent的下載地址 :http://www.monkey.org/~provos/libevent/

2、安裝libevent

# tar xvf libevent-1.4.4-stable.tar.gz     
#
 cd libevent-1.4.4-stable    
#
 ./configure --prefix= /opt/cuix/3rdParty/libevent-1.4.4    
#
 make    
#
 make install

   檢查是否安裝成功:

#cd /opt/cuix/3rdParty/libevent-1.4.4/lib

   如果有:
   libevent-1.4.so.2 
   libevent-1.4.so.2.0.0 
   libevent.a 
   libevent.la 
   libevent.so
   這幾個文件存在,說明安裝成功。

3、安裝memcached
   

# tar xvf memcached-1.2.5.tar.gz     
#
 cd memcached-1.2.5   
#
 ./configure --with-libevent=/opt/cuix/3rdParty/libevent-1.4.4 
         --prefix=/opt/cuix/3rdParty/memcached-1.2.5    
# make    
#
 make install

   
   檢查是否安裝成功:

# cd 3rdParty/memcached-1.2.5/bin

   如果memcached 和memcached-debug這2個文件存在,說明安裝成功

4、執行

# cd /opt/cuix/3rdParty/memcached-1.2.5/bin    
#
 ./memcached -h

 
   如果出現:
  

memcached 1.2.5
   -p <num>      TCP port number to listen on (default: 
11211)
   -U <num>      UDP port number to listen on (default: 
0, 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 is INDRR_ANY
   -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 is 64 MB
   -M            return error on memory exhausted (rather than removing items)
   -c <num>      max simultaneous connections
, default is 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)
   -h            print this help and exit
   -i            print memcached and libevent license
   -b            run a managed instanced (mnemonic: buckets)
   -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 

    說明安裝成功,并且路徑配置正確。
   有可能會出現:

memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

   說明沒有找到文件:libevent-1.4.so.2

   解決辦法:
   將libevent-1.4.so.2拷貝到任何一個列出的lib下或者軟鏈接就可以了。
   或者 修改.profile文件。加入:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/opt/cuix/3rdParty/libevent-1.4.4/lib 

  
   啟動服務:

./memcached --10 -u cuix -10.3.2.36 -18887 -256 -/tmp/memcached.pid

   
   參數說明:
    -d選項是啟動一個守護進程
    -m是分配給Memcache使用的內存數量,單位是MB,我這里是10MB
    -u是運行Memcache的用戶,我這里是root
    -l是監聽的服務器IP地址
    -p是設置Memcache監聽的端口,最好是1024以上的端口
    -c選項是最大運行的并發連接數,默認是1024,按照你服務器的負載量來設定
    -P是設置保存Memcache的pid文件

    停止服務:
    用# ps -e 查看進程,# kill pid memcached的進程號。