1.memcachedb安装
根据memcachedb介绍、编译以及安装,试装memcachedb。BerkeleyDB页面上提供的是oracle的官方地址,但下载要注册。。。找朋友要了个4.6版本的装,装memcachedb-1.2.1-beta会提示:
configure: error: cannot find libdb.so in /usr/local/BerkeleyDB.4.7/lib
看了一下日志,http://memcachedb.googlecode.com/svn/trunk/ChangeLog,发现下图:
在memcachedb的configure文件3571行,如下
可见,MemcacheDB 1.2.0 is released, for BerkeleyDB 4.7,才明白,memcachedb-1.2.1-beta是需要装BerkeleyDB.4.7的。
装libevent
wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
tar -zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure
make
make install
装berkeley-db
wget http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz
tar zxf db-4.7.25.tar.gz
cd db-4.7.25/build_unix/
../dist/configure
make
make install
#编译完成,将Berkeley Db运行库的路径添加到系统配置里面
echo "/usr/local/BerkeleyDB.4.7/lib/" >> /etc/ld.so.conf
ldconfig
装memcachedb,最新版是2008年12月份的,至今没有更新据说是已经比较稳定了。
wget http://memcachedb.googlecode.com/files/memcachedb-1.2.1-beta.tar.gz
tar zxf memcachedb-1.2.1-beta.tar.gz
cd memcachedb-1.2.1-beta
./configure
make
make install
装完了!
启动memcachedb
创建目录/www/mcdb_data
memcachedb -p 22222 -d -r -u root -H /www/mcdb_data -N
用PHP连接memcachedb和连接memcache的代码几乎是一模一样的。
<?php
$mcdb_host = '127.0.0.1';
$mcdb_port = '22222';
$mcdb = new Memcache;
$mcdb->connect($mcdb_host, $mcdb_port);
$mcdb->set('test','test');
echo $mcdb->get('test');
?>
服务器重启后,$mcdb->get('test'),仍然可以获得值,证明不会丢失,测试完成:)
如果之前装过libevent,并且指定了安装目录,在装mcdb时需要用-with-libevent=/dir/指定。
如:./configure --with-libevent=/usr/local/libevent
2.memcacheq的安装
Building MemcacheQ
On a *nix, just following:
$tar xvzf memcacheq-0.2.x.tar.gz
$cd memcacheq-0.2.x
$./configure --enable-threads
$make
$sudo make install
Start the daemon
For example:
memcacheq -d -r -H /data1/memcacheq -N -R -v -L 1024 -B 1024 > /data1/mq_error.log 2>&1
Notice: Because MemcacheQ is using fixed-length storage, so you should use '-B' option to specify the max length of your message. Default is 1024 bytes. Any message that shorter than the length you specified will be padded with '0x20', the space character. A message includes following bytes:
<your queue name bytes> + <message metadata(9 ~ 20+ bytes)> + <your message body bytes>
use "-h" option to see more configures.
Only two commands are used to operate the queue:
Append a message to the tail of queue:
set <queue name> <flags> 0 <message_len>\r\n
<put your message body here>\r\n
STORED\r\n
Note: MQ will create a new queue automatically if your queue is not existed. The original 'expire time' field is ignored by server.
Consume a message from the head of queue:
get <queue name>\r\n
VALUE <queue name> <flags> <message_len>\r\n
<your message body will come here>\r\n
END\r\n
Building MemcacheQ
On a *nix, just following:
$tar xvzf memcacheq-0.2.x.tar.gz
$cd memcacheq-0.2.x
$./configure --enable-threads
$make
$sudo make install
Start the daemon
For example:
memcacheq -d -r -H /data1/memcacheq -N -R -v -L 1024 -B 1024 > /data1/mq_error.log 2>&1
Notice: Because MemcacheQ is using fixed-length storage, so you should use '-B' option to specify the max length of your message. Default is 1024 bytes. Any message that shorter than the length you specified will be padded with '0x20', the space character. A message includes following bytes:
<your queue name bytes> + <message metadata(9 ~ 20+ bytes)> + <your message body bytes>
use "-h" option to see more configures.
Only two commands are used to operate the queue:
Append a message to the tail of queue:
set <queue name> <flags> 0 <message_len>\r\n
<put your message body here>\r\n
STORED\r\n
Note: MQ will create a new queue automatically if your queue is not existed. The original 'expire time' field is ignored by server.
Consume a message from the head of queue:
get <queue name>\r\n
VALUE <queue name> <flags> <message_len>\r\n
<your message body will come here>\r\n
END\r\n
Other tips
use 'stats queue' to see your current queues:
$ telnet 127.0.0.1 22201
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats queue
STAT test1
STAT test2
STAT test3
STAT test4
END
delete a queue:
$ telnet 127.0.0.1 22201 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. delete test1 DELETED
'db_stat' a queue to see how many records now in:
$ cd <your queue dir>
$ /usr/local/BerkeleyDB.4.7/bin/db_stat -d test1
Mon Sep 22 20:25:56 2008 Local time
42253 Queue magic number
4 Queue version number
1024 Fixed-length record size
0x20 Fixed-length record pad
4096 Underlying database page size
131072 Underlying database extent size
100000 Number of records in the database
33334 Number of database pages
2048 Number of bytes free in database pages (99% ff)
1 First undeleted record
100001 Next available record number