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
這幾個(gè)文件存在,說(shuō)明安裝成功。
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個(gè)文件存在,說(shuō)明安裝成功
4、執(zhí)行
# cd /opt/cuix/3rdParty/memcached-1.2.5/bin
# ./memcached -h
如果出現(xiàn):
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

說(shuō)明安裝成功,并且路徑配置正確。
有可能會(huì)出現(xiàn):
memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
說(shuō)明沒(méi)有找到文件:libevent-1.4.so.2
解決辦法:
將libevent-1.4.so.2拷貝到任何一個(gè)列出的lib下或者軟鏈接就可以了。
或者 修改.profile文件。加入:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/opt/cuix/3rdParty/libevent-1.4.4/lib
啟動(dòng)服務(wù):
./memcached -d -m 10 -u cuix -l 10.3.2.36 -p 18887 -c 256 -P /tmp/memcached.pid
參數(shù)說(shuō)明:
-d選項(xiàng)是啟動(dòng)一個(gè)守護(hù)進(jìn)程
-m是分配給Memcache使用的內(nèi)存數(shù)量,單位是MB,我這里是10MB
-u是運(yùn)行Memcache的用戶,我這里是root
-l是監(jiān)聽(tīng)的服務(wù)器IP地址
-p是設(shè)置Memcache監(jiān)聽(tīng)的端口,最好是1024以上的端口
-c選項(xiàng)是最大運(yùn)行的并發(fā)連接數(shù),默認(rèn)是1024,按照你服務(wù)器的負(fù)載量來(lái)設(shè)定
-P是設(shè)置保存Memcache的pid文件
停止服務(wù):
用# ps -e 查看進(jìn)程,# kill pid memcached的進(jìn)程號(hào)。