Mongo db 복제(Replication)

Embed Size (px)

DESCRIPTION

mongo db 완벽 가이드 9장 복제 파트 스터디 자료

Citation preview

  • 1. 9
    MongoDB

    http://cafe.naver.com/architect1
    1

2. Single server durability
Single server durability
.
?
DBMS single server durability .
.
?
Multi-server durability .
2
3.




3
4. -
Master
Slave
# mongod --dbpath~/dbs/master --port 10000 --master
# mongod --dbpath~/dbs/slave --port 10001 --slave --source localhost:10000
Slave 0

master

MAX 12
Slave N
oplog
4
5.
5
6. Shell
Master
Slave
Shell slave
6
7.




( ver 1.6+ )
12
7
7
8. ( ver 1.8+ )

  • Replica set

$ mongod --replSetsetname--rest

  • Replica set

> rs.initiate()
> rs.initiate( )
> db.runCommand( { replSetInitiate : } )

  • Configobject

> cfg= {
... _id : "acme_a",
... members :
[ ... { _id : 0, host : "sf1.acme.com" },
... { _id : 1, host : "sf2.acme.com" },
... { _id : 2, host : "sf3.acme.com" } ] }
> rs.initiate(cfg) > rs.status()
> rs.add("sf2.acme.com");
> rs.add("sf3.acme.com");
> rs.status();
http://www.mongodb.org/display/DOCS/Replica+Set+Configuration
8
9.
Node type
(Standard)
(Passive)
{ , Priority : 0, }

(Arbiter)
{ , arbiterOnly : true, }

9
10.

Heartbeat voting


Voting

10
11. Vote:
Slave
Master
Vote:6
Slave
Slave
Slave
Slave
Slave
11
12.
Slave
Master
Vote:2
Slave
Slave
Slave
Slave
Slave
12
13.

Master
Slave
Vote:2
Slave
Slave
Slave
Slave
Slave
13
14.

Master
Vote:3
Slave
Vote:2
Slave
Slave
Slave
Slave
Slave
14
15.

Master
Vote:3
Slave
Vote:2
Slave
Slave
Master
Slave
Slave
Slave
15
16.




16
17.
1. slaveOkey query
2. --master --slave
, .
db
17
18. ( Oplog )
1: CUD command
Master
Slave
5%
2: Oplog
oplog


$inc $set
18
19. ( )
:
Master
Slave
oplog
oplog
19
20. ( )

Master
Slave
[N]
oplog
20
21. ( )
Master
Slave
~ oplog
oplog
21
22.
local database
Mongodb database
Replica set
Replica set collection
local.system.replset : config
local.oplog.rs : oplog
local.replset.minvalid : ,
Master/Slave replication collection
Master node
local.oplog.$main : oplog
local.slaves
Slave node
local.sources
Other
local.me
22
23.
N
N 2 ~ 3 ( / trade-off )
> db.runCommand( {getLastError: 1, w : N } )
23
24.

Oplog
> db.printReplicationInfo()
configured oplog size: 944.1375732421875MB
log length start to end: 1266secs (0.35hrs)
oplog first event time:Thu Aug 04 2011 23:47:12 GMT+0900
oplog last event time: Fri Aug 05 2011 00:08:18 GMT+0900
now: Fri Aug 05 2011 23:44:46 GMT+0900
> db.printSlaveReplicationInfo()
source: localhost:27017
syncedTo: Fri Aug 05 2011 23:46:11 GMT+0900
$ rm /data/db/local.*
$ mongod --master --oplogSizesize
//slave --autosync
24
25.

/ local db
Slave
repl
local.system.users
> use local
Switched to db local
> db.add.User( repl, password );
{user : repl,
readOnly : false,
pwd : }
25
26.
.
Master-slave
Replica set ( )
Oplog .

Slave query ?
--master or --slaveOkey
26
27.
27