Replication

The Mongo database supports replication of data between servers.

The replication is an enhanced master-slave configuration: that is, only one server is active for writes (the master) at a given time. The primary goal of replication is failover and redundancy.

Mongo supports two forms of replication: simple master-slave configurations, and additionally a replica pair concept.  Please see the following pages for more details:

Security

When security is enabled, one must configure a user account for the local database that exists on both servers.

The slave-side of a replication connection first looks for a user repl in local.system.users. If present, that user is used to authenticate against the local database on the source side of the connection. If repl user does not exist, the first user object in local.system.users is tried.

The local database works like the admin database: an account for local has access to the entire server.

Diagnostics

From the shell

Check master status from the mongo shell with:

// inspects contents of local.oplog.$main on master and reports status:
db.printReplicationInfo()

Check slave status from the mongo shell with:

// inspects contents of local.sources on the slave and reports status:
db.printSlaveReplicationInfo()

(Note you can evaluate the above functions without the parenthesis above to see their javascript source and a bit on the internals.)

As of 1.3.2, you can do this on the slave

db._adminCommand( { serverStatus : 1 , repl : N } )

N is the level of diagnostic information and can have the following values:

  • 0 - none
  • 1 - local (doesn't have to connect to other server)
  • 2 - remote (has to check with the master)

Http Interface

The administrative Http Interace (at port 28017) provides some basic status information on either a master or slave mongod process.

replInfo:  repl: sleep 2sec before next pass
replication
master: 0
slave:  1
initialSyncCompleted: 1

Options

Slave Delay

Sometimes its beneficial to have a slave that is purposefully many hours behind to prevent human error. In MongoDB 1.3.3+, you can specify this with the --slavedelay mongod command line option:

--slavedelay arg      specify delay (in seconds) to be used when applying
                      master ops to slave

See Also


Labels

printreplicationinfo printreplicationinfo Delete
printslavereplicationinfo printslavereplicationinfo Delete
getreplicationinfo getreplicationinfo Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.

These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group.

blog comments powered by Disqus