云数据库 MongoDB版,采用三节点副本集的架构保证服务的高可用。本文介绍如何通过阿里云资源编排服务(ROS),创建一台ECS服务器和一个Mongodb版云数据库,并把ECS加入到Mongodb的访问白名单中。
创建ECS实例
创建ECS实例的详细说明,请移步 通过资源编排创建一个ECS实例。模板片段如下:
{
"ROSTemplateFormatVersion" : "2015-09-01",
"Description": "一个简配的ecs实例,包括一个安全组,用户只需要指定imageId",
"Parameters" : {
"ImageId": {
"Type" : "String",
"Default": "centos6u5_64_40G_aliaegis_20160222.vhd",
"Description": "镜像文件 ID,表示启动实例时选择的镜像资源"
},
"InstanceType": {
"Type": "String",
"Description": "实例的资源规格",
"Default": "ecs.s3.medium",
"AllowedValues": [
"ecs.t1.small", "ecs.s1.small", "ecs.s1.medium", "ecs.s1.large",
"ecs.s2.small", "ecs.s2.large", "ecs.s2.xlarge", "ecs.s2.2xlarge",
"ecs.s3.medium", "ecs.s3.large", "ecs.m1.medium", "ecs.m2.medium",
"ecs.m1.xlarge", "ecs.c1.small", "ecs.c1.large", "ecs.c2.medium",
"ecs.c2.large", "ecs.c2.xlarge"
]
},
"SecurityGroupName": {
"Type": "String",
"Description": "安全组名称"
}
},
"Resources" : {
"WebServer": {
"Type": "ALIYUN::ECS::Instance",
"Properties": {
"ImageId" : {"Ref": "ImageId"},
"InstanceType": {"Ref": "InstanceType"},
"SecurityGroupId": {"Ref": "SecurityGroup"}
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"SecurityGroupName": {"Ref": "SecurityGroupName"}
}
}
}
}
创建Mongodb实例
ROS提供了资源 ALIYUN::MONGODB::Instance 支持创建Mongodb实例。
基本属性:
- DBInstanceStorage, 所需存储空间大小,以GB为基本单位。
- AccountPassword, root账号密码
- SecurityIPArray, 实例访问白名单
-
DBInstanceClass,实例规格, 目前支持的规格列表如下:
- 1核2G(dds.mongo.mid)
- 2核4G(dds.mongo.standard)
- 4核8G(dds.mongo.large)
- 8核16G(dds.mongo.xlarge)
- 8核32G(dds.mongo.2xlarge)
- 16核64G(dds.mongo.4xlarge)
模板定义:
下面的模板将创建一个4核8G的classic类型的Mongodb实例,如果需要配置更多属性请参考ROS资源详情 ALIYUN::MONGODB::Instance
{
"ROSTemplateFormatVersion" : "2015-09-01",
"Parameters" : {
"DBInstanceClass": {
"Type": "String",
"Description": "实例规格",
"Default": "dds.mongo.mid",
"AllowedValues": [
"dds.mongo.mid", "dds.mongo.standard", "dds.mongo.large",
"dds.mongo.xlarge", "dds.mongo.2xlarge", "dds.mongo.4xlarge"
]
}
},
"Resources" : {
"MongoDB": {
"Type": "ALIYUN::MONGODB::Instance",
"Properties": {
"DBInstanceClass":"dds.mongo.mid",
"DBInstanceStorage":"10",
"NetworkType":"CLASSIC"
}
}
}
}
把ECS内网ip加入到Mongodb白名单
Mongodb中添加白名单配置如下:
"SecurityIPArray": {"Fn::GetAtt": [ "WebServer", "PrivateIp" ] }
创建完成后,ecs内网就可以访问mongodb!
完整的模板 下载地址