-
Notifications
You must be signed in to change notification settings - Fork 35
/
migrate-rabbitmq-to-cloud.yml
232 lines (223 loc) · 7.39 KB
/
migrate-rabbitmq-to-cloud.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建VPC、ECS实例,安装Docker与Java,配置RabbitMQ容器,同时部署云上RabbitMQ实例,实现自建RabbitMQ至云端的迁移。
en: Create a VPC and ECS instances, install Docker and Java, configure a RabbitMQ
container, simultaneously deploy a cloud-based RabbitMQ instance, and facilitate
the migration from an on-premises RabbitMQ to the cloud-based setup.
Parameters:
CommonName:
Type: String
Default: migrate-rabbitmq
ZoneId:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
Label:
en: Availability Zone
zh-cn: 可用区
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: Instance Password
zh-cn: 实例密码
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'
Default: null
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: ${CommonName}-vpc
VSwitch:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
ZoneId:
Ref: ZoneId
VSwitchName:
Fn::Sub: ${CommonName}-vsw
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: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 15672/15672
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 5672/5672
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_9_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs
InstanceType:
Ref: InstanceType
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 100
Password:
Ref: InstancePassword
ModuleInstallDocker:
Version: default
Type: 'MODULE::ACS::OOS::Extension'
Properties:
EcsInstanceIds:
Fn::GetAtt:
- EcsInstance
- InstanceIds
PackageName: ACS-Extension-DockerCE-1853370294850618
ModuleInstallJava:
Version: default
Type: 'MODULE::ACS::OOS::Extension'
DependsOn: ModuleInstallDocker
Properties:
EcsInstanceIds:
Fn::GetAtt:
- EcsInstance
- InstanceIds
PackageName: ACS-Extension-java-1853370294850618
InstallRabbitMQ:
Type: 'ALIYUN::ECS::RunCommand'
DependsOn:
- ModuleInstallDocker
- ModuleInstallJava
Properties:
InstanceIds:
Fn::GetAtt:
- EcsInstance
- InstanceIds
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
export PATH=/usr/local/bin:$PATH
# RabbitMQ 默认的用户和密码
RABBITMQ_USER="guest"
RABBITMQ_PASS="guest"
# 要创建的 Vhost、Exchange 和 Queue 名称
RABBITMQ_VHOST="myvhost"
RABBITMQ_EXCHANGE="myexchange"
RABBITMQ_QUEUE="myqueue"
RABBITMQ_ROUTING_KEY="my.routing.key"
# 拉取并运行 RabbitMQ Docker 容器
docker pull rabbitmq:3.13-management-alpine
docker run -d --hostname my-rabbit --name rabbitmq --restart=always -p 5672:5672 -p 15672:15672 rabbitmq:3.13-management-alpine
# 等待 RabbitMQ 启动
echo "Waiting for RabbitMQ to start..."
sleep 10
# 创建 Vhost
echo "Creating Vhost..."
curl -u $RABBITMQ_USER:$RABBITMQ_PASS \
-X PUT http://localhost:15672/api/vhosts/$RABBITMQ_VHOST \
-H "Content-Type: application/json"
# 创建 Exchange
echo "Creating Exchange..."
curl -u $RABBITMQ_USER:$RABBITMQ_PASS \
-X PUT http://localhost:15672/api/exchanges/$RABBITMQ_VHOST/$RABBITMQ_EXCHANGE \
-H "Content-Type: application/json" \
-d '{"type":"direct","auto_delete":false,"durable":true,"internal":false,"arguments":{}}'
# 创建 Queue
echo "Creating Queue..."
curl -u $RABBITMQ_USER:$RABBITMQ_PASS \
-X PUT http://localhost:15672/api/queues/$RABBITMQ_VHOST/$RABBITMQ_QUEUE \
-H "Content-Type: application/json" \
-d '{"auto_delete":false,"durable":true,"arguments":{}}'
# 绑定 Queue 到 Exchange
echo "Binding Queue to Exchange..."
curl -u $RABBITMQ_USER:$RABBITMQ_PASS \
-X POST http://localhost:15672/api/bindings/$RABBITMQ_VHOST/e/$RABBITMQ_EXCHANGE/q/$RABBITMQ_QUEUE \
-H "Content-Type: application/json" \
-d "{\"routing_key\":\"$RABBITMQ_ROUTING_KEY\",\"arguments\":{}}"
echo "RabbitMQ setup complete!"
RabbitMQ:
Type: 'ALIYUN::AMQP::Instance'
Properties:
PayType: PayAsYouGo
SupportEip: true
SupportTracing: true
InstanceName:
Fn::Sub: ${CommonName}-rabbitmq
Outputs:
EcsLoginAddress:
Description:
zh-cn: ECS登录地址。
en: Ecs login address.
Value:
'Fn::Sub': https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs®ionId=${ALIYUN::Region}&instanceId=${EcsInstance}
MqAdminAddress:
Description:
zh-cn: 自建RabbitMQ管理地址。
en: RabbitMQ login address.
Value:
Fn::Sub:
- http://${PublicIp}:15672
- PublicIp:
Fn::Select:
- 0
- Fn::GetAtt:
- EcsInstance
- PublicIps
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId
- InstanceType
- InstancePassword
TemplateTags:
- acs:technical-solution:cloud-migration:自建RabbitMQ迁移至云消息队列RabbitMQ版-tech_solu_122
Hidden:
- CommonName