Windows XP sp2にCouchDBを入れたときのメモ

# 概要

Apache CouchDB(Erlang実装)をWindowsに入れたときのメモ

# サポート・テスト済み環境
Windows XP SP3 32bit
Windows Vista 32bit

# 依存ライブラリ
CouchDB win32用インストーラー起動時にはインストール済みでなくてはならない。

Erlang/OTP
http://www.erlang.org/download.html
インストーラーが用意されているので普通にダウンロードしてインストール
※今回試したバージョン:R13B01
・デフォルトインストールディレクトリ:C:/Program Files/erl5.7.2/

・Visual C++2008 Redistributables(for openssl binary) (再頒布可能パッケージ[x86])
http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en
Visual C++2008 ライブラリランタイム・コンポーネント
インストーラが用意されているので普通にダウンロードしてインストール
・system32直下にDLLが置かれるよう指定

・OpenSSL - 特にバージョン Win32OpenSSL_Light-0_9_8iを使ったら成功した by Couchdb Wiki
※現状だと0_9_8iは落とせないみたいなので、Win32OpenSSL_Light-0_9_8k.exeで検証してみる
http://www.openssl.org/related/binaries.html
インストーラが用意されているので普通にダウンロードしてインストール

# 導入手順
参考:http://wiki.apache.org/couchdb/Installing_on_Windows

[windows installer test beta]
http://dl.getdropbox.com/u/118385/CouchDbBinaries/couchdb-0.8.1-win32.exe

[依存]
Erlang/OTP
・C Compiler/Linker(such as GCC or Visual C++) - 今回はVisual C++ 2008 redistributablesで
・Make(such as GNU Make or nmake)
・OpenSSL
ICU(International Components for Unicode) - http://www.icu-project.org/download/4.0.html
※推奨ビルドを利用−binary build of 4.2
SpiderMonkey

[導入事前確認]
Erlang/OTPインストール済みであること
・Visual C++ 2008 Redistributablesインストール済みであること
・OpenSSL for win32がインストール済みであること
ICU DLL (ErlangにInternatinal Component for Unicodeを提供する)
※ダウンロードしてきたICUバイナリを icu*.dllをErlangインストールディレクトリのbinディレクトリに配置
Wikiには、"""libeay32.dll for older versions of ICU""" ICUの古いバージョンのためにlibeay32.dllも配置する
と書かれていたが、OpenSSL for win32 が導入済みなのでスキップしました。

[導入]
Windows binary installer test betaがダウンロードできるので、普通に落としてきてインストール
※必要なライブラリランタイムとWindowsバイナリ再構成が行われる

Erlang/OTPインストールディレクトリのlib直下にcouchdb-0.8.1ディレクトリが作成される
ただ、CouchDB WikiWindowsインストール(インストーラを利用しない場合の手順はcouchdbのバージョンは0.9.0なので
そちらの手順とミックスしてやってみるのは若干微妙だったけどやってみた)

以下CouchDB Installing_on_Windowsの手順とインストーラが行ったことを照らし合わせて検証

1. Install CouchDB as an Erlang Library Directory
CouchDBErlangのライブラリディレクトリにインストールされているかを確認する。
自分の環境では以下のようにディレクトリが作成されていました。

C:\Program Files\erl5.7.2\lib\couchdb-0.8.1

2.Make the following empty directory:
以下のように空ディレクトリを作成します.とWikiにはありますが、

C:\Program Files\erl5.7.2\lib\mochiweb-0.01\ebin

インストーラを使うと以下のようにディレクトリが作成されErlang beam codeが配置されていました
C:\Program Files\erl5.7.2\lib\mochiweb-0.01\ebin\

3.Provide ICU to Erlang
""" ErlangICUを提供する """
既に事前準備で行っているのでスキップ

4.Build SpiderMonkey
CouchDBはRESTful HTTP/JSON APIでお話するので、内部的にSpiderMonkeyを使っています。
そのためこの手順が必要なりますが、インストーラでインストールすると、よきに計らってくれました。
一応以下のようにcouch_js.exe, js32.dllが配置されていること確認

C:\Program Files\erl5.7.2\bin\couch_js.exe
C:\Program Files\erl5.7.2\bin\js32.dll

以下、本家Wiki手順こぴぺ

The SpiderMonkey distribution's Windows build stuff is broken. See this blog posthttp://blog.endflow.net/?p=55&lang=en
for a working js.mak file. Don't bother trying to import the project file into a contemporary Visual Studio;
just use the Visual Studio command line tools with the js.mak file referred to above.

CouchDB uses a custom JavaScript driver, which provides unicode and buffering improvements.
In the SpiderMonkey distribution, rename src/js.c to src/js.c.bak, and copy
C:\Program Files\erl5.6.3\lib\couchdb-0.8.1\src\couchdb\couch_js.c from the CouchDB distribution to src/js.c
in the SpiderMonkey distribution. Before running nmake, edit the new js.c and change #include to #include "jsapi.h".

Once you've built js.exe and js32.dll, copy them both to

C:\Program Files\erl5.7.1\erts-5.7.1\bin

and rename js.exe to couch_js.exe.

Here are the binaries built according to the blog post: couchbd_spidermonkey_1.7_win32_32bit.ziphttp://dl.getdropbox.com/u/118385/CouchDbBinaries/couchbd_spidermonkey_1.7_win32_32bit.zip . Just unzip the contents to the bin directory.

てか、普通にバイナリーを落とせるのでインストーラーを使わないでcouche_js.exeとjs32.dllのビルドにしくじった場合は
落としてきて使ったほうが無難っぽいです。

5.Build couchdb/couch_erl_driver.c
couchdbErlangをつなぐためのドライバビルド。
これもインストーラを利用しない場合は、ほげほげしないと駄目みたいですが、インストーラだと
よきにはからってくれます。

C:\Program Files\erl5.7.2\lib\couchdb-0.8.1\priv\lib\couch_erl_driver.dll

というようにドライバDLLが配置されています。

6.Erlang Compilation
Erlangコンパイルを行います。
インストーラでインストールした場合は、コンパイルまで行ってくれるので、
あとは、CouchDBの設定ファイルを所定のディレクトリに配置するのみです。

以下CouchDB Wiki手順

Create a the following file:

C:\Program Files\erl5.7.1\lib\apache-couchdb-0.9.0\src\Emakefile

Add the following content:

{'./couchdb/*', [{outdir,"../ebin"}]}.
{'./mochiweb/*', [{outdir,"../../mochiweb-0.01/ebin"}]}.

Launch erl (or werl) and execute the following command to change working directory:

cd("C:/Program Files/erl5.7.1/lib/apache-couchdb-0.9.0/src").

Execute this command to compile CouchDB:

make:all().


7.Configuring(構成)
C:\Program Files\erl5.7.2\lib\couchdb-0.8.1\etc\couchdb\couch.ini.tpl.in
ファイルをコピーして、Erlangインストールディレクトリ直下のbinディレクトリに
default.iniという名前で保存する。Wikiでは、Version 0.9.0のCouchDBの設定ファイルについて
言及してあるのですが、0.8.1の設定ファイルと設定内容に異なる部分があったため、
今回は、デフォルト設定の0.8.1の設定をそのまま使っています。

以下default.ini

; @configure_input@

[Couch]

ConsoleStartupMsg=Apache CouchDB is starting.

DbRootDir=%localstatelibdir%

Port=5984

BindAddress=127.0.0.1

DocumentRoot=%localdatadir%/www

LogFile=%localstatelogdir%/couch.log

UtilDriverDir=%couchprivlibdir%

LogLevel=info

[Couch Query Servers]

javascript=%bindir%/%couchjs_command_name% %localdatadir%/server/main.js

8.Running
実際に動作させてみます。
事前準備でインストールしておいた Erlangの実行環境(エミュレータ)を起動します

[スタートメニュー] - [すべてのプログラム] - [Erlang OTP R13B01] - [Erlang]

を選択すると、Erlangの実行環境が起動します。

起動したら、以下を実行して、CouchDBサーバーを起動します。

Erlang R13B01 (erts-5.7.2) [rq:1] [async-threads:0]

Eshell V5.7.2 (abort with ^G)
1> couch_server:start().
Apache CouchDB 0.0.0 (LogLevel=info)
Apache CouchDB is starting. Futon is at http://localhost:5984/_utils/index.html

Apache CouchDB has started. Time to relax.というログが出力されたら、
http://localhost:5984/_utils/index.htmlへアクセスします。

以下のような画面が表示されたら正常にCouchDBがインストールされています。
あとは、煮るなり焼くなりお好きにどうぞ。

テキストに書いたやつをそのまま貼ったのであとで整形する。