Cloud Manager Automation with DigitalOcean

Jay Gordon

#Cloud

Cloud Manager automation is an easy way to create new MongoDB deployments without having to do much of the underlying configuration work. This post is how you can get started using automation on your droplets.

A note: This does not provide details on configuring security for your system. Please review our documentation on configuring MongoDB with iptables on Linux.

Initial setup:

Let’s begin by determining what our use case and requirements are for our application. I think today I will start by working on a simple three node replica set using 1GB sized droplets. First ensure you’ve got credit and the appropriate ssh key you plan on working imported to your account.

https://webassets.mongodb.com/_com_assets/blog/tblr/66.media.tumblr.com--92ba6c5e72d79436fb127ccab9a304a8--tumblr_o6xclnmiHF1sdaytmo2_1280.png

First I’ve created the three droplets required, I am using Ubuntu 14.04 LTS x64, however feel free whichever of the supported versions we have agents for. Cloud Manager supports many different OSs and has a number of agents available. DigitalOcean has a Private Networking option, making it easy to configure your deployment securely. When creating these new droplets, it’s a good idea to enable this service.

https://webassets.mongodb.com/_com_assets/blog/tblr/67.media.tumblr.com--4f6dbaa2f6410ab2cb817f8eb1a436b9--tumblr_o6xclnmiHF1sdaytmo1_1280.png

Next, select a hostname, in this case we’ll use something able to identify where we are located and what we are doing:

https://webassets.mongodb.com/_com_assets/blog/tblr/67.media.tumblr.com--133120f5f2a414abb321a2257097bf1b--tumblr_o6xclnmiHF1sdaytmo3_1280.png

Configuring the Droplets:

Your droplets will need a few post-configuration options for our automation to begin working correctly.

Hostname and Private IPs

SSH into your droplets and validate their hostname:

root@mongodb-1gb-nyc2-01:~# hostname -f
mongodb-1gb-nyc2-01

root@mongodb-1gb-nyc2-02:~# hostname -f
mongodb-1gb-nyc2-02

root@mongodb-1gb-nyc2-03:~# hostname -f
mongodb-1gb-nyc2-03

Review each host’s private IP:

root@mongodb-1gb-nyc2-01:~# /sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2| cut -d' ' -f1
10.128.32.63

root@mongodb-1gb-nyc2-02:~# /sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2| cut -d' ' -f1
10.128.32.64

root@mongodb-1gb-nyc2-03:~# /sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2| cut -d' ' -f1
10.128.32.66

Create hosts file entry for each site and then enter it into each server’s /etc/hosts/ file:

10.128.32.63 mongodb-1gb-nyc2-01
10.128.32.64 mongodb-1gb-nyc2-02
10.128.32.66 mongodb-1gb-nyc2-03

Our entire /etc/hosts file example for mongodb-1gb-nyc2-01:

127.0.1.1 mongodb-1gb-nyc2-01 mongodb-1gb-nyc2-01
127.0.0.1 localhost

10.128.32.63 mongodb-1gb-nyc2-01
10.128.32.64 mongodb-1gb-nyc2-02
10.128.32.66 mongodb-1gb-nyc2-03

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Test you can ping by name from a host:

root@mongodb-1gb-nyc2-01:~# ping mongodb-1gb-nyc2-02
PING mongodb-1gb-nyc2-02 (10.128.32.64) 56(84) bytes of data.
64 bytes from mongodb-1gb-nyc2-02 (10.128.32.64): icmp_seq=1 ttl=64 time=1.75 ms

Install the automation agent on all three:

Next, we install the automation agent to all three servers. Log onto your Cloud Manager Deployment, click the “Agents” tab and you’ll then find a tab titled “Downloads & Setttings.” Here you will be able to review the different agents available, in this case we will use the Ubuntu (12.X, 14.X) - DEB agent.

https://webassets.mongodb.com/_com_assets/blog/tblr/65.media.tumblr.com--238776b002da267be18834f80241ed8a--tumblr_o6xclnmiHF1sdaytmo4_1280.png

Once you click this link, you’ll see a set of instructions on how to install the agent, enter the appropriate API key information and how to prep your data directory for the MongoDB database files. To save time, you can repeat each step of these instructions in parallel across servers with the same OS, on Mac OS X I’ve found iTerm 2 useful for this feature along with ClusterSSH in Linux.

Install the package as instructions say and then start the agent across your three droplets:

root@mongodb-1gb-nyc2-01:~# sudo dpkg -i mongodb-mms-automation-agent-manager_2.7.1.1631-1_amd64.deb
Selecting previously unselected package mongodb-mms-automation-agent-manager.
(Reading database ... 86823 files and directories currently installed.)
Preparing to unpack mongodb-mms-automation-agent-manager_2.7.1.1631-1_amd64.deb ...
Unpacking mongodb-mms-automation-agent-manager (2.7.1.1631-1) ...
Setting up mongodb-mms-automation-agent-manager (2.7.1.1631-1) ...
Adding system user `mongodb' (UID 106) ...
Adding new user `mongodb' (UID 106) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 114) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
Processing triggers for ureadahead (0.100.0-16) …

Open the config file, add your API and Group information in the file as recommended:

sudo vi /etc/mongodb-mms/automation-agent.config

This file may look something like this, just paste in the key values given to you in the installer instructions on the Cloud Manager UI:

#
# REQUIRED
# Enter your Group ID - It can be found at https://cloud.mongodb.com/settings/group
#
mmsGroupId=


#
# REQUIRED
# Enter your API key - It can be found at https://cloud.mongodb.com/settings/group
#
mmsApiKey=

Save the file and close it up

Prep your data directory

The default location we normally like to recommend is /data. You may choose a different directory but it must be configured with much of the same values:

Prepare the /data directory to store your MongoDB data. This directory must be owned by the mongodb user.

sudo mkdir -p /data
sudo chown mongodb:mongodb /data 

Start your agent (startup method may depend on your OS install):

And finally let’s start the agent!

sudo start mongodb-mms-automation-agent
mongodb-mms-automation-agent start/running

Monitoring Agent

Now that we have our automation agents installed, wait a few seconds and they should begin to report back to Cloud Manager (Deployment - > Agents):

https://webassets.mongodb.com/_com_assets/blog/tblr/66.media.tumblr.com--91634a0402cef6b27eb4b8099bedc28a--tumblr_o6xclnmiHF1sdaytmo7_1280.png

As the red box says, we’re not quite ready to get started. We still need to install a monitoring agent, which we can do right here from Cloud Manager’s UI. Be aware, unlike the automation agent, the monitoring agent only requires installation on one server in your group. [You can review this detailed blog post on agents and how many are required for additional information on this subject] (http://blog.cloud.mongodb.com/post/120124825840/how-many-agents-do-i-need-and-why/).

First, go to the Server’s tab under Deployment. Your droplets should be visible here:

https://webassets.mongodb.com/_com_assets/blog/tblr/66.media.tumblr.com--4a0795582c093353c2543d8b06b8b33a--tumblr_o6xcm60nFG1sdaytmo4_1280.png

Since we only require this monitoring agent on one of the nodes, we can go ahead and just click the “…” and then select to install the monitoring agent. We’ll do this on mongodb-1gb-nyc02-01:

https://webassets.mongodb.com/_com_assets/blog/tblr/67.media.tumblr.com--211345cebeeae974d2491b1a337a268a--tumblr_o6xcm60nFG1sdaytmo1_1280.png

Click the yellow bar on the top to review deploy and allow the agent to install.

https://webassets.mongodb.com/_com_assets/blog/tblr/67.media.tumblr.com--b203824d38443aa670652fbc77c49eb7--tumblr_o6xclnmiHF1sdaytmo6_1280.png

Automate your installation:

Now we are finally ready to configure our systems to run with MongoDB as a replica set.

Click Deployment and then find the green +ADD button, and select “New Replica Set”

https://webassets.mongodb.com/_com_assets/blog/tblr/66.media.tumblr.com--005f3b277431ce6778011d127f9cb4c2--tumblr_o6xcm60nFG1sdaytmo3_500.png

This will bring up your replica set configuration setting within your Cloud Manager UI, you can then set your systems and MongoDB configuration here for your new deployment, then click apply:

https://webassets.mongodb.com/_com_assets/blog/tblr/67.media.tumblr.com--fb72c575be92558fca8aad23aa0867b9--tumblr_o6xclnmiHF1sdaytmo5_1280.png

Now we have a preview of our new replica set, check all looks right and then click Review & Deploy:

https://webassets.mongodb.com/_com_assets/blog/tblr/65.media.tumblr.com--26cba3fdf6b7a819d7397ebdda4537f2--tumblr_o6xcm60nFG1sdaytmo2_1280.png

Now Wait…

Now wait and you should see your deployment begin, in but a few minutes you should then see your new DigitalOcean MongoDB Cluster in the Cloud Manager UI:

https://webassets.mongodb.com/_com_assets/blog/tblr/66.media.tumblr.com--4b2472ae7fef7499524ab362c9114b6f--tumblr_o6xcm60nFG1sdaytmo5_1280.png

That’s it, MongoDB has been deployed on your droplets. At this time, it’s a good idea to begin the process of configuring your MongoDB authentication and security of your network. Once you’ve done these tasks, you can begin inserting your data and working to develop your application.

Jay Gordon is a Technical Account Manager with MongoDB and is available via our chat to discuss Cloud Manager at cloud.mongodb.com