Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Click-to-deploy MongoDB: How it works

The click-to-deploy MongoDB process on Google Compute Engine is intended to help you get a development or test environment running quickly. This document provides the details that you might need regarding software installation and tuning in order to use your cluster. In addition, you can use this deployment approach as a starting point if you choose to launch and maintain your own production MongoDB cluster. You will learn the steps that were performed and a few best practices for bringing up any cluster on Google Compute Engine.

Objectives

  • Learn about the click-to-deploy process and the optimizations that were made, such as running instances with the least privileges to ensure stability and security.
  • Extend this knowledge to other applications and situations.

Deployment processing

The deployment of the MongoDB cluster is managed by Google Cloud Deployment Manager . Deployment Manager uses templates to help you deploy your configuration. These templates can include actions , which specify shell scripts that can contain specific deployment instructions. In the click-to-deploy templates, these scripts are specific to MongoDB and define the types of Compute Engine instances to create and how to install MongoDB on the instances.

The click-to-deploy templates define three modules:

  • Deployment coordinator
  • MongoDB server
  • MongoDB arbiter

The Compute Engine instances that are associated with each of the modules start concurrently and coordinate the installation and configuration of the MongoDB replica set.

Deployment coordinator module

A single, short-lived deployment coordinator instance is created during the deployment. This instance exists to ensure that the long-running MongoDB server instances can run under the principle of least priviledge .

Automatically creating and attaching of persistent disks to Compute Engine instances requires the authorization of the https://www.googleapis.com/auth/compute OAuth 2.0 scope. Service account scopes are granted to a Compute Engine instances when it is created and exists for the lifespan of that instance.

Rather than granting this scope to the long-running MongoDB server instances, the scope is granted to the deployment coordinator instance. The deployment coordinator creates and attaches a data disk for each MongoDB server instance.

MongoDB server module

When the MongoDB server instances are created, they complete the following steps:

  1. Download the MongoDB software and source code.
  2. Install the MongoDB software and copy the source code to /usr/src .
  3. Wait for attachment of the data disk by the deployment coordinator.
  4. Format and mount the data disk.
  5. Increase the open files limit for MongoDB.
  6. Move the MongoDB data, journal, and log files to the data disk.
  7. Update the MongoDB configuration file with the new paths to the files.
  8. Store the replica set shared key, if specified, and update the configuration.
  9. Set the replica set name in the configuration.

At this point, the configuration of the MongoDB secondary instances is complete. The MongoDB primary instance will connect to MonboDB and complete the following additional steps:

  1. Add all database instances to the replica set.
  2. Add all arbiter instances to the replica set.

On deployment, the MongoDB primary instance is chosen arbitrarily as the MongoDB server whose hostname is first alphabetically.

MongoDB arbiter module

When the MongoDB arbiter instances are created, they complete the following steps:

  1. Download the MongoDB software and source code.
  2. Install the MongoDB software and copy the source code to /usr/src .
  3. Store the replica set shared key, if specified, and update the configuration.
  4. Set the replica set name in the configuration.

Deployment work flow

The following graphic shows the work flow for each of the server types. Most of the steps occur independently. Only two steps need to be coordinated:

  1. Individual MongoDB servers wait for the deployment coordinator to create and attach the data disk.
  2. The primary MongoDB server connects to MongoDB and adds each server and arbiter to the replica set. If a given server or arbiter is not running, this step will block.
Flow chart showing the
    steps involved in deploying each of the server types outlined previously.

Next steps

Configure your virtual machine instances
Use gcutil ssh to connect to the external IP addresses for your machines and perform any system configuration that you might need on each server. You can look up your IP addresses by using the gcutil listinstances command or you can find them in the Developers Console .
Learn about running a production system on Compute Engine

The following resources can help you get up and running with a production cluster on Compute Engine:

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.