Erlangベースの key-value Store ということで、最近にわかに盛り上がってきている(の?) CouchDB というのに触ってみます。
(きっとカウチデービーって読むんですよね。)
CouchDBは、JSONでデータを取り出せる key-value ストア(レプリケーション対応)です。
くわしくはこのへん↓。
- Web 時代の非リレーショナルデータベース: 第 1 回 Apache CouchDB の概要とインストール
- CouchDB勉強会レポート - Hello, world! - s21g
- MongoDB,Tokyo Tyrant, CouchDBのベンチマーク記事 - うっかりプログラミング日誌
- Apache CouchDB: The CouchDB Project
- CouchDB を探る
こないだこんな日記を書いたのですが、私のやりたいことは、CouchDB のほうがきれいにかなえてくれそうな予感がしています。
- Git と Eventually Concistency - kawaguti の日記 (id:wayaguchi)
- - -
ここからはインストールログです。
MacPorts は CouchDB 0.8.1 がとれるみたい。
最新版 0.9.0 で 後方互換性のない変更があるみたいですが、とりあえずお試しなので楽な方で。
$ port search couchdb couchdb databases/couchdb 0.8.1 couchdb is a document database server couchdb-devel databases/couchdb-devel 0.9.0a-incubating couchdb is a document database server $ sudo port install couchdb ---> Fetching gawk ---> Attempting to fetch gawk-3.1.6.tar.bz2 from http://ftp.gnu.org/gnu/gawk ---> Verifying checksum(s) for gawk ---> Extracting gawk ---> Configuring gawk ---> Building gawk with target all ---> Staging gawk into destroot ---> Installing gawk 3.1.6_0 ---> Activating gawk 3.1.6_0 ---> Cleaning gawk ---> Fetching tcl ---> Attempting to fetch tcl8.5.5-src.tar.gz from http://downloads.sourceforge.net/tcl ---> Verifying checksum(s) for tcl ---> Extracting tcl ---> Configuring tcl ---> Building tcl with target all ---> Staging tcl into destroot ---> Installing tcl 8.5.5_0 ---> Activating tcl 8.5.5_0 ---> Cleaning tcl ---> Fetching tk ---> Attempting to fetch tk8.5.5-src.tar.gz from http://downloads.sourceforge.net/tcl ---> Verifying checksum(s) for tk ---> Extracting tk ---> Configuring tk ---> Building tk with target all ---> Staging tk into destroot ---> Installing tk 8.5.5_0 ---> Activating tk 8.5.5_0 ---> Cleaning tk ---> Fetching erlang ---> Attempting to fetch otp_src_R12B-5.tar.gz from http://www.erlang.org/download/ ---> Attempting to fetch otp_doc_man_R12B-5.tar.gz from http://www.erlang.org/download/ ---> Attempting to fetch otp_doc_html_R12B-5.tar.gz from http://www.erlang.org/download/ ---> Verifying checksum(s) for erlang ---> Extracting erlang ---> Applying patches to erlang ---> Configuring erlang ----> Building erlang with target all ---> Staging erlang into destroot ---> Installing erlang R12B-5_0 ---> Activating erlang R12B-5_0 ---> Cleaning erlang
awk, tck/tk がインストールされ、Erlangはソースからビルドされます(しばらく時間がかかる)。
---> Fetching icu ---> Attempting to fetch icu4c-4_0-src.tgz from http://download.icu-project.org/files/icu4c/4.0/ ---> Verifying checksum(s) for icu ---> Extracting icu ---> Configuring icu ---> Building icu with target all ---> Staging icu into destroot ---> Installing icu 4.0_0 ---> Activating icu 4.0_0 ---> Cleaning icu
---> Fetching nspr ---> Attempting to fetch nspr-4.7.3.tar.gz from http://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.7.3/src/ ---> Verifying checksum(s) for nspr ---> Extracting nspr ---> Configuring nspr ---> Building nspr with target all ---> Staging nspr into destroot ---> Installing nspr 4.7.3_0 ---> Activating nspr 4.7.3_0 ---> Cleaning nspr
nsprは、これみたいです。
- Netscape ポータブル・ランタイム (NSPR)
---> Fetching spidermonkey ---> Attempting to fetch js-1.7.0.tar.gz from http://ftp.mozilla.org/pub/mozilla.org/js/ ---> Verifying checksum(s) for spidermonkey ---> Extracting spidermonkey ---> Applying patches to spidermonkey ---> Configuring spidermonkey ---> Building spidermonkey with target all ---> Staging spidermonkey into destroot ---> Installing spidermonkey 1.7.0_1 ---> Activating spidermonkey 1.7.0_1 ---> Cleaning spidermonkey
spidermonkey は JavaScript 処理系ですね。
CouchDBはJSONでやりとりしますので、パーサとして使っている感じでしょうね。
---> Fetching couchdb ---> Attempting to fetch apache-couchdb-0.8.1-incubating.tar.gz from http://www.apache.org/dist/incubator/couchdb/0.8.1-incubating/ ---> Verifying checksum(s) for couchdb ---> Extracting couchdb ---> Configuring couchdb ---> Building couchdb with target all ---> Staging couchdb into destroot ---> Installing couchdb 0.8.1_0 ---> Activating couchdb 0.8.1_0 ---> Cleaning couchdb
起動は、couchdb コマンドで
$ couchdb ---Apache CouchDB 0.8.1-incubating (LogLevel=info) Apache CouchDB is starting. Config Info /opt/local/etc/couchdb/couch.ini: CurrentWorkingDir= (カレントディレクトリ) DbRootDir=/opt/local/var/lib/couchdb BindAddress="127.0.0.1" Port="5984" DocumentRoot=/opt/local/share/couchdb/www LogFile=/opt/local/var/log/couchdb/couch.log UtilDriverDir=/opt/local/lib/couchdb/erlang/lib/couch-0.8.1-incubating/priv/lib DbUpdateNotificationProcesses= FullTextSearchQueryServer= javascript=/opt/local/bin/couchjs /opt/local/share/couchdb/server/main.js
アクセスしてみる。
$ curl http://localhost:5984/ curl: (7) couldn't connect to host
だめやんけ。
LogFileを見ようと思ったら、/opt/local/var/log/couchdb/ がないっす。
sudo mkdir /opt/local/var/log sudo mkdir /opt/local/var/log/couchdb
なんかパーミションも足りていない感じなので、sudo で起動してみます。
sudo couchdb Apache CouchDB 0.8.1-incubating (LogLevel=info) Apache CouchDB is starting. Apache CouchDB has started. Time to relax.
お、メッセージが変わった。動いたっぽい。
$ curl http://localhost:5984/ {"couchdb":"Welcome","version":"0.8.1-incubating"}
http://localhost:5984/_utils で、マネジメント画面(futon)にはいれます。