블로그 이미지
윤영식
Frontend Application Architecter, Full Stacker, KnowHow Dispenser and Bike Rider

Publication

Statistics Graph

Recent Comment

'Master/Slave'에 해당되는 글 1

  1. 2013.07.27 [MongoDB] Master/Slave 만들기
2013.07.27 12:28 MongoDB/Prototyping

몽고디비의 마스터/슬레이브 환경을 만들어서 fault tolerance 시스템을 구성해 본다



1. 마스터 만들기

  - 옵션 : --master

mongodb_2.4.5> mongod --dbpath /mongodb_2.4.5/master --master --port 38000
Sat Jul 27 11:50:39.279 [initandlisten] MongoDB starting : pid=70914 port=38000 dbpath=mongodb_2.4.5/master master=1 64-bit host=nulpulum-mac-13-retina.local
Sat Jul 27 11:50:39.279 [initandlisten] db version v2.4.5
.. 중략 ..
Sat Jul 27 11:50:39.347 [websvr] admin web console waiting for connections on port 39000
Sat Jul 27 11:50:39.347 [initandlisten] waiting for connections on port 38000
Sat Jul 27 11:51:47.344 [initandlisten] connection accepted from 127.0.0.1:63461 #1 (1 connection now open)


mongodb_2.4.5> mongo --port 38000
MongoDB shell version: 2.4.5
connecting to: 127.0.0.1:38000/test
> show dbs
local    0.328125GB

> db.printReplicationInfo()
configured oplog size:   192MB
log length start to end: 317secs (0.09hrs)
oplog first event time:  Sat Jul 27 2013 11:50:16 GMT+0900 (KST)
oplog last event time:   Sat Jul 27 2013 11:55:33 GMT+0900 (KST)
now:                     Sat Jul 27 2013 11:55:36 GMT+0900 (KST)

> db.printSlaveReplicationInfo()
local.sources is empty; is this db a --slave?
> db.printShardingStatus()
printShardingStatus: this db does not have sharding enabled. be sure you are connecting to a mongos from the shell and not to a mongod.



2. slave 만들기

  - 옵션 : --slave  --source <master 위치>

mongodb_2.4.5> mongod --dbpath /mongodb_2.4.5/slave --slave --port 48000 --source localhost:38000
Sat Jul 27 12:04:55.853 [initandlisten] MongoDB starting : pid=70927 port=48000 dbpath=mongodb_2.4.5/slave slave=1 64-bit host=nulpulum-mac-13-retina.local
Sat Jul 27 12:04:55.853 [initandlisten] options: { dbpath: "/mongodb_2.4.5/slave", port: 48000, slave: true, source: "localhost:38000" }
Sat Jul 27 12:04:56.891 [replslave] build index done.  scanned 0 total records. 0 secs


  - master의 내역확인: slave하나가 연결되었다

Sat Jul 27 11:51:47.344 [initandlisten] connection accepted from 127.0.0.1:63461 #1 (1 connection now open)
Sat Jul 27 12:04:56.889 [initandlisten] connection accepted from 127.0.0.1:63547 #2 (2 connections now open)
Sat Jul 27 12:04:57.896 [slaveTracking] build index local.slaves { _id: 1 }
Sat Jul 27 12:04:57.897 [slaveTracking] build index done.  scanned 0 total records. 0 secs


  - slave 하나더 만들기

mongodb_2.4.5> mongod --dbpath /mongodb_2.4.5/slave2 --slave --port 58000 --source localhost:38000
Sat Jul 27 12:08:53.817 [initandlisten] MongoDB starting : pid=70932 port=58000 dbpath=mongodb_2.4.5/slave2 slave=1 64-bit host=nulpulum-mac-13-retina.local
Sat Jul 27 12:08:53.818 [initandlisten] options: { dbpath: "/mongodb_2.4.5/slave2", port: 58000, slave: true, source: "localhost:38000" }
Sat Jul 27 12:08:55.069 [replslave] build index local.me { _id: 1 }
Sat Jul 27 12:08:55.070 [replslave] build index done.  scanned 0 total records. 0 secs



3. REPL로 작업하고 확인하기

  - 연결 : mongo <주소:port>

////////////////// slave 1번

mongodb_2.4.5> mongo  localhost:48000
MongoDB shell version: 2.4.5
connecting to: localhost:48000/test
> db.printSlaveReplicationInfo()
source:   localhost:38000
     syncedTo: Sat Jul 27 2013 12:09:53 GMT+0900 (KST)
         = 74 secs ago (0.02hrs)
> ^C
bye

////////////////// slave 2번
mongodb_2.4.5> mongo  localhost:58000
MongoDB shell version: 2.4.5
connecting to: localhost:58000/test
> db.printSlaveReplicationInfo()
source:   localhost:38000
     syncedTo: Sat Jul 27 2013 12:08:53 GMT+0900 (KST)
         = 144 secs ago (0.04hrs)
> ^C
bye

////////////////// master
mongodb_2.4.5> mongo  localhost:38000
MongoDB shell version: 2.4.5
connecting to: localhost:38000/test
> db.printSlaveReplicationInfo()
local.sources is empty; is this db a --slave?


  - master에 데이터 넣고 master에서 save한것이 slave로 복제되는지 확인하기

////////////////// master

> use dowon
switched to db dowon
> db.youngsik.save({name:'dowon', age:22});
> db.youngsik.find();
{ "_id" : ObjectId("51f33a81dbed34cf65d102d0"), "name" : "dowon", "age" : 22 }
> show dbs
config    (empty)
dowon    0.203125GB
local    0.328125GB
> ^C
bye

////////////////// slave 1번
mongodb_2.4.5> mongo  localhost:48000
MongoDB shell version: 2.4.5
connecting to: localhost:48000/test
> show dbs
dowon    0.203125GB
local    0.078125GB
> use dowon
switched to db dowon
> show collections
system.indexes
youngsik
> db.youngsik.find();
{ "_id" : ObjectId("51f33a81dbed34cf65d102d0"), "name" : "dowon", "age" : 22 }
>

////////////////// slave 2번

mongodb_2.4.5> mongo  localhost:58000
MongoDB shell version: 2.4.5
connecting to: localhost:58000/test
> use dowon
switched to db dowon
> show collections
system.indexes
youngsik
> db.youngsik.find();
{ "_id" : ObjectId("51f33a81dbed34cf65d102d0"), "name" : "dowon", "age" : 22 }


  - 파일 시스템 확인하기 : master, slave, slave2

mongodb_2.4.5/slave2>

-rwxr-xr-x   1 nulpulum  staff          6  7 27 12:08 mongod.lock
drwxr-xr-x   4 nulpulum  staff        136  7 27 12:12 journal
-rw-------   1 nulpulum  staff  134217728  7 27 12:12 dowon.1
drwxr-xr-x   2 nulpulum  staff         68  7 27 12:12 _tmp
-rw-------   1 nulpulum  staff   16777216  7 27 12:12 local.ns
-rw-------   1 nulpulum  staff   16777216  7 27 12:12 dowon.ns
-rw-------   1 nulpulum  staff   67108864  7 27 12:12 dowon.0
-rw-------   1 nulpulum  staff   67108864  7 27 12:21 local.0

mongodb_2.4.5/slave>
-rwxr-xr-x   1 nulpulum  staff          6  7 27 12:04 mongod.lock
drwxr-xr-x   4 nulpulum  staff        136  7 27 12:12 journal
-rw-------   1 nulpulum  staff  134217728  7 27 12:12 dowon.1
drwxr-xr-x   2 nulpulum  staff         68  7 27 12:12 _tmp
-rw-------   1 nulpulum  staff   16777216  7 27 12:12 local.ns
-rw-------   1 nulpulum  staff   16777216  7 27 12:13 dowon.ns
-rw-------   1 nulpulum  staff   67108864  7 27 12:13 dowon.0
-rw-------   1 nulpulum  staff   67108864  7 27 12:23 local.0


mongodb_2.4.5/master>
-rwxr-xr-x   1 nulpulum  staff          6  7 27 11:50 mongod.lock
drwxr-xr-x   4 nulpulum  staff        136  7 27 11:51 journal
-rw-------   1 nulpulum  staff   67108864  7 27 12:05 local.0
-rw-------   1 nulpulum  staff  134217728  7 27 12:12 dowon.1
drwxr-xr-x   2 nulpulum  staff         68  7 27 12:12 _tmp
-rw-------   1 nulpulum  staff   16777216  7 27 12:12 dowon.ns
-rw-------   1 nulpulum  staff   67108864  7 27 12:12 dowon.0
-rw-------   1 nulpulum  staff   16777216  7 27 12:22 local.ns
-rw-------   1 nulpulum  staff  268435456  7 27 12:22 local.1



<참조>

  - 10Gen Master/Slave 메뉴얼

저작자 표시 비영리 변경 금지
신고
posted by peter yun 윤영식
prev 1 next