-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmariadb-one-node.yaml
151 lines (141 loc) · 4.73 KB
/
mariadb-one-node.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to Create an EC2 instance in a VPC
Parameters:
ImageIdPriRep:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::ImageIdPriRep>'
Description: YOUR_IMAGE_ID
Default: ImageIdPriRep
VpcId:
Type: String
Description: VPC id
Default: vpc-07377e6c
SubnetId:
Type: String
Description: Subnet in which to launch an EC2
Default: subnet-06377e6d
AvailabilityZone:
Type: String
Description: Availability Zone into which instance will launch
Default: us-west-2a
InstanceType:
Type: String
Description: Instance type
Default: i3.4xlarge
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Description: SSH Keypair to login to the instance
Default: mmalgeri777-keypair-mdb
MyIp:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::MyIp>'
Description: MY_IP
Default: MyIp
DemoIpRange:
Type: String
Description: Demo Ip Range
Default: 172.31.32.0/20
DemoIp1:
Type: String
Description: Demo Ip 1
Default: 172.31.42.77
primaryReplicaToken:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::primaryReplicaToken>'
Description: YOUR_TOKEN
Default: primaryReplicaToken
primaryReplicaPassword:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::primaryReplicaPassword>'
Description: YOUR_PASSWORD
Default: primaryReplicaPassword
primaryReplicaVersion:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::primaryReplicaVersion>'
Description: YOUR_MARIADB_VERSION
Default: primaryReplicaVersion
Resources:
mariadb1:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref ImageIdPriRep
InstanceType: !Ref InstanceType
AvailabilityZone: !Ref AvailabilityZone
KeyName: !Ref KeyName
NetworkInterfaces:
- DeviceIndex: 0
PrivateIpAddress: !Ref DemoIp1
DeleteOnTermination: true
SubnetId: !Ref SubnetId
GroupSet:
- !Ref DemoSecurityGroup
- !Ref DemoHttpSecurityGroup
Tags:
- Key: Name
Value: mariadb1
UserData:
Fn::Base64: !Sub |
#!/bin/bash
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo "Installing mariadb enterprise"
yum update -y
echo "Updated yum"
echo "get private ip address"
ip=$(hostname -i)
echo "private address is "
echo $ip
sudo yum -y install wget
echo "Installed wget and now getting mariadb repo"
wget https://dlm.mariadb.com/enterprise-release-helpers/mariadb_es_repo_setup
sudo chmod +x mariadb_es_repo_setup
echo "Got repo and made it executable"
./mariadb_es_repo_setup --token=${primaryReplicaToken} --apply --mariadb-server-version="${primaryReplicaVersion}"
echo "Installed repo, now installing MariaDB-server"
sudo yum -y install MariaDB-server
echo "Done installing MariaDB-server"
sleep 10
sudo systemctl start mariadb
sudo systemctl enable mariadb
echo "Done installing, starting, and enabling MariaDB-server and installing MariaDB-backup "
echo "Modifying mysql-clients.cnf file"
sudo sed -i '4i [client]' /etc/my.cnf.d/mysql-clients.cnf
sudo sed -i '5i password=${primaryReplicaPassword}' /etc/my.cnf.d/mysql-clients.cnf
echo "Installing sshpass"
sudo yum -y install sshpass
echo "Stopping and disabling firewalld"
sudo systemctl stop firewalld
sudo systemctl disable firewalld
echo "firewalld stopped and disabled"
DemoSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SG to allow SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref MyIp
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref DemoIpRange
- IpProtocol: tcp
FromPort: '3306'
ToPort: '3306'
CidrIp: !Ref DemoIpRange
Tags:
- Key: Name
Value: SSH-SG
DemoHttpSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SG to allow HTTP access via port 80
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: !Ref MyIp
Tags:
- Key: Name
Value: SSH-HTTPD
Outputs:
DemoInstanceId:
Description: Instance Id
Value: !Ref mariadb1