Solaris10(x86)でmongodbをbuild

わたしが管理しているウェブサイトは同一アーキテクチュアのIAサーバ二台で運用されています。アーキテクチュアは同一なんですが、歴史的経緯により、OSがRHELSolaris10(x86)だったりします。RHELの方へなにか新しいものを入れるときは大抵yum一発か、rpmでインストールできますが、Solaris(x86)の方はこれはこれは一筋縄ではいかなんですな。
ということで、今日はmongodbをインストールしたときのメモ。

Spidermonkeyをインストール

Linuxspidermonkeyをいれたときのレポートは2011年3月9日のエントリにあります。これを参考にしてSolaris10(x86)へもインストールしてみます。するとmake でエラー。

$ /usr/local/bin/make -f Makefile.ref
config.mk:159: config/SunOS5.10_i86pc.mk: ファイルもディレクトリもありません。
cat: ../../dist/SunOS5.10_i86pc_DBG.OBJ/nspr/Version をオープンできません。
make: *** No rule to make target `config/SunOS5.10_i86pc.mk'.  Stop.

アーキテクチュア、OS毎にインクルードするmakefileがあるようですが、このOS用のファイルがないみたいです。まぁ、Solaris10なら大体おなじだろうってことで、SunOS5.10のものをリンクして再度make。

$ ln -s ./config/SunOS5.10.mk ./config/SunOS5.10_i86pc.mk
$ /usr/local/bin/make -f Makefile.ref
(中略)
/usr/ccs/bin/as -o SunOS5.10_i86pc_DBG.OBJ/lock_SunOS.o  -P -L -K PIC -D_ASM -D__STDC__=0 lock_SunOS.s
Assembler: 
        "lock_SunOS.s", line 1 : Syntax error
        Near line: "! "
        "lock_SunOS.s", line 2 : Syntax error
        Near line: "! ***** BEGIN LICENSE BLOCK *****"
        "lock_SunOS.s", line 2 : Illegal mnemonic
        Near line: "! ***** BEGIN LICENSE BLOCK *****"
        "lock_SunOS.s", line 2 : Illegal mnemonic
        Near line: "! ***** BEGIN LICENSE BLOCK *****"
        "lock_SunOS.s", line 2 : Illegal mnemonic
        Near line: "! ***** BEGIN LICENSE BLOCK *****"
        "lock_SunOS.s", line 3 : Syntax error
        Near line: "! Version: MPL 1.1/GPL 2.0/LGPL 2.1"
        "lock_SunOS.s", line 3 : Illegal mnemonic
        Near line: "! Version: MPL 1.1/GPL 2.0/LGPL 2.1"
        "lock_SunOS.s", line 3 : Illegal mnemonic
        Near line: "! Version: MPL 1.1/GPL 2.0/LGPL 2.1"
        "lock_SunOS.s", line 4 : Syntax error
        Near line: "!"
        "lock_SunOS.s", line 5 : Syntax error
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 5 : Illegal mnemonic
        Near line: "! The contents of this file are subject to the Mozilla Public License Version"
        "lock_SunOS.s", line 6 : Syntax error
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 6 : Illegal mnemonic
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 6 : Illegal mnemonic
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 6 : Illegal mnemonic
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 6 : Syntax error
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 6 : Illegal mnemonic
        Near line: "! 1.1 (the "License"); you may not use this file except in compliance with"
        "lock_SunOS.s", line 7 : Syntax error
        Near line: "! the License. You may obtain a copy of the License at"
        "lock_SunOS.s", line 7 : Illegal mnemonic
        Near line: "! the License. You may obtain a copy of the License at"
Too many errors - Goodbye
make[1]: *** [SunOS5.10_i86pc_DBG.OBJ/lock_SunOS.o] Error 127
make[1]: Leaving directory `/export/home/hoge/js/src'
make: *** [all] Error 2

なんじゃ? アセンブラの文法エラーか。困ったなぁ・・と思ったら同じ現象に遭遇して解決している人を発見。ありがたい。
lock_SunOS.sを消してしまえってことみたい。まぁロックがなくてもすこし困るくらいかな。
ということで再度チャンレンジ。

$ rm lock_SunOS.s 
$ /usr/local/bin/make -f Makefile.ref

ようやくビルドできました。めでたし、、じゃない。まだmongo本体が残っている。

mongodbをビルド

mongodbのソースからのインストールメモは2011年3月22日のエントリにあります。これを参考にしてインストール。

$ /usr/local/bin/tar -xzvf mongodb-src-r1.8.1.tar.gz
$ cd mongodb-src-r1.8.1/
$ scons .
(中略)
# scons --prefix=/usr install
(後略)

prefixを/usrにしたのはLinuxの環境と同じところへインストールしたかったからです。

動かしてみる

さっそく動かしてみる。

# mkdir -p /data/db
# /usr/bin/mongod
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
異常終了 (core dumped)

えー、coredumpってか。なんだろ。 localeってあるから言語関係のなにかかな。ってことでこうやってみる。

# export LANG=C
# /usr/bin/mongod

をを、動きやがった。ロケールのファイルが見えないのか、不正なのか。あとで調べてみよう。
とりあえずはマルチバイト文字をいれても問題ないみたい。

> db.foo.insert({"マルチバイト":"こっちは感じ"})
> db.foo.findOne() 
{ "_id" : ObjectId("4ddf3660d0ff5974a5786a41"), "マルチバイト" : "こっちは感じ" }
>