ほんの触りだけになるかもしれませんが、MongoDBでちょっと遊んでみることにしました。
MongoDB
http://www.mongodb.org/
参考になりそうなところ
http://gihyo.jp/dev/serial/01/mongodb
で、当方Ubuntu Linuxですが、オフィシャルサイトからビルド済みtar.gzをダウンロードしてきてインストールしたいと思います。
MongoDB Downloads
http://www.mongodb.org/downloads
現時点での最新版は、2.4.4でした。
これを、/usr/local/mongodbにインストールするという手順で。
$ cd /usr/local/ $ sudo mkdir mongodb $ cd mongodb/ $ sudo cp [ダウンロードしたディレクトリ]/mongodb-linux-x86_64-2.4.4.tgz ./. $ sudo tar -zxvf mongodb-linux-x86_64-2.4.4.tgz
名前がちょっと長いので、短く。
$ sudo mv mongodb-linux-x86_64-2.4.4 mongodb-2.4.4
$ sudo ln -s mongodb-2.4.4 current
「current」としているのは、個人的な趣味です。
あとは、データファイル配置先ディレクトリですね。
デフォルトだと
/data/db
だということですが、これはちょっと嫌なので先ほどのMongoDBのインストール先にまとめることにしました。
$ cd /usr/local/mongodb/ $ sudo mkdir -p data/db
権限変更も、必要に応じて。
$ sudo chown -R xxxxx.xxxxx data/
一応、PATHも通しましょうか。
export MONGODB_HOME=/usr/local/mongodb/current PATH=${MONGODB_HOME}/bin:${PATH}
.bashrcに書いたので、再評価。
$ . .bashrc
で、あとはmongodコマンドで起動するのですが、そのまま起動すると「/data/db」がないと起動に失敗するので、先ほど作ったディレクトリを指定して起動してみます。
オプションは、「--dbpath」で。
$ mongod --dbpath /usr/local/mongodb/data/db
ちなみに、設定ファイルを作って
mongod --config /etc/mongod.conf #または mongod -f /etc/mongod.conf
みたいに指定していいらしいです。その場合は、こんな感じで?
dbpath=/usr/local/mongodb/data/db
で起動してみるとログが、だらだらと…。
Wed Jun 12 21:35:00.818 [initandlisten] MongoDB starting : pid=4579 port=27017 dbpath=/usr/local/mongodb/data/db 64-bit host=ubuntu Wed Jun 12 21:35:00.819 [initandlisten] db version v2.4.4 Wed Jun 12 21:35:00.819 [initandlisten] git version: 4ec1fb96702c9d4c57b1e06dd34eb73a16e407d2 Wed Jun 12 21:35:00.819 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49 Wed Jun 12 21:35:00.819 [initandlisten] allocator: tcmalloc Wed Jun 12 21:35:00.819 [initandlisten] options: { dbpath: "/usr/local/mongodb/data/db" } Wed Jun 12 21:35:00.872 [initandlisten] journal dir=/usr/local/mongodb/data/db/journal Wed Jun 12 21:35:00.872 [initandlisten] recover : no journal files present, no recovery needed Wed Jun 12 21:35:01.222 [initandlisten] preallocateIsFaster=true 5.76 Wed Jun 12 21:35:01.539 [initandlisten] preallocateIsFaster=true 4.74 Wed Jun 12 21:35:02.801 [initandlisten] preallocateIsFaster=true 3.52 Wed Jun 12 21:35:02.802 [initandlisten] preallocating a journal file /usr/local/mongodb/data/db/journal/prealloc.0 Wed Jun 12 21:35:05.016 [initandlisten] File Preallocator Progress: 408944640/107374182438% Wed Jun 12 21:35:13.494 [initandlisten] File Preallocator Progress: 492830720/107374182445% Wed Jun 12 21:35:20.636 [initandlisten] File Preallocator Progress: 545259520/107374182450% Wed Jun 12 21:35:23.293 [initandlisten] File Preallocator Progress: 681574400/107374182463% Wed Jun 12 21:35:39.584 [initandlisten] File Preallocator Progress: 713031680/107374182466% Wed Jun 12 21:35:42.251 [initandlisten] File Preallocator Progress: 870318080/107374182481% Wed Jun 12 21:35:51.587 [initandlisten] File Preallocator Progress: 880803840/107374182482% Wed Jun 12 21:36:02.344 [initandlisten] File Preallocator Progress: 954204160/107374182488% Wed Jun 12 21:36:43.799 [initandlisten] preallocating a journal file /usr/local/mongodb/data/db/journal/prealloc.1 Wed Jun 12 21:36:46.095 [initandlisten] File Preallocator Progress: 387973120/107374182436% Wed Jun 12 21:36:52.148 [initandlisten] File Preallocator Progress: 429916160/107374182440% Wed Jun 12 21:37:00.131 [initandlisten] File Preallocator Progress: 471859200/107374182443% Wed Jun 12 21:37:03.236 [initandlisten] File Preallocator Progress: 608174080/107374182456% Wed Jun 12 21:37:12.387 [initandlisten] File Preallocator Progress: 618659840/107374182457% Wed Jun 12 21:37:19.076 [initandlisten] File Preallocator Progress: 692060160/107374182464% Wed Jun 12 21:37:28.829 [initandlisten] File Preallocator Progress: 723517440/107374182467% Wed Jun 12 21:37:31.094 [initandlisten] File Preallocator Progress: 891289600/107374182483% Wed Jun 12 21:37:36.817 [initandlisten] File Preallocator Progress: 901775360/107374182483% Wed Jun 12 21:37:43.846 [initandlisten] File Preallocator Progress: 933232640/107374182486% Wed Jun 12 21:37:53.046 [initandlisten] File Preallocator Progress: 1048576000/107374182497% Wed Jun 12 21:38:13.262 [initandlisten] preallocating a journal file /usr/local/mongodb/data/db/journal/prealloc.2 Wed Jun 12 21:38:16.012 [initandlisten] File Preallocator Progress: 408944640/107374182438% Wed Jun 12 21:38:23.286 [initandlisten] File Preallocator Progress: 461373440/107374182442% Wed Jun 12 21:38:28.330 [initandlisten] File Preallocator Progress: 513802240/107374182447% Wed Jun 12 21:38:33.876 [initandlisten] File Preallocator Progress: 587202560/107374182454% Wed Jun 12 21:38:43.573 [initandlisten] File Preallocator Progress: 660602880/107374182461% Wed Jun 12 21:38:46.050 [initandlisten] File Preallocator Progress: 828375040/107374182477% Wed Jun 12 21:38:51.957 [initandlisten] File Preallocator Progress: 838860800/107374182478% Wed Jun 12 21:38:55.715 [initandlisten] File Preallocator Progress: 849346560/107374182479% Wed Jun 12 21:39:02.159 [initandlisten] File Preallocator Progress: 964689920/107374182489% Wed Jun 12 21:39:08.426 [initandlisten] File Preallocator Progress: 1038090240/107374182496% Wed Jun 12 21:39:11.602 [initandlisten] File Preallocator Progress: 1048576000/107374182497% Wed Jun 12 21:39:32.727 [FileAllocator] allocating new datafile /usr/local/mongodb/data/db/local.ns, filling with zeroes... Wed Jun 12 21:39:32.728 [FileAllocator] creating directory /usr/local/mongodb/data/db/_tmp Wed Jun 12 21:39:32.747 [FileAllocator] done allocating datafile /usr/local/mongodb/data/db/local.ns, size: 16MB, took 0.002 secs Wed Jun 12 21:39:32.769 [FileAllocator] allocating new datafile /usr/local/mongodb/data/db/local.0, filling with zeroes... Wed Jun 12 21:39:33.432 [FileAllocator] done allocating datafile /usr/local/mongodb/data/db/local.0, size: 64MB, took 0.663 secs Wed Jun 12 21:39:33.484 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37 802ms Wed Jun 12 21:39:33.527 [initandlisten] waiting for connections on port 27017 Wed Jun 12 21:39:33.528 [websvr] admin web console waiting for connections on port 28017
なんか、起動にめっちゃ時間がかかってるなぁと思ってたら、ジャーナルファイルを作っていたようで…。
$ ll -h /usr/local/mongodb/data/db/journal/ 合計 3.1G drwxrwxr-x 2 xxxxx xxxxx 4.0K Jun 12 21:39 ./ drwxr-xr-x 4 xxxxx xxxxx 4.0K Jun 12 21:39 ../ -rw------- 1 xxxxx xxxxx 1.0G Jun 12 21:39 j._0 -rw------- 1 xxxxx xxxxx 88 Jun 12 21:39 lsn -rw------- 1 xxxxx xxxxx 1.0G Jun 12 21:37 prealloc.1 -rw------- 1 xxxxx xxxxx 1.0G Jun 12 21:39 prealloc.2
いきなり、1Gのファイルを3つも作りおった…。
*2回目以降は、早くなります
んじゃ、mongoコマンドで接続してみましょう。
$ mongo MongoDB shell version: 2.4.4 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user
> use tutorial; switched to db tutorial > db.users.insert({name: "Kazuhira", site: "http://d.hatena.ne.jp/Kazuhira/"}) > db.users.count() 1 > db.users.find() { "_id" : ObjectId("51b86e55a8de269a905acff8"), "name" : "Kazuhira", "site" : "http://d.hatena.ne.jp/Kazuhira/" }
動いてますね〜。