Thursday, January 17, 2013

learn a bit - MongoDB

After I read a few document about Oracle Linux. I thought I should learn something new today. I didn't have much time. Maybe 30 minutes! So, I started to read a little about mongodb, then  download binary from web. I thought it's cool for installation it.
[surachart@centos ~]$ curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.2.tgz > mongo.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 53.3M  100 53.3M    0     0   163k      0  0:05:35  0:05:35 --:--:--  219k
[surachart@centos ~]$ tar zxf mongo.tgz
[surachart@centos ~]$ ls mongo*
mongo.tgz

mongodb-linux-x86_64-2.2.2:
bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES
[surachart@centos ~]$ ln -s mongodb-linux-x86_64-2.2.2 mongo
[surachart@centos ~]$ sudo mkdir -p /data/db
[surachart@centos ~]$ sudo chown -R surachart:surachart /data/db
[surachart@centos ~]$ cd mongo
[surachart@centos mongo]$ ls
bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES
[surachart@centos mongo]$ less README
[surachart@centos mongo]$ ./bin/mongod
./bin/mongod --help for help and startup options
Thu Jan 17 18:28:28 [initandlisten] MongoDB starting : pid=1559 port=27017 dbpath=/data/db/ 64-bit host=centos
Thu Jan 17 18:28:28 [initandlisten] db version v2.2.2, pdfile version 4.5
Thu Jan 17 18:28:28 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Thu Jan 17 18:28:28 [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
Thu Jan 17 18:28:28 [initandlisten] options: {}
Thu Jan 17 18:28:28 [initandlisten] journal dir=/data/db/journal
Thu Jan 17 18:28:28 [initandlisten] recover : no journal files present, no recovery needed
Thu Jan 17 18:28:29 [initandlisten] preallocateIsFaster=true 7.88
Thu Jan 17 18:28:30 [initandlisten] preallocateIsFaster=true 9.26
Thu Jan 17 18:28:31 [initandlisten] preallocateIsFaster=true 9.06
Thu Jan 17 18:28:31 [initandlisten] preallocating a journal file /data/db/journal/prealloc.0
Thu Jan 17 18:28:34 [initandlisten]             346030080/1073741824    32%
Thu Jan 17 18:28:37 [initandlisten]             471859200/1073741824    43%
Thu Jan 17 18:28:40 [initandlisten]             608174080/1073741824    56%
Thu Jan 17 18:28:43 [initandlisten]             734003200/1073741824    68%
Thu Jan 17 18:28:47 [initandlisten]             849346560/1073741824    79%
Thu Jan 17 18:28:50 [initandlisten]             954204160/1073741824    88%
Thu Jan 17 18:29:14 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
Thu Jan 17 18:29:17 [initandlisten]             346030080/1073741824    32%
Thu Jan 17 18:29:20 [initandlisten]             482344960/1073741824    44%
Thu Jan 17 18:29:23 [initandlisten]             618659840/1073741824    57%
Thu Jan 17 18:29:26 [initandlisten]             723517440/1073741824    67%
Thu Jan 17 18:29:29 [initandlisten]             859832320/1073741824    80%
Thu Jan 17 18:29:32 [initandlisten]             954204160/1073741824    88%
Thu Jan 17 18:29:50 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
Thu Jan 17 18:29:53 [initandlisten]             408944640/1073741824    38%
Thu Jan 17 18:29:56 [initandlisten]             503316480/1073741824    46%
Thu Jan 17 18:29:59 [initandlisten]             639631360/1073741824    59%
Thu Jan 17 18:30:02 [initandlisten]             754974720/1073741824    70%
Thu Jan 17 18:30:05 [initandlisten]             807403520/1073741824    75%
Thu Jan 17 18:30:09 [initandlisten]             859832320/1073741824    80%
Thu Jan 17 18:30:12 [initandlisten]             1048576000/1073741824   97%
Thu Jan 17 18:30:24 [initandlisten] waiting for connections on port 27017
Thu Jan 17 18:30:24 [websvr] admin web console waiting for connections on port 28017
Tried to connect and tested.
[surachart@centos mongo]$ ./bin/mongo
MongoDB shell version: 2.2.2
connecting to: test
> db.test.save( { a: 1 }
... )
> db.test.find()
{ "_id" : ObjectId("50f7e19da5c1776d2865a0c5"), "a" : 1 }
>
After I tested some options. I should do something. Then I copied mongodb-linux-x86_64-2.2.2 folder on "centos" machine to another machine. I started it as Master.
[surachart@centos mongo]$ ./bin/mongod --master
Thu Jan 17 18:37:13 [initandlisten] MongoDB starting : pid=1637 port=27017 dbpath=/data/db/ master=1 64-bit host=centos
Thu Jan 17 18:37:13 [initandlisten] db version v2.2.2, pdfile version 4.5
Thu Jan 17 18:37:13 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Thu Jan 17 18:37:13 [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
Thu Jan 17 18:37:13 [initandlisten] options: { master: true }
Thu Jan 17 18:37:14 [initandlisten] journal dir=/data/db/journal
Thu Jan 17 18:37:14 [initandlisten] recover : no journal files present, no recovery needed
Thu Jan 17 18:37:14 [initandlisten] ******
Thu Jan 17 18:37:14 [initandlisten] creating replication oplog of size: 944MB...
Thu Jan 17 18:37:14 [FileAllocator] allocating new datafile /data/db/local.ns, filling with zeroes...
Thu Jan 17 18:37:14 [FileAllocator] creating directory /data/db/_tmp
Thu Jan 17 18:37:14 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB,  took 0.008 secs
Thu Jan 17 18:37:14 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
Thu Jan 17 18:37:14 [FileAllocator] done allocating datafile /data/db/local.0, size: 1024MB,  took 0.184 secs
Thu Jan 17 18:37:14 [initandlisten] ******
Thu Jan 17 18:37:14 [initandlisten] waiting for connections on port 27017
Thu Jan 17 18:37:14 [websvr] admin web console waiting for connections on port 28017
Thu Jan 17 18:37:34 [initandlisten] connection accepted from 192.168.111.14:63933 #1 (1 connection now open)
Thu Jan 17 18:37:34 [conn1] end connection 192.168.111.14:63933 (0 connections now open)
On another machine, it's "centostest1". I started it as Slave.
[surachart@centostest1 mongo]$ ./bin/mongod --slave --source centos:27017
Thu Jan 17 18:40:59 [initandlisten] MongoDB starting : pid=1571 port=27017 dbpath=/data/db/ slave=1 64-bit host=centostest1
Thu Jan 17 18:40:59 [initandlisten] db version v2.2.2, pdfile version 4.5
Thu Jan 17 18:40:59 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Thu Jan 17 18:40:59 [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
Thu Jan 17 18:40:59 [initandlisten] options: { slave: true, source: "centos:27017" }
Thu Jan 17 18:40:59 [initandlisten] journal dir=/data/db/journal
Thu Jan 17 18:40:59 [initandlisten] recover : no journal files present, no recovery needed
Thu Jan 17 18:41:00 [initandlisten] preallocateIsFaster=true 8.34
Thu Jan 17 18:41:01 [initandlisten] preallocateIsFaster=true 12.22
Thu Jan 17 18:41:03 [initandlisten] preallocateIsFaster=true 15
Thu Jan 17 18:41:03 [initandlisten] preallocateIsFaster check took 3.421 secs
Thu Jan 17 18:41:03 [initandlisten] preallocating a journal file /data/db/journal/prealloc.0
Thu Jan 17 18:41:06 [initandlisten]             566231040/1073741824    52%
Thu Jan 17 18:41:09 [initandlisten]             880803840/1073741824    82%
Thu Jan 17 18:41:12 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
Thu Jan 17 18:41:15 [initandlisten]             671088640/1073741824    62%
Thu Jan 17 18:41:19 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
Thu Jan 17 18:41:22 [initandlisten]             744488960/1073741824    69%
Thu Jan 17 18:41:27 [websvr] admin web console waiting for connections on port 28017
Thu Jan 17 18:41:27 [initandlisten] waiting for connections on port 27017
Thu Jan 17 18:41:29 [FileAllocator] allocating new datafile /data/db/local.ns, filling with zeroes...
Thu Jan 17 18:41:29 [FileAllocator] creating directory /data/db/_tmp
Thu Jan 17 18:41:30 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB,  took 0.075 secs
Thu Jan 17 18:41:30 [FileAllocator] allocating new datafile /data/db/local.0, fi
Thu Jan 17 18:41:30 [FileAllocator] done allocating datafile /data/db/local.0, s
Thu Jan 17 18:41:30 [FileAllocator] allocating new datafile /data/db/local.1, fi
Thu Jan 17 18:41:30 [FileAllocator] done allocating datafile /data/db/local.1, s
Thu Jan 17 18:41:30 [replslave] build index local.sources { _id: 1 }
Thu Jan 17 18:41:30 [replslave] build index done.  scanned 0 total records. 0.59
Thu Jan 17 18:41:30 [replslave] repl: syncing from host:centos:27017
Thu Jan 17 18:41:30 [replslave] build index local.me { _id: 1 }
Thu Jan 17 18:41:31 [replslave] build index done.  scanned 0 total records. 0.08
Thu Jan 17 18:41:31 [replslave] resync: dropping database test
Thu Jan 17 18:41:32 [replslave] removeJournalFiles
Thu Jan 17 18:41:32 [replslave] resync: cloning database test to get an initial
Thu Jan 17 18:41:32 [FileAllocator] allocating new datafile /data/db/test.ns, fi
Thu Jan 17 18:41:32 [FileAllocator] done allocating datafile /data/db/test.ns, s
Thu Jan 17 18:41:32 [FileAllocator] allocating new datafile /data/db/test.0, fil
Thu Jan 17 18:41:32 [FileAllocator] done allocating datafile /data/db/test.0, si
Thu Jan 17 18:41:32 [FileAllocator] allocating new datafile /data/db/test.1, fil
Thu Jan 17 18:41:32 [replslave] build index test.test { _id: 1 }
Thu Jan 17 18:41:32 [replslave]          fastBuildIndex dupsToDrop:0
Thu Jan 17 18:41:32 [replslave] build index done.  scanned 1 total records. 0 se
Thu Jan 17 18:41:32 [replslave] resync: done with initial clone for db: test
Thu Jan 17 18:41:32 [FileAllocator] done allocating datafile /data/db/test.1, si
Cool! Tested a bit.
On Master "centos":
[surachart@centos mongo]$ ./bin/mongo
MongoDB shell version: 2.2.2
connecting to: test
> db.test.find()
{ "_id" : ObjectId("50f7e19da5c1776d2865a0c5"), "a" : 1 }
> db.test.save( { b: 2 } )
> db.test.find()
{ "_id" : ObjectId("50f7e19da5c1776d2865a0c5"), "a" : 1 }
{ "_id" : ObjectId("50f7e3be65e911b8888fb813"), "b" : 2 }
>
On Slave "centostest1":
[surachart@centostest1 mongo]$ ./bin/mongo
MongoDB shell version: 2.2.2
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
> db.test.find()
{ "_id" : ObjectId("50f7e19da5c1776d2865a0c5"), "a" : 1 }
> db.test.find()
{ "_id" : ObjectId("50f7e19da5c1776d2865a0c5"), "a" : 1 }
{ "_id" : ObjectId("50f7e3be65e911b8888fb813"), "b" : 2 }
> db.test.save( { c: 3 } )
not master
>
Oh! I spent a half hour. I could install and test a bit. So, I will test more for mongodb then. :)
Reference:
http://www.mongodb.org/display/DOCS/Home

No comments: