CentOS 6.4にMongoDB最新版をインストール
今回はMongoDBちゃん。
MongoDBはpostgreSQLとかMySQLとは違ったデータベース。
ドキュメント指向ってやつですよ。
MySQLとかってテーブル作るときにintegerとかtextとかvarcharとか型を決めるじゃないすか。
Mongoちゃんにはそういうの必要ない。なんでもはいる、楽しいこれがスキーマレス。
型定義してない?問題ない。
そもそもテーブル作ってない?全く問題ない。
あとから列を足したい?alter table必要ない!!!
なんて楽しいドキュメント指向!スキーマレス!
ってなわけで入れてみよう。
http://www.mongodb.org/downloads
ここから最新の安定版を入れよう。
wget http://downloads.mongodb.org/src/mongodb-src-r2.4.5.tar.gz
解凍
tar zvxf mongodb-src-r2.4.5.tar.gz
configure系じゃないので別途ツール入れます。
sudo yum -y install scons
やってみる
scons all
結構時間かかりますね
sudo scons install
scons: done building targets.
みたいに出たら終了。デフォルトでは/usr/local/binに入ります。
とりあえず起動する。
[~]$ mongod mongod --help for help and startup options Sun Jul 28 22:38:48.495 [initandlisten] MongoDB starting : pid=28938 port=27017 dbpath=/data/db/ 64-bit host= Sun Jul 28 22:38:48.495 [initandlisten] db version v2.4.5 Sun Jul 28 22:38:48.495 [initandlisten] git version: nogitversion Sun Jul 28 22:38:48.495 [initandlisten] build info: Linux 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49 Sun Jul 28 22:38:48.495 [initandlisten] allocator: tcmalloc Sun Jul 28 22:38:48.495 [initandlisten] options: {} Sun Jul 28 22:38:48.496 [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 Jul 28 22:38:48.496 dbexit: Sun Jul 28 22:38:48.496 [initandlisten] shutdown: going to close listening sockets... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: going to flush diaglog... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: going to close sockets... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: waiting for fs preallocator... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: lock for final commit... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: final commit... Sun Jul 28 22:38:48.496 [initandlisten] shutdown: closing all files... Sun Jul 28 22:38:48.496 [initandlisten] closeAllFiles() finished Sun Jul 28 22:38:48.496 dbexit: really exiting now
dbpath (/data/db/) does not exist.
ということでdbディレクトリがないってのが問題らしい。
作ろう
$ sudo mkdir -p /data/db/
権限を付与してみる
sudo chown -R user:user /data/db/
で、起動
[~]$ mongod [22:45:38] mongod --help for help and startup options Sun Jul 28 22:45:42.019 [initandlisten] MongoDB starting : pid=29205 port=27017 dbpath=/data/db/ 64-bit host=www14280ui.sakura.ne.jp Sun Jul 28 22:45:42.019 [initandlisten] db version v2.4.5 Sun Jul 28 22:45:42.019 [initandlisten] git version: nogitversion Sun Jul 28 22:45:42.019 [initandlisten] build info: Linux 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49 Sun Jul 28 22:45:42.019 [initandlisten] allocator: tcmalloc Sun Jul 28 22:45:42.019 [initandlisten] options: {} Sun Jul 28 22:45:42.033 [initandlisten] journal dir=/data/db/journal Sun Jul 28 22:45:42.033 [initandlisten] recover : no journal files present, no recovery needed Sun Jul 28 22:45:42.083 [FileAllocator] allocating new datafile /data/db/local.ns, filling with zeroes... Sun Jul 28 22:45:42.084 [FileAllocator] creating directory /data/db/_tmp Sun Jul 28 22:45:42.085 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB, took 0 secs Sun Jul 28 22:45:42.085 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes... Sun Jul 28 22:45:42.086 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0 secs Sun Jul 28 22:45:42.088 [websvr] admin web console waiting for connections on port 28017 Sun Jul 28 22:45:42.139 [initandlisten] waiting for connections on port 27017
特にエラーがなければ起動しています。
接続してみる
[~]$ mongo MongoDB shell version: 2.4.5 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 >
goodです!!!!
試す。
> db.testcol.save({name:"me"}) > db.testcol.find() { "_id" : ObjectId("51f521e84bf8f55e2a7acf46"), "name" : "me" }
testcolなんてテーブル一切定義してないのにinsert出来る。スキーマレス良いですね。