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.
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.
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.
Next, select a hostname, in this case we’ll use something able to identify where we are located and what we are doing:
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.
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_18.104.22.1681-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_22.214.171.1241-1_amd64.deb ... Unpacking mongodb-mms-automation-agent-manager (126.96.36.1991-1) ... Setting up mongodb-mms-automation-agent-manager (188.8.131.521-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:
/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
Now that we have our automation agents installed, wait a few seconds and they should begin to report back to Cloud Manager (Deployment - > Agents):
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:
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:
Click the yellow bar on the top to review deploy and allow the agent to install.
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”
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:
Now we have a preview of our new replica set, check all looks right and then click Review & Deploy:
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:
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.