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:
- Download the MongoDB software and source code.
-
Install the MongoDB software and copy the source code to
/usr/src
. - Wait for attachment of the data disk by the deployment coordinator.
- Format and mount the data disk.
- Increase the open files limit for MongoDB.
- Move the MongoDB data, journal, and log files to the data disk.
- Update the MongoDB configuration file with the new paths to the files.
- Store the replica set shared key, if specified, and update the configuration.
- 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:
- Add all database instances to the replica set.
- 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:
- Download the MongoDB software and source code.
-
Install the MongoDB software and copy the source code to
/usr/src
. - Store the replica set shared key, if specified, and update the configuration.
- 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:
- Individual MongoDB servers wait for the deployment coordinator to create and attach the data disk.
- 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.
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 thegcutil 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: