forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyticDB-and-Bailian-system.yml
289 lines (279 loc) · 9.27 KB
/
AnalyticDB-and-Bailian-system.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: AnalyticDB and Bailian build intelligent question and answer system.
zh-cn: AnalyticDB与百炼搭建智能问答系统。
Parameters:
ZoneId:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
Label:
en: Availability Zone
zh-cn: 可用区
DASHSCOPE_API_KEY:
NoEcho: true
Type: String
Label:
en: Bailian application API-KEY
zh-cn: 百炼应用的API-KEY
APP_ID:
Type: String
Label:
en: Application ID of Bilian application
zh-cn: 百炼应用的应用ID
InstanceType:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 实例规格
InstancePassword:
NoEcho: true
Type: String
Description:
en: >-
Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
symbol in)
zh-cn: >-
服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符号)
Label:
en: ECS Instance Password
zh-cn: ECS实例密码
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)'
AssociationProperty: 'ALIYUN::ECS::Instance::Password'
CommonName:
Type: String
Default: RAG
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: vpc_${CommonName}
VSwitch:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
ZoneId:
Ref: ZoneId
VSwitchName:
Fn::Sub: vsw_${CommonName}
SecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 22/22
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 5000/5000
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
EcsInstance:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs_adb
InstanceType:
Ref: InstanceType
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 100
Password:
Ref: InstancePassword
AnalyticDB:
Type: ALIYUN::GPDB::DBInstance
Properties:
EngineVersion: '6.0'
InstanceSpec: 4C16G
ZoneId:
Ref: ZoneId
VSwitchId:
Ref: VSwitch
SegNodeNum: 2
SegStorageType: cloud_essd
SegDiskPerformanceLevel: pl1
StorageSize: 50
VPCId:
Ref: Vpc
SecurityIPList: 192.168.0.0/24
DBInstanceDescription:
Fn::Sub: ${CommonName}-adb
PayType: Postpaid
DBInstanceCategory: Basic
DBInstanceMode: StorageElastic
VectorConfigurationStatus: true
WaitConditionHandle:
Type: 'ALIYUN::ROS::WaitConditionHandle'
Properties: { }
RosWaitCondition:
Type: 'ALIYUN::ROS::WaitCondition'
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 7200
RunCommand:
Type: 'ALIYUN::ECS::RunCommand'
Properties:
InstanceIds:
Fn::GetAtt:
- EcsInstance
- InstanceIds
Type: RunShellScript
Sync: true
Timeout: 7200
CommandContent:
'Fn::Sub':
- >-
#!/bin/bash
if [ ! -f .ros.provision ]; then
echo "Name: 手动搭建AnalyticDB与百炼搭建智能问答系统" > .ros.provision
fi
name=$(grep "^Name:" .ros.provision | awk -F':' '{print $2}' | sed
-e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$name" != "手动搭建AnalyticDB与百炼搭建智能问答系统" ]]; then
echo "当前实例已使用过\"$name\"教程的一键配置,不能再使用本教程的一键配置"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance has already applied the configuration of the \\\"$name\\\" tutorial, and the configuration of this tutorial can no longer be applied.\"}"
exit 0
fi
if ! grep -q "^Step1: Prepare Environment$" .ros.provision; then
echo "#########################"
echo "# Prepare Environment "
echo "#########################"
# 安装Python-3.9.7,建议Python版本为3.9及以上。
sudo yum update -y && \
sudo yum groupinstall "Development Tools" -y && \
sudo yum install openssl-devel bzip2-devel libffi-devel -y
cd /usr/src && \
sudo curl -O https://help-static-aliyun-doc.aliyuncs.com/software/Python-3.9.0.tgz && \
sudo tar xzf Python-3.9.0.tgz && \
cd Python-3.9.0 && \
sudo ./configure --enable-optimizations && \
sudo make altinstall
python3.9 --version && \
python3.9 -m ensurepip && \
python3.9 -m pip install --upgrade pip
echo 'export SOCKET_ENDPOINT="${ECS_NETWORK_IP}:5000"' >> ~/.bashrc
echo 'export APP_ID="${APP_ID}"' >> ~/.bashrc
echo 'export DASHSCOPE_API_KEY="${DASHSCOPE_API_KEY}"' >> ~/.bashrc
source ~/.bashrc
echo "Step1: Prepare Environment" >> .ros.provision
else
echo "#########################"
echo "# Environment has been ready"
echo "#########################"
fi
if ! grep -q "^Step2: Deployment service$" .ros.provision; then
echo "#########################"
echo "# Deployment service "
echo "#########################"
cd /root
wget https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20240729/unpfxr/demo.zip
sudo yum install -y unzip
unzip demo.zip
cd demo
python3.9 -m venv $(pwd)/venv
source $(pwd)/venv/bin/activate
pip3 install -r requirements.txt
sed "s/socketio.run(app, debug=True, host='0.0.0.0')/socketio.run(app, debug=True, host='0.0.0.0', allow_unsafe_werkzeug=True)/" app-stream.py > temp_app_stream.py
mv temp_app_stream.py app-stream.py
rm -rf temp_app_stream.py
nohup python3.9 app-stream.py > app-stream.log 2>&1 &
echo "Step2: Deployment service" >> .ros.provision
else
echo "#########################"
echo "# Service deployed"
echo "#########################"
fi
${WaitConditionHandle.CurlCli} --data-binary '{"status": "SUCCESS"}'
- ECS_NETWORK_IP:
Fn::Select:
- 0
- Fn::GetAtt:
- EcsInstance
- PublicIps
APP_ID:
Ref:
APP_ID
DASHSCOPE_API_KEY:
Ref:
DASHSCOPE_API_KEY
Outputs:
WebUrl:
Description:
zh-cn: Web 访问地址。
en: The Addresses of Web.
Value:
'Fn::Sub':
- 'http://${ServerAddress}:5000/home'
- ServerAddress:
'Fn::Select':
- 0
- 'Fn::GetAtt':
- EcsInstance
- PublicIps
EcsLoginAddress:
Description:
zh-cn: ECS登录地址。
en: Ecs login address.
Value:
'Fn::Sub':
- >-
https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs®ionId=${Region}&instanceId=${InstanceId}
- InstanceId:
'Fn::Select':
- 0
- 'Fn::GetAtt':
- EcsInstance
- InstanceIds
Region:
Ref: 'ALIYUN::Region'
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId
- InstanceType
- InstancePassword
Label:
default:
en: Ecs Configuration
zh-cn: ECS 实例配置
- Parameters:
- APP_ID
- DASHSCOPE_API_KEY
Label:
default:
en: Bilian Application Configuration
zh-cn: 百炼应用配置
Hidden:
- CommonName
TemplateTags:
- acs:technical-solution:ai:AnalyticDB与百炼搭建智能问答系统-tech_solu_150