-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproxysql-demo.yml
539 lines (500 loc) · 15.5 KB
/
proxysql-demo.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
AWSTemplateFormatVersion: '2010-09-09'
Description: Create VPC with RDS Aurora MySQL cluster, EC2 instance with ProxySQL
Parameters:
VpcCIDR:
Type: String
Default: '10.3.0.0/16'
PublicSubnetACIDR:
Type: String
Default: '10.3.1.0/24'
PublicSubnetBCIDR:
Type: String
Default: '10.3.2.0/24'
PrivateSubnetACIDR:
Type: String
Default: '10.3.3.0/24'
PrivateSubnetBCIDR:
Type: String
Default: '10.3.4.0/24'
EC2InstanceAMI:
Type: String
Default: 'ami-0ee42e014ecaa7505'
EC2InstanceConnectCIDR:
Type: String
Default: '3.0.5.32/29'
DBEngine:
Type: String
Default: 'aurora-mysql'
DBEngineVersion:
Type: String
Default: '5.7'
DBClusterParameterGroupFamily:
Type: String
Default: 'aurora-mysql5.7'
DBMasterUsername:
Type: String
Default: 'admin'
DBMasterPassword:
Type: String
Default: 'mysqladmin'
Resources:
###### VPC and SUBNETS ######
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-VPC" ]]
PublicSubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PublicSubnetACIDR
AvailabilityZone: !Select [ 0, !GetAZs ]
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-PublicSubnetA" ]]
PublicSubnetB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PublicSubnetBCIDR
AvailabilityZone: !Select [ 1, !GetAZs ]
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-PublicSubnetB" ]]
PrivateSubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PrivateSubnetACIDR
AvailabilityZone: !Select [ 0, !GetAZs ]
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-PrivateSubnetA" ]]
PrivateSubnetB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PrivateSubnetBCIDR
AvailabilityZone: !Select [ 1, !GetAZs ]
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-PrivateSubnetB" ]]
###### NETWORKING ######
InternetGateway:
Type: AWS::EC2::InternetGateway
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
NatGatewayAEIP:
Type: AWS::EC2::EIP
NatGatewayA:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGatewayAEIP.AllocationId
SubnetId: !Ref PublicSubnetA
NatGatewayBEIP:
Type: AWS::EC2::EIP
NatGatewayB:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGatewayBEIP.AllocationId
SubnetId: !Ref PublicSubnetB
PublicRouteTableA:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
PublicRouteTableB:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
AssociatePublicRouteTableA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnetA
RouteTableId: !Ref PublicRouteTableA
AssociatePublicRouteTableB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnetB
RouteTableId: !Ref PublicRouteTableB
PublicRouteA:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTableA
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref InternetGateway
PublicRouteB:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTableB
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref InternetGateway
PrivateRouteTableA:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
PrivateRouteTableB:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
AssociatePrivateRouteTableA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnetA
RouteTableId: !Ref PrivateRouteTableA
AssociatePrivateRouteTableB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnetB
RouteTableId: !Ref PrivateRouteTableB
PrivateRouteA:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTableA
DestinationCidrBlock: '0.0.0.0/0'
NatGatewayId: !Ref NatGatewayA
PrivateRouteB:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTableB
DestinationCidrBlock: '0.0.0.0/0'
NatGatewayId: !Ref NatGatewayB
###### DATABASE MySQL 5.7 ######
DBCluster57:
Type : "AWS::RDS::DBCluster"
Properties :
Engine : !Ref DBEngine
EngineVersion : !Ref DBEngineVersion
MasterUsername : !Ref DBMasterUsername
MasterUserPassword : !Ref DBMasterPassword
DBSubnetGroupName : !Ref DBSubnetGroup57
DBClusterParameterGroupName : !Ref DBClusterParameterGroup57
VpcSecurityGroupIds :
- !Ref DBSecurityGroup
DBInstance57:
Type: 'AWS::RDS::DBInstance'
Properties:
DBClusterIdentifier: !Ref DBCluster57
Engine : !Ref DBEngine
PubliclyAccessible: False
DBInstanceClass: db.r6g.large
EnablePerformanceInsights: true
DBSubnetGroup57:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription : "DB Subnet Group"
SubnetIds :
- !Ref PrivateSubnetA
- !Ref PrivateSubnetB
DBClusterParameterGroup57:
Type : "AWS::RDS::DBClusterParameterGroup"
Properties :
Description : "DB Cluster Parameter Group"
Family : !Ref DBClusterParameterGroupFamily
Parameters:
time_zone: US/Eastern
character_set_database: utf32
###### DATABASE MySQL 8.0 ######
DBCluster80:
Type : "AWS::RDS::DBCluster"
Properties :
Engine : !Ref DBEngine
EngineVersion : '8.0'
MasterUsername : !Ref DBMasterUsername
MasterUserPassword : !Ref DBMasterPassword
DBSubnetGroupName : !Ref DBSubnetGroup80
DBClusterParameterGroupName : !Ref DBClusterParameterGroup80
VpcSecurityGroupIds :
- !Ref DBSecurityGroup
DBInstance80:
Type: 'AWS::RDS::DBInstance'
Properties:
DBClusterIdentifier: !Ref DBCluster80
Engine : !Ref DBEngine
PubliclyAccessible: False
DBInstanceClass: db.r6g.large
EnablePerformanceInsights: true
DBSubnetGroup80:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription : "DB Subnet Group"
SubnetIds :
- !Ref PrivateSubnetA
- !Ref PrivateSubnetB
DBClusterParameterGroup80:
Type : "AWS::RDS::DBClusterParameterGroup"
Properties :
Description : "DB Cluster Parameter Group"
Family : 'aurora-mysql8.0'
Parameters:
time_zone: US/Eastern
character_set_database: utf32
###### COMPUTE ######
ProxySQLInstance1:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !Ref EC2InstanceAMI
InstanceType: t4g.medium
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- !Ref ProxySQLSecurityGroup
SubnetId: !Ref PrivateSubnetA
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-EC2ProxySQL1" ]]
UserData: !Base64
Fn::Sub: |
#!/bin/bash
: '
This script will handle an installation of proxysql and mysql
'
# Installation
cat <<EOF | sudo tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name=ProxySQL repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.5.x/centos/8
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.5.x/repo_pub_key
EOF
dnf -y install proxysql
dnf -y localinstall https://dev.mysql.com/get/mysql80-community-release-el9-4.noarch.rpm
dnf -y install mysql mysql-community-client
dnf -y install httpd
echo "Hello from proxysql Instance 1" | tee /var/www/html/index.html
service proxysql start
systemctl start httpd
systemctl enable httpd
ProxySQLInstance2:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !Ref EC2InstanceAMI
InstanceType: t4g.medium
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- !Ref ProxySQLSecurityGroup
SubnetId: !Ref PrivateSubnetB
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-EC2ProxySQL2" ]]
UserData: !Base64
Fn::Sub: |
#!/bin/bash
: '
This script will handle an installation of proxysql and mysql
'
# Installation
cat <<EOF | sudo tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name=ProxySQL repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.5.x/centos/8
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.5.x/repo_pub_key
EOF
dnf -y install proxysql
dnf -y localinstall https://dev.mysql.com/get/mysql80-community-release-el9-4.noarch.rpm
dnf -y install mysql mysql-community-client
dnf -y install httpd
echo "Hello from proxysql Instance 2" | tee /var/www/html/index.html
service proxysql start
systemctl start httpd
systemctl enable httpd
SysbenchInstance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !Ref EC2InstanceAMI
InstanceType: t4g.medium
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- !Ref SysbenchSecurityGroup
SubnetId: !Ref PublicSubnetA
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-sysbench" ]]
UserData: !Base64
Fn::Sub: |
#!/bin/bash
dnf -y install git gcc make automake libtool openssl-devel ncurses-compat-libs
dnf -y localinstall https://dev.mysql.com/get/mysql80-community-release-el9-4.noarch.rpm
dnf -y update
dnf -y install mysql-community-devel mysql-community-client mysql-community-common
git clone https://github.com/akopytov/sysbench
cd sysbench
./autogen.sh
./configure
make
make install
EC2InstanceConnectEndpoint:
Type: AWS::EC2::InstanceConnectEndpoint
Properties:
SubnetId: !Ref PrivateSubnetA
SecurityGroupIds:
- !Ref ProxySQLSecurityGroup
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-ProxysqlInstanceConnectEndpoint" ]]
SysbenchSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref "AWS::StackName", "-SysbenchSG" ]]
GroupName: !Join ['', [!Ref "AWS::StackName", "-SysbenchSG" ]]
VpcId: !Ref VPC
SecurityGroupIngress:
- CidrIp: !Ref EC2InstanceConnectCIDR
IpProtocol: "tcp"
FromPort: 22
ToPort: 22
Description: "EC2 Instance Connect IP for Singapore"
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-SysbenchSG" ]]
ProxySQLSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref "AWS::StackName", "-ProxySQLSG" ]]
GroupName: !Join ['', [!Ref "AWS::StackName", "-ProxySQLSG" ]]
VpcId: !Ref VPC
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref SysbenchSecurityGroup
IpProtocol: "tcp"
FromPort: 80
ToPort: 80
Description: "Health Check"
- SourceSecurityGroupId: !Ref SysbenchSecurityGroup
IpProtocol: "tcp"
FromPort: 3306
ToPort: 3306
Description: "MySQL"
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-ProxySQLSG" ]]
PrxoySQLSGIngressSSHSelf:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref ProxySQLSecurityGroup
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: ssh ownself
SourceSecurityGroupId: !Ref ProxySQLSecurityGroup
PrxoySQLSGIngressMySQLSelf:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref ProxySQLSecurityGroup
IpProtocol: tcp
FromPort: 6033
ToPort: 6033
Description: ProxySQL Ownself
SourceSecurityGroupId: !Ref ProxySQLSecurityGroup
PrxoySQLSGIngressHTTPSelf:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref ProxySQLSecurityGroup
IpProtocol: tcp
FromPort: 80
ToPort: 80
Description: health check ownself
SourceSecurityGroupId: !Ref ProxySQLSecurityGroup
DBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref "AWS::StackName", "-DBSG" ]]
GroupName: !Join ['', [!Ref "AWS::StackName", "-DBSG" ]]
VpcId: !Ref VPC
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref ProxySQLSecurityGroup
IpProtocol: "tcp"
FromPort: 3306
ToPort: 3306
Description: "MySQL ProxySQL"
- SourceSecurityGroupId: !Ref SysbenchSecurityGroup
IpProtocol: "tcp"
FromPort: 3306
ToPort: 3306
Description: "MySQL Sysbench"
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-DBSG" ]]
NetworkLoadBalancer:
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Type: network
Scheme: internal
Subnets:
- !Ref PrivateSubnetA
- !Ref PrivateSubnetB
SecurityGroups:
- !Ref ProxySQLSecurityGroup
Tags:
- Key: Name
Value: !Join ['', [!Ref "AWS::StackName", "-NLB" ]]
NLBListener80:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- TargetGroupArn: !Ref NLBTargetGroup80
Type: "forward"
LoadBalancerArn: !Ref NetworkLoadBalancer
Port: 80
Protocol: TCP
NLBTargetGroup80:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
HealthCheckPort: 80
HealthCheckProtocol: HTTP
Port: 80
Protocol: TCP
VpcId: !Ref VPC
Targets:
- Id: !Ref ProxySQLInstance1
- Id: !Ref ProxySQLInstance2
NLBListener3306:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- TargetGroupArn: !Ref NLBTargetGroup6033
Type: "forward"
LoadBalancerArn: !Ref NetworkLoadBalancer
Port: 3306
Protocol: TCP
NLBTargetGroup6033:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
HealthCheckPort: 80
HealthCheckProtocol: HTTP
Port: 6033
Protocol: TCP
VpcId: !Ref VPC
Targets:
- Id: !Ref ProxySQLInstance1
- Id: !Ref ProxySQLInstance2
Outputs:
Aurora80WriterEndpoint:
Value: !GetAtt DBCluster80.Endpoint.Address
Description: Aurora MySQL 8.0 Writer Endpoint
Aurora80ReaderEndpoint:
Value: !GetAtt DBCluster80.ReadEndpoint.Address
Description: Aurora MySQL 8.0 Reader Endpoint
Aurora57WriterEndpoint:
Value: !GetAtt DBCluster57.Endpoint.Address
Description: Aurora MySQL 5.7 Writer Endpoint
Aurora57ReaderEndpoint:
Value: !GetAtt DBCluster57.ReadEndpoint.Address
Description: Aurora MySQL 5.7 Reader Endpoint
NLBEndpoint:
Value: !GetAtt NetworkLoadBalancer.DNSName
Description: Endpoint for NLB