Database JUNKY

MySQL,MariaDBを中心としたブログです

mongodbのインストール

インストールは書くまでもなく簡単です。また簡単なのはインストールのみならず、シャーディングやレプリケーションもコマンド一発でいけるところ、MySQLも簡単なのですが、それを上回る簡単さです。今回はそんな、mongdbのインストール方法について記載します。

以下の環境で試しました

  • OS :CENTOS5.5 (IA64)

  • ファイルのダウンロード

[shell]

cd /usr/local/src

wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-1.4.2.tgz

[/shell]

  1. ダウンロードしたファイルを解凍

[shell]

tar zxvf mongodb-linux-x86_64-1.4.2.tgz

[/shell] 3. デフォルトのデータディレクトリを作成

[shell]

mkdir -p /data/db

[/shell]

  1. mongoDBの起動

[shell]

cd /usr/local/src/mongodb-linux-x86_64-1.4.2/bin/

./mongod

./mongod help for help and startup options Mon May 24 17:10:43 Mongo DB : starting : pid = 15264 port = 27017 dbpath = /data/db/ master = 0 slave = 0  64-bit Mon May 24 17:10:43 db version v1.4.2, pdfile version 4.5 Mon May 24 17:10:43 git version: 53749fc2d547a3139fcf169d84d58442778ea4b0 Mon May 24 17:10:43 sys info: Linux domU-12-31-39-06-79-A1 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_41 Mon May 24 17:10:43 waiting for connections on port 27017 Mon May 24 17:10:43 web admin interface listening on port 28017 [/shell] ※これだけで起動は完了です!! 5. 上記パターンですが、フォアグラウンドで起動してしまうので、一旦終了させる。 [shell] CTRL + C でデーモンを終了させる。 Mon May 24 17:17:26 got kill or ctrl c signal 2 (Interrupt), will terminate after current cmd ends Mon May 24 17:17:26 now exiting Mon May 24 17:17:26  dbexit: Mon May 24 17:17:26      shutdown: going to close listening sockets… Mon May 24 17:17:26      going to close listening socket: 5 Mon May 24 17:17:26      going to close listening socket: 7 Mon May 24 17:17:26      shutdown: going to flush oplog… Mon May 24 17:17:26      shutdown: going to close sockets… Mon May 24 17:17:26      shutdown: waiting for fs preallocator… Mon May 24 17:17:26      shutdown: closing all files… Mon May 24 17:17:26      closeAllFiles() finished Mon May 24 17:17:26      shutdown: removing fs lock… Mon May 24 17:17:26  dbexit: really exiting now [/shell] 6. バックグラウンドで起動する。

[shell]

./mongod  dbpath /data/db &

[/shell] 7. インストールした場所がなんなので、一旦デーモンを終了する。 [shell]

pwd

/usr/local/src/mongodb-linux-x86_64-1.4.2/bin

./mongo

MongoDB shell version: 1.4.2 url: test connecting to: test Mon May 24 17:28:46 connection accepted from 127.0.0.1:53819 #4 type "help" for help > use admin switched to db admin > db.shutdownServer() Mon May 24 17:29:14 terminating, shutdown command received Mon May 24 17:29:14  dbexit: Mon May 24 17:29:14      shutdown: going to close listening sockets… Mon May 24 17:29:14      going to close listening socket: 5 Mon May 24 17:29:14      going to close listening socket: 7 Mon May 24 17:29:14      shutdown: going to flush oplog… Mon May 24 17:29:14      shutdown: going to close sockets… Mon May 24 17:29:14      shutdown: waiting for fs preallocator… Mon May 24 17:29:14      shutdown: closing all files… Mon May 24 17:29:14      closeAllFiles() finished Mon May 24 17:29:14      shutdown: removing fs lock… Mon May 24 17:29:14  dbexit: really exiting now ERROR: Client::~Client context should be NULL: conn Mon May 24 17:29:14 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1 server should be down… Mon May 24 17:29:14 trying reconnect to 127.0.0.1 Mon May 24 17:29:14 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1 127.0.0.1:27017 Mon May 24 17:29:14 MessagingPort say send() errno:9 Bad file descriptor 127.0.0.1:27017 Mon May 24 17:29:14 JS Error: Error: error doing query: unknown (anon):1284 > > quit function () { return nativeHelper.apply(quit, arguments); } > exit bye [1]+  Done                    ./mongod dbpath /data/db [/shell] 8. ディレクトリ毎、ごっそりmoveする。 [shell]

mv -f mongodb-linux-x86_64-1.4.2/ /usr/local/mongo

  /usr/local/mongo/bin/mongod dbpath /data/db &

[/shell] 9. 再度起動確認 [shell]

/usr/local/mongo/bin/mongo

MongoDB shell version: 1.4.2 url: test connecting to: test Mon May 24 18:07:24 connection accepted from 127.0.0.1:37307 #1 type "help" for help > db test > exit bye Mon May 24 18:07:39 end connection 127.0.0.1:37307 [/shell] 10. .bashrcに以下を追記する [shell]

.bashrc

User specific aliases and functions

alias rm='rm -i' alias cp='cp -i' alias mv='mv -i'

Source global definitions

if [ -f /etc/bashrc ]; then . /etc/bashrc fi

add mongodb path

export PATH=$PATH::/usr/local/mongo/bin [/shell]