forked from celingest/mongo-formation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MongoNodeCLNGS-2.cftemplate
335 lines (309 loc) · 13.6 KB
/
MongoNodeCLNGS-2.cftemplate
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
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "MongoDB Replica Node 20130621-01",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access",
"Type" : "String"
},
"InstanceType" : {
"Type" : "String",
"Default" : "m1.large",
"AllowedValues" : [ "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.xlarge", "cc1.4xlarge" ],
"Description" : "EC2 instance type (e.g. m1.large, m1.xlarge, m2.xlarge)"
},
"VolumeSize" : {
"Description" : "Volume size for each EBS volume",
"Type" : "Number",
"Default" : "10"
},
"AccessKeyId" : {
"Description" : "Access Key ID",
"Type" : "String"
},
"SecretAccessKey" : {
"Description" : "Secret Access Key for the specified Access Key ID",
"Type" : "String"
},
"ReplicaSetName" : {
"Description" : "Name of the MongoDB replica set",
"Type" : "String"
},
"SecurityGroupName" : {
"Description" : "MongoDB replica set security group name",
"Type" : "String"
},
"InstanceZone" : {
"Description" : "AvailabilityZone for this instance",
"Type" : "String"
}
},
"Mappings" : {
"InstanceTypeArch" : {
"m1.small" : { "Arch" : "64" },
"m1.medium" : { "Arch" : "64" },
"m1.large" : { "Arch" : "64" },
"m1.xlarge" : { "Arch" : "64" },
"m2.xlarge" : { "Arch" : "64" },
"m2.2xlarge" : { "Arch" : "64" },
"m2.4xlarge" : { "Arch" : "64" },
"c1.medium" : { "Arch" : "64" },
"c1.xlarge" : { "Arch" : "64" },
"cc1.4xlarge" : { "Arch" : "64HVM" }
},
"RegionImageZone" : {
"us-east-1" : { "64" : "ami-a73758ce", "64HVM" : "ami-a73758ce" },
"us-west-2" : { "64" : "ami-0358ce33", "64HVM" : "ami-d75bcde7" },
"us-west-1" : { "64" : "ami-3ffed17a", "64HVM" : "ami-47fed102" },
"eu-west-1" : { "64" : "ami-c7c0d6b3", "64HVM" : "ami-d1c0d6a5" },
"ap-southeast-1": { "64" : "ami-fade91a8", "64HVM" : "ami-18de914a" },
"ap-southeast-2": { "64" : "ami-39b23d38", "64HVM" : "ami-2db33c2c" },
"ap-northeast-1": { "64" : "ami-d16bfbeb", "64HVM" : "ami-876bfbbd" },
"sa-east-1" : { "64" : "ami-5253894f", "64HVM" : "ami-38538925" }
}
},
"Resources" : {
"ReplicaSetMemberInstance" : {
"Type" : "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"packages" : {
"yum" : {
"mdadm" : [],
"sysstat" : [],
"xfsprogs" : [],
"ntp" : []
}
},
"files" : {
"/etc/yum.repos.d/10gen.repo" : {
"content" : { "Fn::Join" : ["", [
"[10gen]\n",
"name=10gen Repository\n",
"baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64\n",
"gpgcheck=0\n"
] ] },
"mode" : "000644",
"owner" : "root",
"group" : "root"
},
"/etc/rc.local" : {
"content" : { "Fn::Join" : ["", [
"#!/bin/sh\n",
"#\n",
"# This script will be executed *after* all the other init scripts.\n",
"# You can put your own initialization stuff in here if you don't\n",
"# want to do the full Sys V style init stuff.\n",
"# \n",
"# See http://docs.mongodb.org/manual/faq/diagnostics/#does-tcp-keepalive-time-affect-sharded-clusters-and-replica-sets\n",
"echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time\n",
"touch /var/lock/subsys/local\n"
] ] },
"mode" : "000644",
"owner" : "root",
"group" : "root"
}
},
"services" : {
"sysvinit" : {
"ntpd" : { "enabled" : "true", "ensureRunning" : "true" }
}
}
}
}
},
"Properties" : {
"InstanceType" : { "Ref" : "InstanceType" },
"ImageId" : { "Fn::FindInMap" : [ "RegionImageZone", { "Ref" : "AWS::Region" },
{ "Fn::FindInMap" : [ "InstanceTypeArch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
"Tags" : [{ "Key" : "Name", "Value" : "MongoReplica" }],
"SecurityGroups" : [ { "Ref" : "SecurityGroupName" } ],
"KeyName" : { "Ref" : "KeyName" },
"AvailabilityZone" : {"Ref" : "InstanceZone" },
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"#\n",
"# Sending all output to /tmp/install.log\n",
"#\n",
"exec 2> /tmp/install.log\n",
"exec >> /tmp/install.log\n",
"#\n",
"# Updating CloudFormation scripts\n",
"#\n",
"yum update -y aws-cfn-bootstrap\n",
"# Error reporting helper function\n",
"function error_exit\n",
"{\n",
"/opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandleReplicaSetMember" }, "'\n",
"exit 1\n",
"}\n",
"## Initialize CloudFormation bits\n",
"/opt/aws/bin/cfn-init -v -s ", { "Ref" : "AWS::StackName" }, " -r ReplicaSetMemberInstance",
" --access-key ", { "Ref" : "AccessKeyId" },
" --secret-key ", {"Ref": "SecretAccessKey" },
" --region ", { "Ref" : "AWS::Region" }, " > /tmp/cfn-init.log 2>&1 || error_exit $(</tmp/cfn-init.log)\n",
"#\n",
"## Variables\n",
"#\n",
"RAIDMEMBERS=4\n",
"## Wait until ALL EBS are connected\n",
"while [ \"$(ls /dev/sdh*|wc -l)\" -lt \"$RAIDMEMBERS\" ]; do sleep 1; done\n",
"#\n",
"# LVM Create with stripe\n",
"#\n",
"#\n",
"# if all devices are ready then\n",
"EBS=($(ls /dev/sdh*))\n",
"if [ ${#EBS[@]} -eq $RAIDMEMBERS ]; then echo \"Desired EBSs ${#EBS[@]} Vs Ready $RAIDMEMBERS : Proceding...\"; pvcreate ${EBS[@]}; else exit; fi\n",
"# if all PVs are ready then\n",
"PVS=($(pvscan | head -n -1 |awk '{print $2}'))\n",
"if [ ${#PVS[@]} -eq $RAIDMEMBERS ]; then echo \"Desired PVs ${#PVS[@]} Vs Ready $RAIDMEMBERS : Proceding...\"; vgcreate vg0 ${PVS[@]}; else exit; fi\n",
"#\n",
"lvcreate -i 4 -I 256 -n mongo -l 100%FREE vg0\n",
"#\n",
"## Tuning read-ahead=ON\n",
"#\n",
"blockdev -v --setra 128 ${EBS[@]}\n",
"blockdev --setra 256 /dev/vg0/mongo\n",
"#\n",
"## Create MongoDB filesystem\n",
"#\n",
"mkfs.xfs -f -L mongo /dev/vg0/mongo\n",
"mkdir -p /var/lib/mongo\n",
"#\n",
"## Update /etc/fstab\n",
"#\n",
"cat << END >> /etc/fstab\n",
"/dev/vg0/mongo /var/lib/mongo xfs noatime,nodiratime,logbufs=8,nodev,noexec 0 0\n",
"END\n",
"#\n",
"## Mounting all new resources\n",
"#\n",
"mount -av\n",
"#\n",
"## Minimum performance tuning: Set limits for mongod user\n",
"#\n",
"cat << END > /etc/security/limits.conf\n",
"mongod soft nofile 64000\n",
"mongod soft nproc 32000\n",
"mongos soft nofile 64000\n",
"mongos soft nproc 32000\n",
"END\n",
"#\n",
"## Updating RPMs and Installing MongoDB\n",
"#\n",
"yum update -y\n",
"yum install mongo-10gen-server -y\n",
"#\n",
"## Create MongoDB config\n",
"#\n",
"cat << END > /etc/mongod.conf\n",
"# mongod.conf\n",
"dbpath=/var/lib/mongo\n",
"logpath=/var/log/mongo/mongod.log\n",
"logappend=true\n",
"fork=true\n",
"replSet=", {"Ref" : "ReplicaSetName"}, "\n",
"# Enable webserver REST\n",
"rest = true\n",
"END\n",
"#\n",
"## Fixing mongod permission on /var/lib/mongo\n",
"#\n",
"chown -Rv mongod:mongod /var/lib/mongo\n",
"#\n",
"## Updating system config and starting MongoDB\n",
"#\n",
"chkconfig mongod on\n",
"service mongod start\n",
"#\n",
"## CloudFormation signal that setup is complete\n",
"/opt/aws/bin/cfn-signal -e 0 -r \"ReplicaSetMemberInstance setup complete\" '", { "Ref" : "WaitHandleReplicaSetMember" }, "'\n"
] ] } }
}
},
"MongoVolume1" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : { "Ref" : "VolumeSize" },
"Tags" : [{ "Key" : "Name", "Value" : "MongoVolume" }],
"AvailabilityZone" : { "Fn::GetAtt" : [ "ReplicaSetMemberInstance", "AvailabilityZone" ]}
}
},
"MongoVolume2" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : { "Ref" : "VolumeSize" },
"Tags" : [{ "Key" : "Name", "Value" : "MongoVolume" }],
"AvailabilityZone" : { "Fn::GetAtt" : [ "ReplicaSetMemberInstance", "AvailabilityZone" ]}
}
},
"MongoVolume3" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : { "Ref" : "VolumeSize" },
"Tags" : [{ "Key" : "Name", "Value" : "MongoVolume" }],
"AvailabilityZone" : { "Fn::GetAtt" : [ "ReplicaSetMemberInstance", "AvailabilityZone" ]}
}
},
"MongoVolume4" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : { "Ref" : "VolumeSize" },
"Tags" : [{ "Key" : "Name", "Value" : "MongoVolume" }],
"AvailabilityZone" : { "Fn::GetAtt" : [ "ReplicaSetMemberInstance", "AvailabilityZone" ]}
}
},
"MongoVolumeMount1" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "ReplicaSetMemberInstance" },
"VolumeId" : { "Ref" : "MongoVolume1" },
"Device" : "/dev/sdh1"
}
},
"MongoVolumeMount2" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "ReplicaSetMemberInstance" },
"VolumeId" : { "Ref" : "MongoVolume2" },
"Device" : "/dev/sdh2"
}
},
"MongoVolumeMount3" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "ReplicaSetMemberInstance" },
"VolumeId" : { "Ref" : "MongoVolume3" },
"Device" : "/dev/sdh3"
}
},
"MongoVolumeMount4" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "ReplicaSetMemberInstance" },
"VolumeId" : { "Ref" : "MongoVolume4" },
"Device" : "/dev/sdh4"
}
},
"WaitHandleReplicaSetMember" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle",
"Properties" : {}
},
"WaitConditionReplicaSetMember" : {
"Type" : "AWS::CloudFormation::WaitCondition",
"DependsOn" : "ReplicaSetMemberInstance",
"Properties" : {
"Handle" : { "Ref" : "WaitHandleReplicaSetMember" },
"Timeout" : "600"
}
}
},
"Outputs" : {
"ReplicaSetMemberName" : {
"Value" : { "Fn::GetAtt" : [ "ReplicaSetMemberInstance", "PublicDnsName" ] },
"Description" : "public DNS name of the MongoDB Replica Set Member Instance"
}
}
}