forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecs-with-java-web-enviroment.yml
208 lines (196 loc) · 5.42 KB
/
ecs-with-java-web-enviroment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create an ECS instance and install JDK and Tomcat.
zh-cn: 创建一个ECS实例并安装JDK和Tomcat。
Parameters:
TomcatDownloadUrl:
Type: String
Label: Tomcat Download Url
Description: The official download path of .tar.gz
Default: http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.41/bin/apache-tomcat-8.5.41.tar.gz
TomcatInstallationHome:
Type: String
Label: Tomcat Installation Home
Description: TOMCAT_HOME directory should be new.
Default: /usr/local/tomcat/apache-tomcat-8.5.41
ImageId:
Type: String
Label: ECS Image Id
Description: Image Id, represents the image resource to startup one ECS instance,
<a href='#/product/cn-beijing/list/imageList' target='_blank'>View image resources</a>
Default: centos_7
InstanceType:
Type: String
Label: ECS Instance Type
Description: The ECS instance type, <a href='#/product/cn-beijing/list/typeList'
target='_blank'>View instance types</a>
Default: ecs.c5.large
AllowedValues:
- ecs.c5.large
- ecs.g5.large
- ecs.c5.xlarge
- ecs.g5.xlarge
InstancePassword:
Type: String
Label: ECS Instance Password
Description: The root password of ECS instance. The password is a string of 8
to 41 characters and must contain uppercase/lowercase letters, numbers.
ConstraintDescription: Consist of 8 to 30 alphanumeric.
AllowedPattern: '[a-zA-Z0-9]*'
MinLength: '8'
MaxLength: '30'
NoEcho: true
Confirm: true
InstanceSystemDiskCategory:
Type: String
Label: Instance System Disk Category
Description: 'System disk category: average cloud disk(cloud), efficient cloud
disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)'
Default: cloud_ssd
AllowedValues:
- cloud
- cloud_efficiency
- cloud_ssd
VpcCidrBlock:
Type: String
Label: Vpc Cidr Block
Description: |-
The IP address range of the VPC in the CIDR block form. You can use the following IP address ranges and their subnets:
10.0.0.0/8
172.16.0.0/12 (Default)
192.168.0.0/16
Default: 192.168.0.0/16
AllowedValues:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
VSwitchCidrBlock:
Type: String
Label: VSwitch Cidr Block
Description: Cidr Block of created VSwitch
Default: 192.168.1.0/24
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName: Java_Web_VPC
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Fn::Select:
- '0'
- Fn::GetAZs:
Ref: ALIYUN::Region
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
CidrBlock:
Ref: VSwitchCidrBlock
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- SourceCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: internet
PortRange: -1/-1
Priority: 1
SecurityGroupEgress:
- IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
PortRange: -1/-1
Priority: 1
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId:
Ref: ImageId
Password:
Ref: InstancePassword
SystemDiskCategory:
Ref: InstanceSystemDiskCategory
InternetMaxBandwidthOut: 80
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- WebServerConditionHandle
- CurlCli
- Fn::Join:
- ''
- - '#!/bin/bash
'
- TOMCAT_HOME=
- Ref: TomcatInstallationHome
- '
'
- TomcatUrl=
- Ref: TomcatDownloadUrl
- '
'
- 'cd /root
'
- "yum -y install java \n"
- "yum -y install aria2 \n"
- 'aria2c $TomcatUrl
'
- "mkdir -p $TOMCAT_HOME \n"
- "tar zxvf apache-tomcat-*.tar.gz -C $TOMCAT_HOME \n"
- "cd $TOMCAT_HOME \n"
- "mv apache-tomcat-*.*/* ./ \n"
- "rmdir apache-tomcat-*.* \n"
- "$TOMCAT_HOME/bin/startup.sh \n"
- '# Config the firewall to allow the port 8080
'
- 'systemctl start firewalld.service
'
- 'firewall-cmd --zone=public --add-port=8080/tcp
'
- 'systemctl stop firewalld.service
'
- 'cd /root
'
- 'rm -f apache-tomcat-*.tar.gz
'
- 'ros-notify -d ''{"data" : "Install Java and Tomcat."}''
'
InstanceName: Java_Web_Instance
InstanceType:
Ref: InstanceType
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WebServerGroupWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Handle:
Ref: WebServerConditionHandle
Timeout: 3600
Count: 1
DependsOn: WebServer
Outputs:
WebsiteURL:
Description: URL for newly created Apache Tomcat/8.5.41
Value:
Fn::Join:
- ''
- - http://
- Fn::GetAtt:
- WebServer
- PublicIp
- :8080