Skip to content

Commit d557142

Browse files
committed
docs:修改md文档内容,并更新目录。
1 parent 9de7932 commit d557142

File tree

7 files changed

+163
-4
lines changed

7 files changed

+163
-4
lines changed

solution/tech-solution/migrate-ecs-mongodb-to-cloud/README.md renamed to solution/tech-solution/migrate-self-managed-mongodb-to-cloud/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Introduction
2+
13
<!-- DOCS_DESCRIPTION_CN -->
24
本示例用于实现解决方案[自建 MongoDB 迁移到云数据库](https://www.aliyun.com/solution/tech-solution/migrate-self-managed-mongodb-to-cloud), 涉及到专有网络(VPC)、交换机(VSwitch)、云服务器(ECS)、云数据库(MongoDB) 等资源的创建。
35
<!-- DOCS_DESCRIPTION_CN -->
@@ -11,8 +13,8 @@ This example demonstrates the implementation of the solution [Migrate self-manag
1113

1214
| Name | Version |
1315
|------|---------|
14-
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | 1.253.0 |
15-
| <a name="provider_random"></a> [random](#provider\_random) | 3.7.2 |
16+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
17+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
1618

1719
## Modules
1820

@@ -44,9 +46,9 @@ No modules.
4446
|------|-------------|------|---------|:--------:|
4547
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | 请输入自建MongoDB数据库名称(由小写字母、数字及特殊字符 -\_ 组成,以小写字母开头,小写字母或数字结尾,最多64个字符)。 | `string` | `"mongodb_transfer_test"` | no |
4648
| <a name="input_db_password"></a> [db\_password](#input\_db\_password) | 请输入自建MongoDB数据库密码。密码长度为8-32位,需包含大写字母、小写字母、数字和特殊字符(如:!@#$%^&*()\_+-=)。 | `string` | n/a | yes |
47-
| <a name="input_db_user_name"></a> [db\_user\_name](#input\_db\_user\_name) | 请输入自建MongoDB数据库账号(长度为2-16个字符,仅允许小写字母、大写字母、数字和下划线,必须以字母开头,以字母或数字结尾)。 | `string` | n/a | yes |
49+
| <a name="input_db_user_name"></a> [db\_user\_name](#input\_db\_user\_name) | 请输入自建MongoDB数据库账号(长度为2-16个字符,仅允许小写字母、大写字母、数字和下划线,必须以字母开头,以字母或数字结尾)。 | `string` | `"mongouser"` | no |
4850
| <a name="input_ecs_instance_password"></a> [ecs\_instance\_password](#input\_ecs\_instance\_password) | 请输入服务器登录密码。密码长度为8-30位,必须包含大写字母、小写字母、数字和特殊字符(如:!@#$%^&*\_-+=\|{}[]:;'<>,.?/)。 | `string` | n/a | yes |
49-
| <a name="input_mongodb_account_password"></a> [mongodb\_account\_password](#input\_mongodb\_account\_password) | 请输入MongoDB Root密码。密码长度为6-32位,需包含大写字母、小写字母、数字和特殊字符(如:!@#$%^&*()\_+-=)。 | `string` | n/a | yes |
5051
| <a name="input_mongodb_instance_class"></a> [mongodb\_instance\_class](#input\_mongodb\_instance\_class) | 请输入MongoDB实例规格(例如:mdb.shard.2x.xlarge.d)。根据您的数据库负载选择合适的规格。 | `string` | `"mdb.shard.2x.xlarge.d"` | no |
52+
| <a name="input_mongodb_password"></a> [mongodb\_password](#input\_mongodb\_password) | 请输入MongoDB Root密码。密码长度为6-32位,需包含大写字母、小写字母、数字和特殊字符(如:!@#$%^&*()\_+-=)。 | `string` | n/a | yes |
5153
| <a name="input_region_id"></a> [region\_id](#input\_region\_id) | 请输入地域ID(例如:cn-hangzhou)。 | `string` | `"cn-hangzhou"` | no |
5254
<!-- END_TF_DOCS -->
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
provider "alicloud" {
2+
region = var.region_id
3+
}
4+
5+
resource "random_id" "suffix" {
6+
byte_length = 8
7+
}
8+
9+
data "alicloud_instance_types" "default" {
10+
system_disk_category = "cloud_essd"
11+
image_id = data.alicloud_images.default.images[0].id
12+
instance_type_family = "ecs.c6"
13+
availability_zone = data.alicloud_db_zones.rds_zones.zones[length(data.alicloud_db_zones.rds_zones.zones) - 1].id
14+
}
15+
16+
data "alicloud_images" "default" {
17+
name_regex = "^aliyun_3_x64_20G_alibase_.*"
18+
most_recent = true
19+
owners = "system"
20+
}
21+
22+
locals {
23+
common_name = "${random_id.suffix.id}"
24+
redis_install_script = <<-SCRIPT
25+
#!/bin/bash
26+
export ROS_DEPLOY=true
27+
curl -fsSL https://static-aliyun-doc.oss-cn-hangzhou.aliyuncs.com/install-script/read-write-splitting-through-tair-proxy/install.sh | bash
28+
SCRIPT
29+
}
30+
31+
# VPC Resources
32+
resource "alicloud_vpc" "vpc" {
33+
vpc_name = "VPC_HZ"
34+
cidr_block = "192.168.0.0/16"
35+
}
36+
37+
resource "alicloud_vswitch" "vswitch" {
38+
vpc_id = alicloud_vpc.vpc.id
39+
cidr_block = "192.168.1.0/24"
40+
zone_id = var.zone_id
41+
vswitch_name = "vsw_001"
42+
}
43+
44+
# Security Group
45+
resource "alicloud_security_group" "ecs_security_group" {
46+
vpc_id = alicloud_vpc.vpc.id
47+
security_group_name = "SecurityGroup_1"
48+
security_group_type = "normal"
49+
}
50+
51+
resource "alicloud_security_group_rule" "http" {
52+
type = "ingress"
53+
ip_protocol = "tcp"
54+
port_range = "80/80"
55+
cidr_ip = "140.205.11.1/25"
56+
security_group_id = alicloud_security_group.ecs_security_group.id
57+
}
58+
59+
# Redis Instance
60+
resource "alicloud_kvstore_instance" "redis" {
61+
db_instance_name = "redis"
62+
instance_class = "redis.shard.small.2.ce"
63+
engine_version = "7.0"
64+
password = var.db_password
65+
payment_type = "PostPaid"
66+
vswitch_id = alicloud_vswitch.vswitch.id
67+
zone_id = var.zone_id
68+
read_only_count = 1
69+
security_ips = ["192.168.0.0/16"]
70+
}
71+
72+
# ECS Instance
73+
resource "alicloud_instance" "ecs_instance" {
74+
instance_name = "ecs-${local.common_name}"
75+
system_disk_category = data.alicloud_instance_types.default.system_disk_category
76+
image_id = data.alicloud_images.default.images[0].id
77+
system_disk_size = 100
78+
vswitch_id = alicloud_vswitch.vswitch.id
79+
password = var.ecs_instance_password
80+
instance_type = var.ecs_instance_type
81+
internet_max_bandwidth_out = 5
82+
security_groups = [alicloud_security_group.ecs_security_group.id]
83+
}
84+
85+
# Install Redis Client Command
86+
resource "alicloud_ecs_command" "install_redis_client" {
87+
name = "install-redis-client-${local.common_name}"
88+
description = "Install Redis client on ECS instance"
89+
type = "RunShellScript"
90+
command_content = base64encode(local.redis_install_script)
91+
timeout = 600
92+
working_dir = "/root"
93+
}
94+
95+
resource "alicloud_ecs_invocation" "install_redis_client" {
96+
instance_id = [alicloud_instance.ecs_instance.id]
97+
command_id = alicloud_ecs_command.install_redis_client.id
98+
depends_on = [alicloud_kvstore_instance.redis]
99+
timeouts {
100+
create = "10m"
101+
}
102+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Outputs
2+
output "ecs_login_address" {
3+
description = "ECS登录地址"
4+
value = "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${data.alicloud_regions.current.regions[0].id}&instanceId=${alicloud_instance.ecs_instance.id}"
5+
}
6+
7+
output "redis_connection_address" {
8+
description = "Redis连接地址"
9+
value = alicloud_kvstore_instance.redis.connection_domain
10+
}
11+
12+
output "ecs_public_ip" {
13+
description = "ECS公网IP"
14+
value = alicloud_instance.ecs_instance.public_ip
15+
}
16+
17+
data "alicloud_regions" "current" {
18+
current = true
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Parameters
2+
variable "region_id" {
3+
description = "请输入地域ID(例如:cn-hangzhou)。"
4+
default = "cn-hangzhou"
5+
}
6+
variable "zone_id" {
7+
type = string
8+
description = "交换机可用区ID"
9+
default = "cn-hangzhou-k"
10+
}
11+
12+
variable "db_password" {
13+
type = string
14+
description = "Tair数据库密码。长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;特殊字符包括:!@#$%^&*()_+-="
15+
sensitive = true
16+
validation {
17+
condition = can(regex("^[0-9A-Za-z_!@#$%^&*()_+\\-=\\+]+$", var.db_password)) && length(var.db_password) >= 8 && length(var.db_password) <= 30
18+
error_message = "长度8-30,必须包含三项(大写字母、小写字母、数字、 !@#$%^&*()_+-=中的特殊符号)"
19+
}
20+
}
21+
22+
variable "ecs_instance_type" {
23+
type = string
24+
description = "ECS 实例类型"
25+
default = "ecs.e-c1m2.large"
26+
}
27+
28+
variable "ecs_instance_password" {
29+
type = string
30+
description = "ECS实例密码。服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ 中的特殊符号)"
31+
sensitive = true
32+
validation {
33+
condition = can(regex("^[a-zA-Z0-9-\\(\\)\\`\\~\\!\\@\\#\\$\\%\\^\\&\\*\\_\\-\\+\\=\\|\\{\\}\\[\\]\\:\\;\\<\\>\\,\\.\\?\\/]*$", var.ecs_instance_password)) && length(var.ecs_instance_password) >= 8 && length(var.ecs_instance_password) <= 30
34+
error_message = "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ 中的特殊符号)"
35+
}
36+
}

0 commit comments

Comments
 (0)