Databases Reference
In-Depth Information
Figure 9-2. A master with three slaves
The basic setup is to start a master node and one or more slave nodes, each of which
knows the address of the master. To start the master, run mongod --master . To start a
slave, run mongod --slave --source master_address , where master_address is the ad-
dress of the master node that was just started.
It is simple to try this on a single machine, although in production you would use
multiple servers. First, create a directory for the master to store data in and choose a
port (10000):
$ mkdir -p ~/dbs/master
$ ./mongod --dbpath ~/dbs/master --port 10000 --master
Now set up the slave, choosing a different data directory and port. For a slave, you also
need to tell it who its master is with the --source option:
$ mkdir -p ~/dbs/slave
$ ./mongod --dbpath ~/dbs/slave --port 10001 --slave --source localhost:10000
All slaves must be replicated from a master node. There is currently no mechanism for
replicating from a slave ( daisy chaining ), because slaves do not keep their own oplog
(see “How It Works” on page 138 for more on the oplog).
There is no explicit limit on the number of slaves in a cluster, but having a thousand
slaves querying a single master will likely overwhelm the master node. In practice,
clusters with less than a dozen slaves tend to work well.
Options
There are a few other useful options in conjunction with master-slave replication:
--only
Use on a slave node to specify only a single database to replicate. (The default is
to replicate all databases.)
 
Search WWH ::




Custom Search