Linux 下安装 memcached 及 memcacheq的方法
一:安装memcached
1.下载memcached包
下载地址:http://www.memcached.org(最新包就在首页,点击下载就OK)
解压包:#tar-zxvfmemcached-1.4.13.tar.gz(根据自身的情况解压到目录)
进入目录:#cdmemcached-1.4.13
2.安装libevent
检查一下有没有安装libevent:ls-al/usr/lib|greplibevent
如果没有就安装libevent,下载地址:http://www.libevent.org(首页Download–Stablereleases)
解压:
#tar-zxvflibevent-***-.tar.gz
#cdlibevent-***-
#./configure--prefix=/usr
#make&&makeinstall
安装完检测下 ls-al/usr/lib|greplibevent
lrwxrwxrwx 1rootroot 2102-0620:26libevent-1.4.so.2->libevent-1.4.so.2.1.3
.................................
-rw-r--r-- 1rootroot 1183804-1314:03libevent_pthreads.a
-rwxr-xr-x 1rootroot 99604-1314:03libevent_pthreads.la
lrwxrwxrwx 1rootroot 3004-1314:03libevent_pthreads.so->libevent_pthreads-2.0.so.5.1.6
lrwxrwxrwx 1rootroot 2104-1314:03libevent.so->libevent-2.0.so.5.1.6
3.安装memcached
预安装:#./configure--prefix=/usr/local/memcached--with-libevent=/usr
注意:在没有安装libevent的情况下,会报错(Ifit'salreadyinstalled,specifyitspathusing--with-libevent=/dir/);
编译并且安装:#make&&makeinstall
OK安装成功.
启动memcached:
#/usr/local/memcached/bin/memcached-l192.168.1.144-d-p11211-unobody-m1024
说明:上面的命令中-d表示用daemon的方式启动memcached,-l和-p组合表示监听在192.168.1.144的11212端口上(如果不用-p指定端口号,则memcached将运行在11211端口 上),-u表示运行用户为nobody,-m表示为其分配1024MB的内存。
连接memcached:#telnet192.168.1.14411211
到这里memcached就已经安装好了。
增加到开机启动
#vi/etc/rc.local
增加:
/usr/local/memcached/bin/memcached-l192.168.1.144-d-p11211-unobody-m1024
二:安装memcacheq
1.下载memcacheq包
下载地址:http://code.google.com/p/memcacheq/downloads/list
解压包:#tar-zxvfmemcacheq.0.2.tar.gz(根据自身的情况解压到目录)
进入目录:#cdmemcacheq-0.2.0
2.安装BerkeleyDB
下载地址:http://www.oracle.com/technetwork/products/berkeleydb/downloads/index.html
解压包:#tar-zxvfdb-5.3.15.tar.gz(根据自身的情况解压到目录)
进入目录:#cddb-5.3.15
#cdbuild_unix
#../dist/configure--prefix=/usr/local/BerkeleyDB.5.3
#make&&makeinstall
#vi/etc/ld.so.conf
增加:
/usr/local/lib
/usr/local/BerkeleyDB.5.3/lib
#vi/etc/profile
增加
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/BerkeleyDB.5.3/lib
3.安装memcacheq(注:下文中的5.3是berkeleyDB的版本 请根据实际情况操作)
预安装:./configure--prefix=/usr/local/memcacheq--enable-threads
注意:在没有安装BerkeleyDB的情况下,会报错(configure:error:cannotfindlibdb.soin/usr/local/BerkeleyDB.5.3/lib);
#make&&makeinstall
测试:/usr/local/memcacheq/bin/memcachq-h
运行报:
memcacheq:errorwhileloadingsharedlibraries:libdb-5.3.so:cannotopensharedobjectfile:Nosuchfileordirectory
解决方法:ln-s/usr/local/BerkeleyDB.5.3/lib/libdb-5.3.so/usr/lib/libdb-5.3.so
连接:/usr/local/memcacheq/bin/memcacheq -d-r-uroot-p11212-H/var/mcq/data-N-R-v-L1024-B1024>/var/mcq/logs/mq_error.log2>&1
(/var/mcq/data必须自己创建)
#ps-ef|grepmemcacheq
root 11908 1 418:06? 00:00:00/usr/local/memcacheq/bin/memcacheq-d-r-uroot-p11212-H/var/mcq/data-N-R-v-L1024-B1024
已经开始运行.
连接到memcacheq:#telnet192.168.1.14411212
增加到开机启动
#vi/etc/rc.local
增加:/usr/local/memcacheq/bin/memcacheq -d-r-uroot-p11212-H/var/mcq/data-N-R-v-L1024-B1024>/var/mcq/logs/mq_error.log2>&1