博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在 Azure 虚拟机上快速搭建 MongoDB 集群
阅读量:4518 次
发布时间:2019-06-08

本文共 3026 字,大约阅读时间需要 10 分钟。

是目前在 NoSQL 市场上非常受欢迎的一个数据库,本文介绍如何使用 Azure PowerShell 和 Azure CLI 在 Azure 虚拟机上搭建单节点 MongoDB(测试使用)和包含主从复制以及分片集群的多节点 MongoDB(生产环境使用)。

 

准备步骤

  • 如果你选择 Azure PowerShell 方式搭建 MongoDB,那么请按中的说明在本地计算机上安装 Azure PowerShell。然后打开 Azure PowerShell 命令提示符,通过运行以下命令并遵循提示进行 Azure 帐户的交互式登录体验,来使用:

    Login-AzureRmAccount -EnvironmentName AzureChinaCloud

    然后你需要创建一个 Azure 资源组( Resource Group ),创建 Azure 虚拟机和搭建 MongoDB 都在该资源组中进行,运行以下命令创建 Azure 资源组:

    New-AzureRmResourceGroup -Name "YOUR-RESOURCE-GROUP-NAME" -Location "China East"

     

  • 如果你选择 Azure CLI 方式搭建 MongoDB,那么请。然后请确保你是处于下,可通过运行以下命令来验证:

    azure config mode arm

    现在,通过运行以下命令并遵循提示进行 Azure 帐户的交互式登录体验,来使用:

    azure login -e AzureChinaCloud -u 

    然后你需要创建一个 Azure 资源组( Resource Group ),创建 Azure 虚拟机和搭建 MongoDB 都在该资源组中进行,运行以下命令创建 Azure 资源组:

    azure group create "YOUR-RESOURCE-GROUP-NAME" "China East"

 

开始动手

Warning

需要以管理员权限运行 PowerShell,使用之前需运行如下命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

 

1.在Azure虚拟机上搭建单节点 MongoDB

默认情况下,以下脚本将创建1台 CentOS 虚机,构成一个单节点 MongoDB。 以下将主要介绍 Azure PowerShell 方式

你需要下载 PowerShell 脚本 ,按照以下示例运行 mongodb-install-centos.ps1 脚本,即可在资源组 rg1 中生成一台 CentOS 虚拟机,接着会在该虚机上安装单节点 MongoDB。

PS C:\mongodb> .\mongodb-singlenode-deploy.ps1 -ResourceGroupName rg1 -AdminUserName azureuser -AdminPassword “YOUR-PASSWORD”  -CentosVersion 6.5 -VmName mongodbserver

创建过程大概需要6分钟,运行成功后会出现如下提示:

Deploy MongoDB on VM mongodb11 (CentOS 6.5) in China North successfully.    To connect using the mongo shell:    % mongo mongodbserver.chinanorth.cloudapp.chinacloudapi.cn:27017/test

 

2. 在Azure虚拟机上搭建包含主从复制节点的 MongoDB

默认情况下,以下脚本将创建3台 CentOS 虚机,组成一个 MongoDB 复制集,该复制集将包含一个 Pirmary 节点和2个 Secondary 节点,架构如下图所示:

 

Azure PowerShell 方式

你需要下载 PowerShell 脚本 ,按照以下示例运行 mongodb-replica-set-deploy.ps1 脚本,即可在资源组 rg1 中生成多台 CentOS 虚拟机,接着会在该虚机上搭建具备主从复制节点的 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

创建过程大概需要10分钟,运行成功后会出现如下提示:

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. 在 Azure 虚拟机上搭建 MongoDB 分片集群

默认情况下,以下脚本将创建11台 CentOS 虚机,包含:2台 router 服务器, 3台 config 服务器,2个分片,每个分片带有1个 Priamry 节点和2个 Secondary 节点,总计11个节点,架构如下图所示:

Azure PowerShell 方式

你需要下载PowerShell脚本 ,按照以下示例运行 mongodb-sharding-deploy.ps1 脚本,即可在资源组rg1中生成多台 CentOS 虚拟机,接着会在该虚机上搭建具备主从复制节点及分片集群的 MongoDB,创建过程大概需要1小时15分钟。

PS C:\mongodb>.\mongodb-sharding-deploy.ps1 -ResourceGroupName rg1 -CentosVersion 7.2 -AdminUsername azureuser -AdminPassword “YOUR-PASSWORD” -MongoUsername mongoadmin -MongoPassword “YOUR-PASSWORD” -DNSNamePrefix mongoshard

 

关于另一种:Azure CLI 方式,感兴趣的朋友可以。

 

转载于:https://www.cnblogs.com/cbits/p/7485966.html

你可能感兴趣的文章
ELK-Elasticsearch安装
查看>>
Android 模拟器(Emulator)访问模拟器所在主机
查看>>
删除字符串中指定子串
查看>>
day40-socket编程
查看>>
SpringBoot里mybatis查询结果为null的列不返回问题的解决方案
查看>>
为什么留不住优秀的员工
查看>>
Django后台管理admin笔记
查看>>
JavaScript中的变量
查看>>
iptables基本原理和规则配置
查看>>
ArcGIS JS 学习笔记4 实现地图联动
查看>>
ubuntu 12.04 lts安装golang并设置vim语法高亮
查看>>
编程题目:PAT 1004. 成绩排名 (20)
查看>>
使用分层实现业务处理
查看>>
Microsoft Windows平台的NoSQL数据存储引擎
查看>>
浅谈虚拟机
查看>>
Ubuntu系统Linux编译osg库
查看>>
BootstrapTable-导出数据
查看>>
Linux学习笔记 -- 系统目录结构
查看>>
[转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件...
查看>>
将数组排序组成最小的整数
查看>>