# Deploy MongoDB Cluster on Windows Azure
This package is a libaray based on Ansible and Vagrant to deploy and manage a mongoDB cluster
on Windows Azure. It installs and configures MMS (MongoDB Management System) over MongoDB
Cloud also it uses NewRelic (A software analytics tool suite) to monitor MongoDB cluster servers
and the running services on your cluster. The following steps describe how to manage monogDB
services (Mongod), automate backup/restore over cloud, monitor mongo services and monitor
all running services in your infrastructure to make sure that it satisfies the availability and
consistency of Mongo database.
## Table of Contents
* [Basic Cluster Architecture](#Basic_Cluster_Architecture)
* [Install and Configure Vagrant](#Install_and_Configure_Vagrant)
* [Install Windows Azure CLI](#Install_Windows_Azure_CLI)
* [Create and manage Azure's certificates](#Create_and_manage_Azure_certificates)
* [Install and Configure Ansible](#Install_and_Configure_Ansible)
* [Configure your Vagrant File](#Configure_your_Vagrant_File)
* [Edit/Create Hosts file](#Edit/Create_Hosts_file)
* [Configure secret and admin passwords](#Configure_secret_and_admin_passwords)
* [NewRelic Server Monitor](#NewRelic_Server_Monitor)
* [MongoDB Management Service (MMS)](#MongoDB_Management_Service)
* [Start MongoDB Deployment](#Start_MongoDB_Deployment)
* [Backup/Restore management using MMS](#BackupRestore_management_using_MMS)
* [MongoDB Member Recovery](#MongoDB_Member_Recovery)
<a name="Basic_Cluster_Architecture"/ rel='nofollow' onclick='return false;'>
## Basic Cluster Architecture

<a name="Install_and_Configure_Vagrant"/ rel='nofollow' onclick='return false;'>
## Install and Configure Vagrant
**Install Vagrant on Ubuntu distribution:**
$ sudo apt-get install vagrant
but I suggest to install Vagrant Binary from [here](http://www.vagrantup.com/downloads.html)
**Install Azure Vagrant Plugin**
$ vagrant plugin install vagrant-azure
**Download this dummy box that vagrant need to use the azure provider**
$ vagrant box add azure https://github.com/msopentech/vagrant-azure/raw/master/dummy.box
<a name="Install_Windows_Azure_CLI"/ rel='nofollow' onclick='return false;'>
## Install Windows Azure CLI
**1. Ubuntu 12.04 LTS Precise Pangolin:**
$ sudo apt-get install curl
$ curl -sL https://deb.nodesource.com/setup | sudo bash -
$ sudo apt-get install -y nodejs
$ sudo npm install -g azure-cli
**2. Ubuntu 14.04 LTS Trusty Tahr:**
$ sudo apt-get install nodejs-legacy
$ sudo apt-get install npm
$ sudo npm install -g azure-cli
$ azure
info: _ _____ _ ___ ___
info: /_\ |_ / | | | _ \ __|
info: _ ___/ _ \__/ /| |_| | / _|___ _ _
info: (___ /_/ \_\/___|\___/|_|_\___| _____)
info: (_______ _ _) _ ______ _)_ _
info: (______________ _ ) (___ _ _)
info:
info: Microsoft Azure: Microsoft's Cloud Platform_
info:
info: Tool version 0.9.5
help:
help: Display help for a given command
help: help [options] [command]
help:
help: Log in to an Azure subscription using Active Directory. Currently, the user can login only via Microsoft organizational account
help: login [options] [username]
help:
help: Log out from Azure subscription using Active Directory. Currently, the user can log out only via Microsoft organizational account
help: logout [options] [username]
help:
help: Open the portal in a browser
help: portal [options]
help:
help: Commands:
help: account Commands to manage your account information and publish settings
help: config Commands to manage your local settings
help: hdinsight Commands to manage HDInsight clusters and jobs
help: mobile Commands to manage your Mobile Services
help: network Commands to manage your Networks
help: sb Commands to manage your Service Bus configuration
help: service Commands to manage your Cloud Services
help: site Commands to manage your Web Sites
help: sql Commands to manage your SQL Server accounts
help: storage Commands to manage your Storage objects
help: vm Commands to manage your Virtual Machines
help:
help: Options:
help: -h, --help output usage information
help: -v, --version output the application version
<a name="Create_and_manage_Azure_certificates"/ rel='nofollow' onclick='return false;'>
## Create and manage Azure's certificates
**1. Download your Management Certificate for Azure CLI:**
$ azure account download
info: Executing command account download
info: Launching browser to **http://go.microsoft.com/fwlink/?LinkId=254**
help: Save the downloaded file, then execute the command
help: account import <file>
info: account download command OK
keep this file in safe place.
**2. Import the certificate to your azure account**
$ azure account import myfile.publishsettings
info: Executing command account import
info: account import command OK
**3. Check your account list:**
$ azure account list
info: Executing command account list
data: Name Id Tenant Id Current
data: -------- ------------------------------------ --------- -------
data: ACCOUNT b80dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx undefined true
info: account list command OK
**4. Create an X.509 certificate to authenticate with Azure**
$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout cert.pem -out cert.pem
**5. Create Microsoft Parallel FX from the X.509 cert**
#Enter the encryption password
$ openssl pkcs12 -export -out cert.pfx -in cert.pem -name "My Cert"
**6.Create service certificate to upload to Azure**
$ openssl x509 -inform pem -in cert.pem -outform der -out cert.cer
Now login to Azure management portal [here](https://manage.windowsazure.com) to upload .cer file certificate
SETTINGS --> MANAGEMENT CERTIFICATES --> UPLOAD
**7. Create RSA private keys**
Do not do this step if you have a RSA private key to check use `ls ~/.ssh/` and skip to login keys
Create RSA private key so that you can log in with your normal credentials
$ ssh-keygen -t rsa
Create login keys
$ openssl req -new -x509 -key ~/.ssh/id_rsa -out ~/.ssh/ssh-cert.pem
**8. Copy all certificates to cert directory**
$ cp cert.* cert/
<a name="Install_and_Configure_Ansible"/ rel='nofollow' onclick='return false;'>
## Install and Configure Ansible
**Ubuntu LTS 12.04**
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible
**Other Linux Distributions**
to install on another Linux Distribution check out [Ansible Docs](http://docs.ansible.com/intro_installation.html)
<a name="Configure_your_Vagrant_File"/ rel='nofollow' onclick='return false;'>
## Configure your Vagrant File
**Open Vagrantfile, and edit the following lines:**
azure.subscription_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
azure.storage_acct_name = 'YOUR_STORAGE_ACCOUNT'
azure.vm_user = 'ahmed' # change to username on your local host
azure.ssh_private_key_file = '/home/ahmed/.ssh/id_rsa' # change the path of id_rsa to yours
azure.ssh_certificate_file = '/home/ahmed/.ssh/ssh-cert.pem' # change the path of ssh-cer.pem to yours
....
azure.ssh_port = 2200
azure.tcp_endpoints = '40000:40000,40001:10100,40002:10400'
**To Add new replica server uncomment the following block**
where this section describes a n