[mac]Mountain LionにmacportsでMongoDBをインストール

[mac]Mountain LionにmacportsでMongoDBをインストール

### インストール
ビルドにそこそこ時間がかかる。6時間なんてエントリーもあったけどそんなにかからなかった。15-20分位?環境はMacBookPro Retina, 13-inch, Early 2013。他のエントリーでは依存問題が...的なのがあったけど、特に問題がなかった。

$ sudo port install mongodb
Warning: port definitions are more than two weeks old, consider using selfupdate
--->  Cleaning bzip2
--->  Unable to uninstall bzip2 @1.0.6_0, the following ports depend on it:
--->  	pcre @8.12_1
--->  	python27 @2.7.2_2
--->  	freetype @2.4.9_1
--->  	php5 @5.3.10_0+apache2
Warning: Uninstall forced.  Proceeding despite dependencies.
--->  Deactivating bzip2 @1.0.6_0
--->  Unable to deactivate bzip2 @1.0.6_0, the following ports depend on it:
--->  	pcre @8.12_1
--->  	python27 @2.7.2_2
--->  	freetype @2.4.9_1
--->  	php5 @5.3.10_0+apache2
Warning: Deactivate forced.  Proceeding despite dependencies.
--->  Cleaning bzip2
--->  Uninstalling bzip2 @1.0.6_0
--->  Cleaning bzip2
--->  Fetching archive for bzip2
--->  Attempting to fetch bzip2-1.0.6_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/bzip2
--->  Attempting to fetch bzip2-1.0.6_0.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/bzip2
--->  Installing bzip2 @1.0.6_0
--->  Activating bzip2 @1.0.6_0
--->  Cleaning bzip2
--->  Computing dependencies for libedit
--->  Fetching archive for libedit
--->  Attempting to fetch libedit-20121213-3.0_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/libedit
--->  Attempting to fetch libedit-20121213-3.0_0.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/libedit
--->  Installing libedit @20121213-3.0_0
--->  Cleaning libedit
--->  Computing dependencies for libedit
--->  Deactivating libedit @20110802-3.0_0
--->  Cleaning libedit
--->  Activating libedit @20121213-3.0_0
--->  Cleaning libedit
--->  Computing dependencies for pcre
--->  Fetching archive for pcre
--->  Attempting to fetch pcre-8.32_1.darwin_12.x86_64.tbz2 from http://packages.macports.org/pcre
--->  Attempting to fetch pcre-8.32_1.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/pcre
--->  Installing pcre @8.32_1
--->  Cleaning pcre
--->  Computing dependencies for pcre
--->  Deactivating pcre @8.12_1
--->  Cleaning pcre
--->  Activating pcre @8.32_1
--->  Cleaning pcre
--->  Computing dependencies for mongodb
--->  Dependencies to be installed: libpcap scons snappy v8
--->  Fetching archive for libpcap
--->  Attempting to fetch libpcap-1.3.0_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/libpcap
--->  Attempting to fetch libpcap-1.3.0_0.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/libpcap
--->  Installing libpcap @1.3.0_0
--->  Activating libpcap @1.3.0_0
--->  Cleaning libpcap
--->  Fetching archive for scons
--->  Attempting to fetch scons-2.2.0_0.darwin_12.noarch.tbz2 from http://packages.macports.org/scons
--->  Attempting to fetch scons-2.2.0_0.darwin_12.noarch.tbz2.rmd160 from http://packages.macports.org/scons
--->  Installing scons @2.2.0_0
--->  Activating scons @2.2.0_0
--->  Cleaning scons
--->  Fetching archive for snappy
--->  Attempting to fetch snappy-1.0.5_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/snappy
--->  Attempting to fetch snappy-1.0.5_0.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/snappy
--->  Installing snappy @1.0.5_0
--->  Activating snappy @1.0.5_0
--->  Cleaning snappy
--->  Fetching archive for v8
--->  Attempting to fetch v8-3.17.15_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/v8
--->  Attempting to fetch v8-3.17.15_0.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/v8
--->  Installing v8 @3.17.15_0
--->  Activating v8 @3.17.15_0
--->  Cleaning v8
--->  Fetching archive for mongodb
--->  Attempting to fetch mongodb-2.4.1_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/mongodb
--->  Attempting to fetch mongodb-2.4.1_0.darwin_12.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/mongodb
--->  Attempting to fetch mongodb-2.4.1_0.darwin_12.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/mongodb
--->  Fetching distfiles for mongodb
--->  Attempting to fetch mongodb-src-r2.4.1.tar.gz from http://distfiles.macports.org/mongodb
--->  Verifying checksum(s) for mongodb
--->  Extracting mongodb
--->  Applying patches to mongodb
--->  Configuring mongodb
--->  Building mongodb
--->  Staging mongodb into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mongodb with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mongodb
###########################################################
--->  Installing mongodb @2.4.1_0
--->  Activating mongodb @2.4.1_0
--->  Cleaning mongodb
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  Found 137 broken file(s), matching files to ports
--->  Found 3 broken port(s), determining rebuild order
--->  Rebuilding in order
     apache2 @2.2.22 +preforkmpm
     git-core @1.7.7.2 +doc+pcre+python27
     php5 @5.3.10 +apache2
--->  Computing dependencies for apache2
--->  Fetching archive for apache2
--->  Attempting to fetch apache2-2.2.24_0+preforkmpm.darwin_12.x86_64.tbz2 from http://packages.macports.org/apache2
--->  Attempting to fetch apache2-2.2.24_0+preforkmpm.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/apache2
--->  Installing apache2 @2.2.24_0+preforkmpm
--->  Cleaning apache2
--->  Computing dependencies for apache2
--->  Deactivating apache2 @2.2.22_1+preforkmpm
--->  Cleaning apache2
--->  Activating apache2 @2.2.24_0+preforkmpm
--->  Cleaning apache2
--->  Computing dependencies for git-core
--->  Dependencies to be installed: p5.12-term-readkey
--->  Fetching archive for p5.12-term-readkey
--->  Attempting to fetch p5.12-term-readkey-2.300.0_3.darwin_12.x86_64.tbz2 from http://packages.macports.org/p5.12-term-readkey
--->  Attempting to fetch p5.12-term-readkey-2.300.0_3.darwin_12.x86_64.tbz2.rmd160 from http://packages.macports.org/p5.12-term-readkey
--->  Installing p5.12-term-readkey @2.300.0_3
--->  Activating p5.12-term-readkey @2.300.0_3
--->  Cleaning p5.12-term-readkey
--->  Fetching archive for git-core
--->  Attempting to fetch git-core-1.8.2.1_0+credential_osxkeychain+doc+pcre+python27.darwin_12.x86_64.tbz2 from http://packages.macports.org/git-core
--->  Attempting to fetch git-core-1.8.2.1_0+credential_osxkeychain+doc+pcre+python27.darwin_12.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/git-core
--->  Attempting to fetch git-core-1.8.2.1_0+credential_osxkeychain+doc+pcre+python27.darwin_12.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/git-core
--->  Fetching distfiles for git-core
--->  Attempting to fetch git-1.8.2.1.tar.gz from http://git-core.googlecode.com/files/
--->  Attempting to fetch git-manpages-1.8.2.1.tar.gz from http://git-core.googlecode.com/files/
--->  Attempting to fetch git-htmldocs-1.8.2.1.tar.gz from http://git-core.googlecode.com/files/
--->  Verifying checksum(s) for git-core
--->  Extracting git-core
--->  Applying patches to git-core
--->  Configuring git-core
--->  Building git-core
--->  Staging git-core into destroot
--->  Installing git-core @1.8.2.1_0+credential_osxkeychain+doc+pcre+python27
--->  Cleaning git-core
--->  Computing dependencies for git-core
--->  Deactivating git-core @1.7.7.2_0+doc+pcre+python27
--->  Cleaning git-core
--->  Activating git-core @1.8.2.1_0+credential_osxkeychain+doc+pcre+python27
--->  Cleaning git-core
--->  Computing dependencies for php5
--->  Fetching archive for php5
--->  Attempting to fetch php5-5.3.23_0+apache2.darwin_12.x86_64.tbz2 from http://packages.macports.org/php5
--->  Attempting to fetch php5-5.3.23_0+apache2.darwin_12.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/php5
--->  Attempting to fetch php5-5.3.23_0+apache2.darwin_12.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/php5
--->  Fetching distfiles for php5
--->  Attempting to fetch php-5.3.23.tar.bz2 from http://jp.php.net/get/php-5.3.23.tar.bz2/from/this/mirror?dummy=
--->  Verifying checksum(s) for php5
--->  Extracting php5
--->  Applying patches to php5
--->  Configuring php5
Error: org.macports.configure for port php5 returned: configure failure: command execution failed
Please see the log file for port php5 for details:
    /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_php5/php5/main.log
Error: Unable to upgrade port: 1
Error rebuilding php5
    while executing
"error "Error rebuilding $portname""
    (procedure "revupgrade_scanandrebuild" line 382)
    invoked from within
"revupgrade_scanandrebuild broken_port_counts $opts"
    (procedure "macports::revupgrade" line 5)
    invoked from within
"macports::revupgrade $opts"
    (procedure "action_revupgrade" line 2)
    invoked from within
"action_revupgrade $action $portlist $opts"
    (procedure "action_target" line 94)
    invoked from within
"$action_proc $action $portlist [array get global_options]"
    (procedure "process_cmd" line 95)
    invoked from within
"process_cmd $remaining_args"
    invoked from within
"if { [llength $remaining_args] > 0 } {

    # If there are remaining arguments, process those as a command
    set exit_status [process_cmd $remaining..."
    (file "/opt/local/bin/port" line 4785)
$ sudo port load mongodb

で起動時にデーモンが立ち上がるようになるみたい。

### mongodbデーモン起動

mongod でデーモン起動。

$ mongod
mongod --help for help and startup options
Sun Jun  2 09:11:40.248 [initandlisten] MongoDB starting : pid=28245 port=27017 dbpath=/data/db/ 64-bit host=clicktx-MBP.local
Sun Jun  2 09:11:40.248 [initandlisten] 
Sun Jun  2 09:11:40.248 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Sun Jun  2 09:11:40.249 [initandlisten] db version v2.4.1
Sun Jun  2 09:11:40.249 [initandlisten] git version: nogitversion
Sun Jun  2 09:11:40.249 [initandlisten] build info: Darwin clicktx-MBP.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Sun Jun  2 09:11:40.249 [initandlisten] allocator: tcmalloc
Sun Jun  2 09:11:40.249 [initandlisten] options: {}
Sun Jun  2 09:11:40.249 [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db/) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Sun Jun  2 09:11:40.249 dbexit: 
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: going to close listening sockets...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: going to flush diaglog...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: going to close sockets...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: waiting for fs preallocator...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: lock for final commit...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: final commit...
Sun Jun  2 09:11:40.249 [initandlisten] shutdown: closing all files...
Sun Jun  2 09:11:40.249 [initandlisten] closeAllFiles() finished
Sun Jun  2 09:11:40.249 dbexit: really exiting now

データベースのディレクトリがないみたい。

### mongodbシェルを使う

$ mongo
MongoDB shell version: 2.4.1
connecting to: test
> 

tabでコマンドの補完やカーソルキーで履歴の表示など出来る。

### チュートリアルを試してみる

[MongoDBの薄い本(The Little MongoDB Book) - cuspy diary](http://www.cuspy.org/diary/2012-04-17)