国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

MemcacheQ安裝及使用方法

2024-09-01 13:50:54
字體:
來源:轉載
供稿:網友

一. 安裝
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-threadsmakemake 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

使用memcacheq做異步隊列,做個簡單的生產者-消費者模型。生產者將數據寫入mq中,消費者異步去隊列中去取數據,進而進一步的消費處理數據。

#!/usr/bin/env python#-*- coding:utf8 -*- import sysimport timeimport random import memcache mc = memcache.Client(["%s:%s"%("127.0.0.1", "22202")])queue_name = "q1"def putter():  count = 0  while True:    data = "hello%d"%(count)    mc.set(queue_name, data)    print "put ", data    count += 1    time.sleep(random.randint(1, 10)) def process_data(data):  print "processing data :", data def getter():  while True:    data = mc.get(queue_name)    if data:      process_data(data)    else:      print "no message, sleep for a while ..."      time.sleep(30) if __name__ == "__main__":  if len(sys.argv) != 2:    print "Wrong arg numbers"  else:    cmd = sys.argv[1]    if cmd == "put": putter()    elif cmd == "get": getter()    else: print "wrong cmd"

在使用時,開兩個終端模擬兩個進程,在一個終端中運行

python mqdemo.py put

來模擬生產者;另一個終端中運行

python mqdemo.py get

模擬消費者。

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 枣阳市| 射阳县| 秦皇岛市| 精河县| 贡嘎县| 丰原市| 南川市| 灵武市| 龙南县| 陆丰市| 高台县| 罗城| 沛县| 余干县| 远安县| 儋州市| 湛江市| 桐梓县| 四子王旗| 鸡西市| 剑河县| 临湘市| 柏乡县| 永昌县| 南城县| 莱西市| 栾川县| 阜平县| 潜江市| 都江堰市| 江陵县| 五莲县| 奉新县| 林口县| 宾川县| 疏勒县| 邳州市| 丹棱县| 侯马市| 揭东县| 昌乐县|