MemcacheQ安装及使用

来源:互联网 发布:arksz410788k数据手册 编辑:程序博客网 时间:2024/04/30 09:40

一. 安装

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时,可以手动指定安装路径:<pre name="code" class="literal-block">../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时,可以手动指定安装路径:<pre name="code" class="literal-block">./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 则需<span style="color:#000000;">--with-bdb=/usr/local/BerkeleyDB.5.3</span> 指定berkeleyDb库的路径

二.使用

启动memcacheQ

  1. 使用memcacheq -h 的命令来查看命令行选项
  2. 启动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\nSTORED\r\n

取出队列:

get <queue name>\r\nVALUE <queue name> <flags> <message_len>\r\n<your message body will come here>\r\nEND\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


本文参考网址:

http://www.niutian365.com/blog/article.asp?id=463

http://web2.0coder.com/archives/197

http://www.cnblogs.com/sunzy/archive/2012/04/13/2446234.html

官方网站:

http://memcachedb.org/memcacheq/


0 0
原创粉丝点击