-
Notifications
You must be signed in to change notification settings - Fork 0
/
HAProxy_Single_Instance_Ubuntu.template
158 lines (149 loc) · 5.24 KB
/
HAProxy_Single_Instance_Ubuntu.template
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A load balancer instance running a local HAproxy on Ubuntu",
"Parameters": {
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type": "String"
},
"Server1": {
"Description": "Server1 to load balance <ip:port>",
"Type": "String"
},
"InstanceType": {
"Description": "HAProxy server EC2 instance type",
"Default": "m1.small",
"Type": "String",
"AllowedValues": [ "m1.tiny", "m1.small", "m1.medium", "m1.large", "m1.xlarge" ],
"ConstraintDescription": "must be a valid EC2 instance type."
},
"LinuxDistribution": {
"Default": "U12",
"Description" : "Distribution of choice",
"Type": "String",
"AllowedValues" : [ "F19", "F18", "F17", "U12", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ]
}
},
"Mappings" : {
"AWSInstanceType2Arch" : {
"m1.tiny" : { "Arch" : "32" },
"m1.small" : { "Arch" : "64" },
"m1.medium" : { "Arch" : "64" },
"m1.large" : { "Arch" : "64" },
"m1.xlarge" : { "Arch" : "64" }
},
"DistroArch2AMI": {
"F19" : { "32" : "F19-i386-cfntools", "64" : "F19-heat-cfntools" },
"F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" },
"F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" },
"U12" : { "32" : "U10-i386-cfntools", "64" : "precise" },
"RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" },
"RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" },
"RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" }
}
},
"Resources": {
"LoadBalancerInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init": {
"configSets" : {
"proxy" : [ "config1" , "config2" ]
},
"config1": {
"files": {
"/etc/yum.conf": {
"content": { "Fn::Join": ["", [
"[main]\n",
"cachedir=/var/cache/yum/$basearch/$releasever\n",
"keepcache=0\n",
"debuglevel=2\n",
"logfile=/var/log/yum.log\n",
"exactarch=1\n",
"obsoletes=1\n",
"gpgcheck=1\n",
"plugins=1\n",
"installonly_limit=3\n",
"# The proxy server - proxy server:port number\n",
"proxy=http://173.36.196.10:80\n",
"\n"
]]},
"mode": "000644",
"owner": "root",
"group": "root"
}
}
},
"config2": {
"packages": {
"apt-get": {
"haproxy" : []
}
},
"services": {
"systemd": {
"haproxy" : { "enabled": "true", "ensureRunning": "true" }
}
},
"files": {
"/etc/haproxy/haproxy.cfg": {
"content": { "Fn::Join": ["", [
" global\n",
" daemon\n",
" maxconn 256\n",
"\n",
" defaults\n",
" mode http\n",
" timeout connect 5000ms\n",
" timeout client 50000ms\n",
" timeout server 50000ms\n",
"\n",
" frontend http-in\n",
" bind *:80\n",
" default_backend servers\n",
"\n",
" backend servers\n",
" balance roundrobin\n",
" option http-server-close\n",
" option forwardfor\n",
" server server1 ", { "Ref" : "Server1" }, "\n"
]]},
"mode": "000644",
"owner": "root",
"group": "root"
}
}
}
}
},
"Properties": {
"ImageId" : {
"Fn::FindInMap" : [ "DistroArch2AMI",
{ "Ref" : "LinuxDistribution" },
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch",
{ "Ref" : "InstanceType" },
"Arch" ] } ]
},
"InstanceType": { "Ref": "InstanceType" },
"KeyName": { "Ref": "KeyName" },
"UserData": { "Fn::Base64": { "Fn::Join": ["", [
"#!/bin/bash -v\n",
"apt-get -y update\n",
"apt-get -y install haproxy\n",
"sed 's/.*ENABLED.*/#/g' /etc/init.d/haproxy > /etc/init.d/temp\n",
"mv /etc/init.d/temp /etc/init.d/haproxy\n",
"chmod 774 /etc/init.d/haproxy\n",
"/opt/aws/bin/cfn-init -c proxy -s ",
{ "Ref": "AWS::StackName" },
" --region ", { "Ref": "AWS::Region" }, "\n"
]]}}
}
}
},
"Outputs": {
"PublicIp": {
"Value": { "Fn::GetAtt": [ "LoadBalancerInstance", "PublicIp" ] },
"Description": "instance IP"
}
}
}