-
Notifications
You must be signed in to change notification settings - Fork 36
/
zookeeper.json
279 lines (259 loc) · 9.16 KB
/
zookeeper.json
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
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launches an Exhibitor-managed ZooKeeper cluster",
"Parameters" : {
"InstanceType" : {
"Description" : "EC2 instance type",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [
"t2.micro", "t2.small", "t2.medium",
"m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
"c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
"c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
"r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
"i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge",
"hs1.8xlarge", "g2.2xlarge"
],
"ConstraintDescription" : "must be a valid, HVM-compatible EC2 instance type."
},
"KeyName" : {
"Description" : "Existing EC2 KeyPair to be associated with all cluster instances for SSH access. For default AMIs, log in as the 'ubuntu' user.",
"Type" : "AWS::EC2::KeyPair::KeyName"
},
"ClusterSize" : {
"Description" : "Number of nodes to launch",
"Type" : "Number",
"Default": 3
},
"DockerImage" : {
"Description" : "Path of the ZK+Exhibitor Docker image (format: '[<registry>[:<port>]/]<repository>:<version>')",
"Type" : "String",
"Default" : "mbabineau/zookeeper-exhibitor:3.4.6_1.5.4"
},
"ExhibitorS3Bucket" : {
"Description" : "Bucket for Exhibitor backups of ZK configs",
"Type" : "String"
},
"ExhibitorS3Region" : {
"Description" : "Region for Exhibitor backups of ZK configs",
"Type" : "String"
},
"ExhibitorS3Prefix" : {
"Description" : "Key prefix for S3 backups. Should be unique per S3 bucket per cluster",
"Type" : "String"
},
"Subnets" : {
"Description" : "List of VPC subnet IDs for the cluster. Note: must match up with the passed AvailabilityZones.",
"Type" : "List<AWS::EC2::Subnet::Id>"
},
"VpcId" : {
"Description" : "VPC associated with the provided subnets",
"Type" : "AWS::EC2::VPC::Id"
},
"AdminSecurityGroup" : {
"Description" : "Existing security group that should be granted administrative access to ZooKeeper (e.g., 'sg-123456')",
"Type" : "AWS::EC2::SecurityGroup::Id"
},
"AvailabilityZones": {
"Description" : "(Optional) If passed, only launch nodes in these AZs (e.g., 'us-east-1a,us-east-1b'). Note: these must match up with the passed Subnets.",
"Type" : "CommaDelimitedList",
"Default" : ""
}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : {
"AMI" : "ami-87705d90"
},
"us-west-1" : {
"AMI" : "ami-1b1e4b7b"
},
"us-west-2" : {
"AMI" : "ami-70b71410"
},
"eu-west-1" : {
"AMI" : "ami-fb91c788"
},
"ap-southeast-1" : {
"AMI" : "ami-c7e447a4"
},
"ap-southeast-2" : {
"AMI" : "ami-ac3a05cf"
},
"ap-northeast-1" : {
"AMI" : "ami-6dc0690c"
},
"sa-east-1" : {
"AMI" : "ami-45ff6029"
}
}
},
"Conditions" : {
"UseAllAvailabilityZones" : {"Fn::Equals" : [{ "Fn::Join" : ["", {"Ref" : "AvailabilityZones"} ]}, ""]}
},
"Resources" : {
"IAMUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"Policies" : [{
"PolicyName" : "S3Access",
"PolicyDocument" : {
"Statement": [{
"Effect" : "Allow",
"Action" : "s3:*",
"Resource" : { "Fn::Join" : ["", ["arn:aws:s3:::", {"Ref" : "ExhibitorS3Bucket"} , "/*"]]}
}]
}
},
{
"PolicyName" : "IAMAccess",
"PolicyDocument" : {
"Statement" : [{
"Effect" : "Allow",
"NotAction" : "iam:*",
"Resource" : "*"
}]
}
}]
}
},
"HostKeys" : {
"Type" : "AWS::IAM::AccessKey",
"Properties" : {
"UserName" : {"Ref": "IAMUser"}
}
},
"ServerGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : {
"Fn::If" : [
"UseAllAvailabilityZones",
{ "Fn::GetAZs": "AWS::Region" },
{ "Ref" : "AvailabilityZones" }
]
},
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : "1",
"MaxSize" : "9",
"DesiredCapacity" : { "Ref" : "ClusterSize" },
"LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ],
"VPCZoneIdentifier" : { "Ref" : "Subnets" },
"Tags" : [
{
"Key" : "role",
"Value" : "zookeeper",
"PropagateAtLaunch" : "true"
}
]
}
},
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI"] },
"SecurityGroups" : [ { "Ref" : "ServerSecurityGroup" }, { "Ref" : "AdminSecurityGroup" } ],
"AssociatePublicIpAddress": "true",
"InstanceType" : { "Ref" : "InstanceType" },
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -ex\n",
"# Helper function\n",
"function error_exit\n",
"{\n",
" cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
" exit 1\n",
"}\n",
"# Set up and start the Exhibitor+ZooKeeper service\n",
"docker pull ", { "Ref": "DockerImage" }, "\n",
"runit-service create zk docker run ",
" -p 8181:8181 -p 2181:2181 -p 2888:2888 -p 3888:3888",
" -e 'S3_BUCKET=", { "Ref" : "ExhibitorS3Bucket" }, "'",
" -e 'S3_PREFIX=", { "Ref" : "ExhibitorS3Prefix" }, "'",
" -e 'AWS_ACCESS_KEY_ID=", { "Ref" : "HostKeys" }, "'",
" -e 'AWS_SECRET_ACCESS_KEY=", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]}, "'",
" -e 'AWS_REGION=", { "Ref" : "ExhibitorS3Region" }, "'",
" -e \"HOSTNAME=`ec2metadata --public-hostname`\"",
" ", { "Ref": "DockerImage" }, "\n",
"runit-service enable zk\n",
"# All is well so signal success\n",
"cfn-signal -e 0 -r \"Stack setup complete\" '", { "Ref" : "WaitHandle" }, "'\n",
"#EOF"
]]}}
}
},
"ClientSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "For ZooKeeper clients. Grants access to the associated ZooKeeper cluster.",
"VpcId" : { "Ref" : "VpcId" }
}
},
"ServerSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH and Exhibitor access",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" :
[ { "IpProtocol" : "tcp", "FromPort" : "8181", "ToPort" : "8181", "SourceSecurityGroupId" : { "Ref" : "LbSecurityGroup"} },
{ "IpProtocol" : "tcp", "FromPort" : "2181", "ToPort" : "2181", "SourceSecurityGroupId" : { "Ref" : "ClientSecurityGroup"} },
{ "IpProtocol" : "tcp", "FromPort" : "2888", "ToPort" : "2888", "SourceSecurityGroupId" : { "Ref" : "ClientSecurityGroup"} },
{ "IpProtocol" : "tcp", "FromPort" : "3888", "ToPort" : "3888", "SourceSecurityGroupId" : { "Ref" : "ClientSecurityGroup"} } ]
}
},
"SecurityGroupIngress": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": { "Ref": "ServerSecurityGroup" },
"IpProtocol": "-1",
"FromPort": "0",
"ToPort": "65535",
"SourceSecurityGroupId": { "Ref": "ServerSecurityGroup" }
}
},
"LbSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable Exhibitor access",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" :
[ { "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "SourceSecurityGroupId" : { "Ref" : "ClientSecurityGroup"} } ]
}
},
"ElasticLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties" : {
"CrossZone": "true",
"Scheme": "internal",
"SecurityGroups": [{ "Ref": "LbSecurityGroup" }, { "Ref": "AdminSecurityGroup" }],
"Subnets": { "Ref": "Subnets" },
"Listeners" : [ {
"LoadBalancerPort" : "80",
"InstancePort" : "8181",
"Protocol" : "HTTP"
} ],
"HealthCheck" : {
"Target" : "HTTP:8181/exhibitor/v1/cluster/state",
"HealthyThreshold" : "3",
"UnhealthyThreshold" : "5",
"Interval" : "30",
"Timeout" : "5"
}
}
},
"WaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle"
}
},
"Outputs" : {
"ExhibitorDiscoveryUrl" : {
"Value" : { "Fn::Join" : ["", [
"http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}, "/exhibitor/v1/cluster/list"
]]}
},
"ClientSecurityGroup" : {
"Value" : { "Ref" : "ClientSecurityGroup" }
}
}
}