Perhaps the most important job of any MongoDB administrator is making sure that replication is set up and functioning correctly. Use of MongoDB’s replication functionality is always recommended in production settings, especially since the current storage engine does not provide single-server durability (see Appendix C for details). Replicas can be used purely for failover and data integrity, or they can be used in more advanced ways, such as for scaling out reads, taking hot backups, or as a data source for offline batch processing. In this chapter, we’ll cover everything you need to know about replication.
Figure 9-1. A master with one slave
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,
mongod --master. To start a slave, run
mongod --slave --source
master_address is the address 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 $ ...