Quickly build a MongoDB cluster on an Azure virtual machine

Source: Internet
Author: User
Tags mongo shell

MongoDB is a very popular database currently on the NoSQL market, this article describes how to use Azure PowerShell and the azure CLI to build a single node MongoDB (test use) on azure virtual machines and multi-node M with master-slave replication and Shard clusters ONGODB (production environment use).

Preparation steps
  • If you chose Azure PowerShell to build MongoDB, then install Azure PowerShell on your local computer as described in how to install and configure Azure PowerShell. Then open the Azure PowerShell command prompt to sign in with your work or school ID by running the following command and following the interactive sign-in experience of prompting for your Azure account:

    Login-azurermaccount-environmentname Azurechinacloud

    Then you need to create an Azure resource group (Resource Group), create an azure virtual machine and build MongoDB both in that resource group, and run the following command to create an Azure resource group:

    New-azurermresourcegroup-name "Your-resource-group-name"-location "China East"

  • If you chose Azure CLI to build MongoDB, then install the Azure CLI. Then make sure that you are in Resource Manager mode and that you can verify by running the following command:

    Azure Config mode arm

    Now sign in with your work or school ID by running the following command and following the interactive sign-in experience of prompting for your Azure account:

    Azure Login-e azurechinacloud-u <your account>

    Then you need to create an Azure resource group (Resource Group), create an azure virtual machine and build MongoDB both in that resource group, and run the following command to create an Azure resource group:

    Azure Group Create "Your-resource-group-name" "China East"

Get started.

Warning

You need to run PowerShell with administrator privileges before you use the following command:

Set-executionpolicy-executionpolicy Unrestricted

1. Building a single node MongoDB on an azure virtual machine

By default, the following script creates 1 CentOS virtual machines, which form a single node MongoDB. The following is a main introduction to Azure PowerShell mode
You need to download the PowerShell script mongodb-singlenode-deploy.ps1, run the Mongodb-install-centos.ps1 script as in the following example to generate a CentOS virtual machine in the resource group RG1 A single node MongoDB is then installed on the virtual machine.

PS c:\mongodb>. \mongodb-singlenode-deploy.ps1-resourcegroupname rg1-adminusername Azureuser-adminpassword " Your-password "  -centosversion 6.5-vmname mongodbserver

The creation process takes about 6 minutes, and after successful operation, the following prompt appears:

Deploy MongoDB on VM mongodb11 (CentOS 6.5) in the north successfully.    To connect using the MONGO Shell:    % MONGO Mongodbserver.chinanorth.cloudapp.chinacloudapi.cn:27017/test

2. Build MongoDB with master-slave replication node on azure virtual machine

By default, the following script creates 3 CentOS VMs that comprise a MongoDB replica set that will contain a pirmary node and 2 secondary nodes, as shown in the schema:

Azure PowerShell Mode

You need to download PowerShell script Mongodb-replica-set-deploy.ps1, run the Mongodb-replica-set-deploy.ps1 script in the following example to generate multiple CentOS in the resource group RG1 Virtual machine, which will then be built on the virtual machine with a master-slave replication node MongoDB.

PS c:\mongodb>.\mongodb-replica-set-deploy.ps1-resourcegroupname rg1-centosversion 7.2-adminusername azureuser- AdminPassword "Your-password"-mongousername Mongoadmin-mongopassword "Your-password"-DNSNamePrefix mongoreplicaset

The creation process takes about 10 minutes, and after successful operation, the following prompt appears:

Deploy MongoDB Replica Set successfully. To connect primary node using the MONGO shell:% MONGO mongoreplicaset.chinanorth.cloudapp.chinacloudapi.cn:27017to Connect secondary NODE0 using the MONGO shell:% MONGO mongoreplicasetsecondary0.chinanorth.cloudapp.chinacloudapi.cn : 27017To Connect secondary node1 using the MONGO shell:% MONGO mongoreplicasetsecondary1.chinanorth.cloudapp.chinacloudapi.cn:27017

3. Building a MongoDB shard cluster on an Azure virtual machine

By default, the following script will create 11 CentOS virtual machines, comprising: 2 router servers, 3 config servers, 2 shards, each with 1 Priamry nodes and 2 secondary nodes, with a total of 11 nodes, as shown in the schema:

Azure PowerShell Mode

You need to download PowerShell script MONGODB-SHARDING-DEPLOY.PS1 and run the Mongodb-sharding-deploy.ps1 script in the following example to generate multiple CentOS virtual machines in the resource group RG1. Then the virtual machine will be built with the master-slave replication node and the Shard cluster MongoDB, the creation process takes about 1 hours and 15 minutes.

PS c:\mongodb>.\mongodb-sharding-deploy.ps1-resourcegroupname rg1-centosversion 7.2-adminusername azureuser- AdminPassword "Your-password"-mongousername Mongoadmin-mongopassword "Your-password"-DNSNamePrefix Mongoshard

For another:Azure CLI approach, interested friends can click here to view.

Quickly build a MongoDB cluster on an Azure virtual machine

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.