memcached 入门介绍
文献引用---memcached入门:
http://blog.sina.com.cn/s/blog_62c5a4810100ndl5.html
在linux上安装memcached
由于memcached安装时,需要使用libevent类库,所以先安装libevent
libevent下载网址:http://www.monkey.org/~provos/libevent/
本手册中下载的是libevent-1.4.8-stable.tar.gz版本安装步骤如下:
1.解压缩
tarxzfvlibevent-1.4.8-stable.tar.gz
2.进入到libevent-1.4.8-stable目录
cdlibevent-1.4.8-stable
3.编译,安装
./configure
make
makeinstall
注:默认安装到/usr/local/lib/目录
接下来,安装memcached
memcached下载网址:http://www.danga.com/memcached/download.bml
本手册中下载的是memcached-1.2.6.tar.gz版本
安装步骤如下:
1.解压缩
tarxzfvmemcached-1.2.6.tar.gz
2.进入到memcached-1.2.6目录
cdmemcached-1.2.6
3.编译,安装
./configure--prefix=/local/memcached
make
makeinstall
安装完成后,会在/local/memcached出现bin和share目录
进行bin目录,启动memcache
方法如下:
./memcached-d-unobody-m512127.0.0.1-p11211
此时,会报一个异常
errorwhileloadingsharedlibraries:libevent-1.4.so.2:cannotopensharedobjectfile:Nosuchfileordirectory
原因是找不到libevent-1.4.so.2类库,解决办法如下:
使用LD_DEBUG=help./memcached-v来确定加载的类库路径,方法如下:
LD_DEBUG=libs./memcached-v2>&1>/dev/null|less
则系统会显示:
linux:/local/memcached/bin#LD_DEBUG=libs./memcached-v2>&1>/dev/null|less
20421:findlibrary=libevent-1.4.so.2;searching
20421:searchcache=/etc/ld.so.cache
20421:searchpath=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686
/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib(systemsearchpath)
20421:tryingfile=/lib/tls/i686/sse2/libevent-1.4.so.2
20421:tryingfile=/lib/tls/i686/libevent-1.4.so.2
20421:tryingfile=/lib/tls/sse2/libevent-1.4.so.2
20421:tryingfile=/lib/tls/libevent-1.4.so.2
20421:tryingfile=/lib/i686/sse2/libevent-1.4.so.2
20421:tryingfile=/lib/i686/libevent-1.4.so.2
20421:tryingfile=/lib/sse2/libevent-1.4.so.2
20421:tryingfile=/lib/libevent-1.4.so.2
20421:tryingfile=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
20421:tryingfile=/usr/lib/tls/i686/libevent-1.4.so.2
20421:tryingfile=/usr/lib/tls/sse2/libevent-1.4.so.2
20421:tryingfile=/usr/lib/tls/libevent-1.4.so.2
20421:tryingfile=/usr/lib/i686/sse2/libevent-1.4.so.2
20421:tryingfile=/usr/lib/i686/libevent-1.4.so.2
20421:tryingfile=/usr/lib/sse2/libevent-1.4.so.2
20421:tryingfile=/usr/lib/libevent-1.4.so.2
20421:
./memcached:errorwhileloadingsharedlibraries:libevent-1.4.so.2:cannotopensharedobjectfile:Nosuchfileordirectory
我们看到,memcached会到很多地方去找,所以根据其它求,我们只需建一个软链接,指定到我们安装的类库上即可
方法如下:
ln-s/usr/local/lib/libevent-1.4.so.2/lib/libevent-1.4.so.2
现在可以正常启动memcached了
./memcached-d-unobody-m512127.0.0.1-p11211
到这里,看到memcached已经启动,说明安装成功。
memcache启动参数说明:
Theoptionsformemcachedare:
-l<ip_addr>
Listenon<ip_addr>;defaulttoINDRR_ANY.Thisisanimportantoptiontoconsiderasthereisnootherwaytosecuretheinstallation.Bindingtoaninternalorfirewallednetworkinterfaceissuggested.
-d
Runmemcachedasadaemon.
-u<username>
Assumetheidentityof<username>(onlywhenrunasroot).
-m<num>
Use<num>MBmemorymaxtouseforobjectstorage;thedefaultis64megabytes.
-M
Insteadofthrowingitemsfromthecachewhenmaxmemoryisreached,throwanerror
-c<num>
Use<num>maxsimultaneousconnections;thedefaultis1024.
-k
Lockdownallpagedmemory.Thisisasomewhatdangerousoptionwithlargecaches,soconsulttheREADMEandmemcachedhomepageforconfigurationsuggestions.
-p<num>
Listenonport<num>,thedefaultisport11211.
-r
Maximizecorefilelimit
-M
Disableautomaticremovalofitemsfromthecachewhenoutofmemory.Additionswillnotbepossibleuntiladequatespaceisfreedup.
-r
Raisethecorefilesizelimittothemaximumallowable.
-h
Showtheversionofmemcachedandasummaryofoptions.
-v
Beverboseduringtheeventloop;printouterrorsandwarnings.
-vv
Beevenmoreverbose;sameas-vbutalsoprintclientcommandsandresponses.
-i
Printmemcachedandlibeventlicenses.
-P<filename>
Printpidfileto<filename>,onlyusedunder-doption.