MemcacheQ安装及使用

[size=medium]MemcacheQ安装及使用


一. 安装
MemcacheQ 是一个简单的分布式队列服务,它的运行依赖于BerkeleyDB 和 libevent,所以需要先安装BerkeleyDB和libevent.
Berkeley DB 4.7 or later

Download from <http://www.oracle.com/database/berkeley-db/db/index.html>
How to install BerkeleyDB:
$tar -xvzf db-5.3.21.tar.gz
$cd db-5.3.21/
$cd build_unix/
$../dist/configure
$make
$make install

安装BerkeleyDB时,可以手动指定安装路径:
../dist/configure --prefix=/usr/local/berkeleydb
不指定的话,默认安装在:/usr/local/BerkeleyDB.5.3
libevent 1.4.x or later

先检查libevent 是否已经安装:
#rpm -qa|grep libevent
libevent-devel-2.0.10-2.fc15.x86_64
libevent-2.0.10-2.fc15.x86_64
libevent-2.0.10-2.fc15.i686
或者:
ls -al /usr/lib |grep libevent
如果还没有安装:
Download from <http://monkey.org/~provos/libevent/>
How to install libevent:
$tar -xvzf libevent-1.4.x-stable.tar.gz
$cd libevent-1.4.x-stable
$./configure
$make
$make install
安装libevent时,可以手动指定安装路径:
./configure --prefix=/usr/local/libevent
不指定的话,默认安装在:/usr/lib64(64位系统)或者/usr/lib(32位系统)

memcacheQ

下载软件包:http://code.google.com/p/memcacheq/downloads/list
解压缩,cd进目录
./configure --enable-threads
make
make install
configure 时,如果libevent 不是安装在默认目录,需--with--libevent=/usr/local/libevent指定libevent的安装目录
若没有将
/usr/local/lib
/usr/local/BerkeleyDB.5.3/lib
添加进/etc/ld.so.conf 并运行 /sbin/ldconfig 则需--with-bdb=/usr/local/BerkeleyDB.5.3 指定berkeleyDb库的路径

二.使用
启动memcacheQ

使用memcacheq -h 的命令来查看命令行选项
启动memcacheq:memcacheq -d -u nobody -r -H /tmp/memcacheq -N -R -v -L 1024 -B 1024 > /tmp/mq_error.log 2>&1
启动时需-u 参数,指定运行memcacheQ的用户,且指定的用户必须有数据文件的读写权限,如这里的/tmp/memcacheQ目录,否则不能启动

命令行使用memcacheQ
telnet 127.0.0.1 22202
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.

只有两个命令可以在命令行下使用memcacheQ
写对列:
set <queue name> <flags> 0 <message_len>\r\n
<put your message body here>\r\n
STORED\r\n
取出队列:
get <queue name>\r\n
VALUE <queue name> <flags> <message_len>\r\n
<your message body will come here>\r\n
END\r\n
与memcache协议基本一致,只是把key name换成queue name,而且在set的命令中,忽略了expire_time的参数。mq的数据存储是存在berkeleyDB中,做了持久化存储,没有内存的过期时间。
示例:
telnet 127.0.0.1 22202
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
set q4 0 0 5
hello
STORED
set q4 0 0 5
world
STORED
stats queue
STAT q4 2/0
END
get q4
VALUE q4 0 5
hello
END
stats queue
STAT q4 2/1
END
三.安装使用过程中可能出现的错误
1.编译出现错误:checking for library containing db_create... no
configure: error: cannot find libdb.so in /usr/local/BerkeleyDB.5.3/lib
需要修改 configure 中的BerkeleyDB中的预编译参数vim configure找到bdbdir="/usr/local/berkeleydb"改为
bdbdir="/usr/local/BerkeleyDB.5.3"再次编译

2.configure: error: cannot find libdb.so in /usr/local/BerkeleyDB.5.3/lib
出现此错误的原因在于没有安装BerkyleyDb,安装即可

3./usr/local/memcacheq/bin/memcachq -h
运行报:
memcacheq: error while loading shared libraries: libdb-5.3.so: cannot open shared object file: No such file or directory
解决方法:ln -s /usr/local/BerkeleyDB.5.3/lib/libdb-5.3.so /usr/lib/libdb-5.3.so
注:在64位操作系统中,需执行
ln -s /usr/local/BerkeleyDB.5.3/lib/libdb-5.3.so /usr/lib64/libdb-5.3.so[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值