-
Notifications
You must be signed in to change notification settings - Fork 5
/
neo4j-cluster.yml
306 lines (231 loc) · 10.6 KB
/
neo4j-cluster.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
---
# This playbook is for deploying multiple instances into EC2/Euca to create a Neo4j Cluster running on Ubuntu Cloud Images.
# - uses the ec2 module.
#
# Run this with ansible-playbook and supply the private key for your EC2/Euca user (to access the instances to configure the cluster ), e.g:
# ansible-playbook neo4j-cluster.yml -v --private-key=/path/to/ec2/pri/key
- name: Stage Neo4j Cluster
hosts: local
connection: local
user: ubuntu
gather_facts: false
vars_files:
- vars/ec2-config
- vars/neo4j-cluster
- vars/haproxy
tasks:
- name: Launch Neo4j cluster instances
local_action: ec2 keypair=${keypair} group=${security_group} instance_type=${instance_type} image=${image} wait=true count=${node_count}
register: ec2
- name: Add new instances to host group with public IPs, adding private IP and AMI Launch Index as variables
local_action: add_host hostname=${item.public_ip} groupname=neo4j-cluster private_ip=${item.private_ip} ami_launch_index=${item.ami_launch_index}
with_items: ${ec2.instances}
- name: Template the /etc/hosts file so all cluster members know of each other
local_action: template src=./templates/hosts.j2 dest=/tmp/hosts
- name: Template the haproxy.cfg file; save template for later
local_action: template src=./templates/haproxy.cfg.j2 dest=/tmp/haproxy.cfg
- name: Report
local_action: debug msg="Cluster members launched."
- name: Launch HA Proxy instance
local_action: ec2 keypair=${keypair} group=${security_group} instance_type=${instance_type} image=${image} wait=true
register: ec2_ha
- name: Add instance to host group with public IPs
local_action: add_host hostname=${item.public_ip} groupname=haproxy
with_items: ${ec2_ha.instances}
- name: Report
local_action: debug msg="HA Proxy server launched."
- name: Wait for a while before trying to configure instances
local_action: pause seconds=30
- name: Install dependency packages
hosts: neo4j-cluster
user: ubuntu
sudo: yes
gather_facts: true
tasks:
- name: Report
local_action: debug msg="Configuring cluster members with pre-req software..."
- name: Add hosts of instances in Neo4j cluster group to /etc/hosts
action: copy src=/tmp/hosts dest=/etc/hosts
- name: Update Repositories
action: command apt-get -y --force-yes dist-upgrade
- name: Neo4j Repository Signing Key
action: apt_key url=http://debian.neo4j.org/neotechnology.gpg.key state=present
- name: Add Neo4j Repository - Debian
action: apt_repository repo='deb http://debian.neo4j.org/repo testing/'
- name: Euca2ools Repository Signing Key
action: apt_key url=http://www.eucalyptus.com/sites/all/files/c1240596-eucalyptus-release-key.pub state=present
- name: Add Euca2ools Repository for Ubuntu Precise
action: apt_repository repo='deb http://downloads.eucalyptus.com/software/euca2ools/2.1/ubuntu precise main'
- name: Update Repositories Cache
action: command apt-get update
- name: Ensure NTP is installed
action: apt pkg=ntp force=yes
- name: Ensure NTP is up and running
action: service name=ntp state=started
ignore_errors: yes
- name: Ensure less, bind9utils, openjdk-6-jdk, liblog4j1.2-java, facter, ruby-json and euca2ools is installed
action: apt pkg=${item} force=yes
with_items:
- less
- bind9utils
- openjdk-6-jdk
- liblog4j1.2-java
- daemon
- default-jre
- default-jre-headless
- facter
- ruby-json
- euca2ools
- name: Gather EC2 Metadata Information for Hostname
action: ec2_facts
- name: Grab Hostname and set it for the instances
action: sysctl name=kernel.hostname value=${ansible_ec2_local_hostname} state=present
- name: Install dependency packages for HA Proxy
hosts: haproxy
user: ubuntu
sudo: yes
gather_facts: true
tasks:
- name: Report
local_action: debug msg="Configuring haproxy instance with pre-req software..."
- name: Update Repositories
action: command apt-get -y --force-yes dist-upgrade
- name: Euca2ools Repository Signing Key
action: apt_key url=http://www.eucalyptus.com/sites/all/files/c1240596-eucalyptus-release-key.pub state=present
- name: Add Euca2ools Repository for Ubuntu Precise
action: apt_repository repo='deb http://downloads.eucalyptus.com/software/euca2ools/2.1/ubuntu precise main'
- name: Update Repositories Cache
action: command apt-get update
- name: Ensure NTP is installed
action: apt pkg=ntp force=yes
- name: Ensure less, haproxy, socat, bind9utils, facter, ruby-json, and euca2ools
action: apt pkg=${item} force=yes
with_items:
- less
- haproxy
- socat
- bind9utils
- facter
- ruby-json
- euca2ools
- name: Ensure NTP is up and running
action: service name=ntp state=started
ignore_errors: yes
- name: Gather EC2 Metadata Information for Hostname
action: ec2_facts
- name: Grab Hostname and set it for the instances
action: sysctl name=kernel.hostname value=${ansible_ec2_local_hostname} state=present
- name: Copy haproxy.cfg to HAProxy instance
action: copy src=/tmp/haproxy.cfg dest=/etc/haproxy/haproxy.cfg
- name: Enable haproxy to be controlled by service
action: lineinfile dest=/etc/default/haproxy state=present regexp=^ENABLED line=ENABLED=1
- name: Prepare Ephemeral Storage and Install Neo4j Software
hosts: neo4j-cluster
user: ubuntu
sudo: yes
gather_facts: true
tasks:
- name: Report
local_action: debug msg="Ensure ephemeral storage is setup correctly..."
- name: Ensure ephemeral device is labeled
action: command /sbin/tune2fs -L ephemeral0 /dev/${item} removes=/dev/${item}
with_items:
- sda2
- vda2
- xvda2
- name: Create Neo4j Directory
action: command /bin/mkdir -p /var/lib/neo4j
- name: Check to see if ephemeral is already mounted
action: mount name=${item} src=LABEL=ephemeral0 fstype=auto state=present
with_items:
- /mnt
- /media/ephemeral0
register: ephemeral_mounted
ignore_errors: yes
action: mount name=${item} src=LABEL=ephemeral0 fstype=auto state=unmounted
with_items:
- /mnt
- /media/ephemeral0
when_unset: $ephemeral_mounted
register: ephemeral_unmounted
ignore_errors: yes
- name: Mount ephemeral storage
action: mount name=/var/lib/neo4j src=LABEL=ephemeral0 fstype=auto opts=defaults,nobootwait,comment=neo4j-storage state=mounted
when_set: $ephemeral_unmounted
- name: Edit rc.local to make sure ephemeral remounts in the case of a reboot
action: lineinfile dest=/etc/rc.local regexp='^# By' insertafter="^# By default this script does nothing." line="# By default this script does nothing.\nMETA_HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/local-hostname`\nMETA_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`\necho ${META_IP} ${META_HOSTNAME} >> /etc/hosts; hostname ${META_HOSTNAME}; sysctl -w kernel.hostname=${META_HOSTNAME}\nif [ -d /var/lib/neo4j/ ]; then mount LABEL=ephemeral0 /var/lib/neo4j; /var/lib/neo4j/bin/neo4j start; fi"
- name: Install Neo4j Enterprise
action: apt pkg=neo4j-enterprise force=yes
- name: Configure Neo4j HA Cluster
hosts: neo4j-cluster
user: ubuntu
sudo: yes
gather_facts: true
vars_files:
- vars/neo4j-cluster
tasks:
- name: Report
local_action: debug msg="Prepare for config file changes"
- name: Stop the Neo4j Service
action: command /usr/sbin/service neo4j-service remove
async: 60
poll: 5
- name: Wait for neo4j-service to stop
wait_for: port=7474 state=stopped timeout=80
- name: Gather EC2 Metadata Information
action: ec2_facts
- name: Copy neo4j.properties to each member of the Neo4j cluster group
action: template src=./templates/neo4j.properties.j2 dest=/var/lib/neo4j/conf/neo4j.properties owner=neo4j group=adm mode=0644
- name: Copy neo4j-server.properties to each member of the Neo4j cluster group
action: template src=./templates/neo4j-server.properties.j2 dest=/var/lib/neo4j/conf/neo4j-server.properties owner=neo4j group=adm mode=0644
- name: Copy neo4j-wrapper.conf to each member of the Neo4j cluster group
action: template src=./templates/neo4j-wrapper.conf.j2 dest=/var/lib/neo4j/conf/neo4j-wrapper.conf owner=neo4j group=adm mode=0644
- name: Change permissions to 0600 of jmx.password file
action: file path=/var/lib/neo4j/conf/jmx.password mode=0600
- name: Change ulimit to 40000
action: lineinfile dest=/etc/security/limits.conf regexp='^ubuntu' insertbefore="^# End of file" line="ubuntu soft nofile 40000\nubuntu hard nofile 40000\n"
- name: Start Neo4j on each node in the cluster
hosts: neo4j-cluster
user: ubuntu
sudo: yes
gather_facts: true
serial: 1
tasks:
- name: Gather EC2 Metadata Information
action: ec2_facts
- name: Grab webserver port for test to see if Neo4j starts
action: shell echo ${ansible_ec2_ami_launch_index} | awk '{PORT = 7474 + $1; print PORT}'
register: webserver_port
- name: Start the Neo4j Service
action: command /var/lib/neo4j/bin/neo4j start
async: 80
poll: 5
- name: Wait for neo4j-service to start
wait_for: port=${webserver_port.stdout} timeout=120
- name: Start HA Proxy and open port in security group
hosts: haproxy
user: ubuntu
sudo: yes
gather_facts: true
vars_files:
- vars/ec2-config
- vars/haproxy
tasks:
- name: Report
local_action: debug msg="Start HAProxy"
- name: Start the HA Proxy Service
action: command /usr/sbin/service haproxy start
async: 20
poll: 5
- name: Gather EC2 Metadata Information
action: ec2_facts
- name: Report
local_action: debug msg="Open HAProxy Port in security group"
- name: Open HA Proxy port
action: shell /usr/bin/euca-authorize --access-key ${ec2_access_key} --secret-key ${ec2_secret_key} --url ${ec2_url} -P tcp -p ${haproxyport} -s 0.0.0.0/0 ${ansible_ec2_security_groups}
- name: Wait for HAProxy to become available
wait_for: port=${haproxyport} timeout=120
register: port_result
- name: Display HAProxy URL
action: shell echo "HAProxy URL for Neo4j - ${haproxymode}://${ansible_ec2_public_hostname}/webadmin/#/info/org.neo4j/High%20Availability/"
when_string: ${port_result.state} == 'started'