Skip to Content
MongoDB: The Definitive Guide
book

MongoDB: The Definitive Guide

by Kristina Chodorow, Michael Dirolf
September 2010
Intermediate to advanced
214 pages
5h 30m
English
O'Reilly Media, Inc.
Content preview from MongoDB: The Definitive Guide

Chapter 9. Replication

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.

Master-Slave Replication

Master-slave replication is the most general replication mode supported by MongoDB. This mode is very flexible and can be used for backup, failover, read scaling, and more (see Figures 9-1 and 9-2).

A master with one slave
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, run mongod --master. To start a slave, run mongod --slave --source master_address, where 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 $ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

MongoDB: The Definitive Guide, 2nd Edition

MongoDB: The Definitive Guide, 2nd Edition

Kristina Chodorow
MongoDB in Action, Second Edition

MongoDB in Action, Second Edition

Tim Hawkins, Kyle Banker, Shaun Verch, Douglas Garrett, Peter Bakkum
MongoDB: The Definitive Guide, 3rd Edition

MongoDB: The Definitive Guide, 3rd Edition

Shannon Bradshaw, Eoin Brazil, Kristina Chodorow

Publisher Resources

ISBN: 9781449381578Errata Page