MongoDBをOS X Lionにインストール（macports)


改めていじってみようと思ってインストールした時のメモ。
まずはmacports でインストールしてみた時のログ

``` 
~ $ sudo port install mongodb
Warning: port definitions are more than two weeks old, consider using selfupdate
--->  Computing dependencies for mongodb
--->  Dependencies to be installed: boost icu libpcap pcre scons spidermonkey nspr
--->  Fetching archive for icu
--->  Attempting to fetch icu-4.6.1_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/icu
--->  Fetching icu
--->  Attempting to fetch icu4c-4_6_1-src.tgz from http://distfiles.macports.org/icu
--->  Verifying checksum(s) for icu
--->  Extracting icu
--->  Applying patches to icu
--->  Configuring icu
--->  Building icu
--->  Staging icu into destroot
--->  Installing icu @4.6.1_0
--->  Activating icu @4.6.1_0
--->  Cleaning icu
--->  Fetching archive for boost
--->  Attempting to fetch boost-1.47.0_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/boost
--->  Fetching boost
--->  Attempting to fetch boost_1_47_0.tar.bz2 from http://jaist.dl.sourceforge.net/boost

--->  Verifying checksum(s) for boost
--->  Extracting boost
--->  Applying patches to boost
--->  Configuring boost
--->  Building boost
--->  Staging boost into destroot
--->  Installing boost @1.47.0_0
--->  Activating boost @1.47.0_0
--->  Cleaning boost
--->  Fetching archive for libpcap
--->  Attempting to fetch libpcap-1.1.1_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/libpcap
--->  Attempting to fetch libpcap-1.1.1_0.darwin_11.x86_64.tbz2.rmd160 from http://packages.macports.org/libpcap
--->  Installing libpcap @1.1.1_0
--->  Activating libpcap @1.1.1_0
--->  Cleaning libpcap
--->  Fetching archive for pcre
--->  Attempting to fetch pcre-8.12_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/pcre
--->  Fetching pcre
--->  Attempting to fetch pcre-8.12.tar.bz2 from http://jaist.dl.sourceforge.net/pcre
--->  Verifying checksum(s) for pcre
--->  Extracting pcre
--->  Configuring pcre
--->  Building pcre
--->  Staging pcre into destroot
--->  Installing pcre @8.12_0
--->  Activating pcre @8.12_0
--->  Cleaning pcre
--->  Fetching archive for scons
--->  Attempting to fetch scons-2.0.1_1.darwin_11.noarch.tbz2 from http://packages.macports.org/scons
--->  Attempting to fetch scons-2.0.1_1.darwin_11.noarch.tbz2.rmd160 from http://packages.macports.org/scons
--->  Installing scons @2.0.1_1
--->  Activating scons @2.0.1_1
--->  Cleaning scons
--->  Fetching archive for nspr
--->  Attempting to fetch nspr-4.8.8_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/nspr
--->  Fetching nspr
--->  Attempting to fetch nspr-4.8.8.tar.gz from http://distfiles.macports.org/nspr
--->  Verifying checksum(s) for nspr
--->  Extracting nspr
--->  Configuring nspr
--->  Building nspr
--->  Staging nspr into destroot
--->  Installing nspr @4.8.8_0
--->  Activating nspr @4.8.8_0
--->  Cleaning nspr
--->  Fetching archive for spidermonkey
--->  Attempting to fetch spidermonkey-1.7.0_5.darwin_11.x86_64.tbz2 from http://packages.macports.org/spidermonkey
--->  Attempting to fetch spidermonkey-1.7.0_5.darwin_11.x86_64.tbz2.rmd160 from http://packages.macports.org/spidermonkey
--->  Installing spidermonkey @1.7.0_5
--->  Activating spidermonkey @1.7.0_5
--->  Cleaning spidermonkey
--->  Fetching archive for mongodb
--->  Attempting to fetch mongodb-1.8.3_0.darwin_11.x86_64.tbz2 from http://packages.macports.org/mongodb
--->  Fetching mongodb
--->  Attempting to fetch mongodb-src-r1.8.3.tar.gz from http://distfiles.macports.org/mongodb
--->  Verifying checksum(s) for mongodb
--->  Extracting mongodb
--->  Applying patches to mongodb
--->  Configuring mongodb
--->  Building mongodb
Error: Target org.macports.build returned: shell command failed (see log for details)
Log for mongodb is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_databases_mongodb/mongodb/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
```

エラーでインストールまで進まなかったので、ググってみる。
https://www.google.co.jp/search?num=30&hl=ja&q=macports+mongodb+error&oq=macports+mongodb+error

ヒットしたページを元に実施した作業。
> https://trac.macports.org/ticket/30263

``` 
sudo port clean mongodb
sudo port extract mongodb
cd $(port work mongodb)/mongodb*
sudo curl -O https://jira.mongodb.org/secure/attachment/12395/lion.patch
sudo patch -p1 < lion.patch
cd
sudo port install mongodb
```


mongoシェル実行…したけど実行できず。

``` 
:~ $ mongo
dyld: Symbol not found: __ZNK5boost15program_options16validation_error4whatEv
  Referenced from: /opt/local/bin/mongo
  Expected in: /opt/local/lib/libboost_program_options-mt.dylib
 in /opt/local/bin/mongo
:~ $ echo $?
133
```


ヒットしたページを元に実施した作業。
> https://trac.macports.org/ticket/35151

依存関係でインストールされたboostに問題があったっぽい(?)ので、旧バージョンに切り替え。

```
:~ $ sudo port activate boost @1.47.0_0
:~ $ sudo mkdir -p /opt/local/var/lib/mongodb
:~ $ sudo touch /opt/local/var/log/mongodb.log
:~ $ sudo mongod --dbpath /opt/local/var/lib/mongodb --logpath /opt/local/var/log/mongodb.log &
all output going to: /opt/local/var/log/mongodb.log
```

```
:~ $ mongo
MongoDB shell version: 2.0.6
connecting to: test
```

お、動いた。
ので一旦メモ終わり