forked from rcbops/RPC-Heat-Galera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mariadb_stack.yaml
802 lines (712 loc) · 20.5 KB
/
mariadb_stack.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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
heat_template_version: 2013-05-23
description: |
Deploys Salt-master and serveral salt-minions for a MariaDB/Galera cluster.
One Minion will be for haproxy
One Minion will act as a bootstrap node
Two minions will act as additional nodes in the cluster.
parameter_groups:
- parameters:
- keyname
- image
- floating-network-id
- apps-network
- flavor
- db-username
- db-user-password
- db-remotehost
- database
parameters:
keyname:
type: string
label: Salt-Master Key Name
description: Name of the key used to ssh into the Salt-Master.
image:
type: string
label: Image Name
description: Name of the existing image to use for every virtual machine created by this stack. The image should have the heat-config and heat-config-script files included.
floating-network-id:
type: string
label: External Network UUID
description: UUID of the external network. The private network created by this stack will route to this network. Any floating IP addresses needed by this stack will also route to this network.
db-username:
type: string
label: Username to Create on the Database
description: Username that will be created on the Galera cluster.
db-user-password:
type: string
hidden: true
label: Password for the Database Username
description: Password for the database username specified.
db-remotehost:
type: string
default: "%"
label: Name of the Remote Host
description: Hostname of the remote host that will have access to the database using the username specified above.
apps-network:
type: string
label: Network UUID of Application Network
description: Network UUID of the network where you run your applications (for example, Magento, Drupal).
database:
type: string
label: Name of Database to Create for the Application
description: Database name that will be created for the application.
flavor:
type: string
label: Flavor
description: Flavor (size) of the database instances.
default: m1.small
resources:
# Random string to aid in naming things.
stack-string:
type: OS::Heat::RandomString
properties:
length: 6
sequence: lettersdigits
# Will be used to generate a random password
# 32 characters long consisting of alpha numeric characters
secret:
type: OS::Heat::RandomString
properties:
length: 32
sequence: lettersdigits
admin_password:
type: OS::Heat::RandomString
properties:
length: 10
sequence: lettersdigits
#This is the security group for the haproxy node to allow mysql, web, icmp, and ssh traffic
secgroup:
type: OS::Neutron::SecurityGroup
properties:
name:
str_replace:
template: galera-$stackstr-secgroup
params:
$stackstr:
get_attr:
- stack-string
- value
description: Ping, SSH, MySQL, web, salt, and galera replication traffic is allowed
rules:
- protocol: icmp
- protocol: tcp
port_range_min: 22
port_range_max: 22
- protocol: tcp
port_range_min: 3306
port_range_max: 3306
- protocol: tcp
port_range_min: 13306
port_range_max: 13306
- protocol: tcp
port_range_min: 4505
port_range_max: 4506
remote_ip_prefix:
get_attr:
- subnet
- cidr
- protocol: tcp
port_range_min: 4567
port_range_max: 4568
remote_ip_prefix:
get_attr:
- subnet
- cidr
- protocol: tcp
port_range_min: 4444
port_range_max: 4444
remote_ip_prefix:
get_attr:
- subnet
- cidr
# Keypair for communicating between nodes within the stack.
# Will allow minions to ssh into the master and vice versa.
coms:
type: OS::Nova::KeyPair
properties:
name:
str_replace:
template: galera-$stackstr-coms
params:
$stackstr:
get_attr:
- stack-string
- value
save_private_key: true
# Private network for this stack
net:
type: OS::Neutron::Net
# Private subnet for this stack
subnet:
type: OS::Neutron::Subnet
properties:
network_id:
get_resource: net
cidr: 10.10.10.0/24
dns_nameservers:
- 8.8.8.8
- 4.2.2.2
# Routes the private network to the external network.
router:
type: OS::Neutron::Router
properties:
external_gateway_info:
network:
get_param: floating-network-id
# Router interface
interface:
type: OS::Neutron::RouterInterface
properties:
router_id:
get_resource: router
subnet_id:
get_resource: subnet
# One floating ip for the salt-master node
master-ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id:
get_param: floating-network-id
# One port for the salt-master node
master-port:
type: OS::Neutron::Port
properties:
network_id:
get_resource: net
security_groups:
- get_resource: secgroup
apps-net-port:
type: OS::Neutron::Port
properties:
network_id:
get_param: apps-network
security_groups:
- {get_resource: secgroup}
# Software configuration script for the salt-master node
# Installs salt-master, sets permission on some personality files
# and uses git to clone any provided state/formula repos
config-salt-master:
type: OS::Heat::SoftwareConfig
properties:
group: script
inputs:
- name: public_key
- name: state_repos
config: |
#!/bin/bash
set -ex
logdir=/var/log/heat-deployments
prefix=${logdir}/config-salt-master
mkdir -p $logdir
exec &> >(tee -a ${prefix}.log)
[ -e ${prefix}.ran ] && exit 0
chmod -R 0600 ${logdir}
chmod 0700 /root/.ssh/coms_rsa
chmod 0600 /srv/pillar/galera/init.sls
# Add coms from minions to master
echo "$public_key" >> /root/.ssh/authorized_keys
# Install git
apt-get install -y git
# Install salt master
echo "Install Salt Master"
add-apt-repository ppa:saltstack/salt
apt-get update -y
apt-get install -y salt-master
mkdir -p /srv/salt
mkdir -p /srv/salt/orchestration
mkdir -p /srv/pillar
mkdir -p /srv/pillar/galera
mkdir -p /srv/pillar/haproxy
mkdir -p /srv/reactor
echo -e 'file_roots:\n base:\n - /srv/salt' >> /etc/salt/master
# Clone state/formula repos in state root directory
cd /srv/salt
while read -r line
do
if [ -n "$line" ]; then
git clone $line
fi
done <<< "$state_repos"
# Finally - Restart salt service
service salt-master restart
touch ${prefix}.ran
# Software configuration for salt minion
# Installs salt-minion, sets up authentication from minion to master,
# and sets permissions of any personality files.
config-salt-minion:
type: OS::Heat::SoftwareConfig
properties:
group: script
inputs:
- name: public_key
- name: master
config: |
#!/bin/bash
set -ex
logdir=/var/log/heat-deployments
prefix=${logdir}/config-salt-minion
mkdir -p $logdir
exec &> >(tee -a ${prefix}.log)
[ -e ${prefix}.ran ] && exit 0
chmod -R 0600 ${logdir}
chmod 0700 /root/.ssh/coms_rsa
# Add coms from minions to master
echo "$public_key" >> /root/.ssh/authorized_keys
# Install salt minion
add-apt-repository ppa:saltstack/salt
apt-get update -y
apt-get install -y salt-minion
#Installing debconf-utils because deconf.set does not return
apt-get install debconf-utils -y
echo master: $master >> /etc/salt/minion
service salt-minion restart
rm /root/.ssh/coms_rsa
#Configuring second interface on all nodes, even though haproxy is the
#only node with two NICs.
cat <<EOF > /etc/network/interfaces.d/eth1.cfg
#File generated by Heat.
auto eth1
iface eth1 inet dhcp
EOF
#Bring up second nic, will ignore if eth1 does not exist.
ifup eth1
touch ${prefix}.ran
# Software deployment for salt-master. Deploys the salt-master software
# configuration.
# Also lists the git repos necessary to make the galera stack work.
deploy-salt-master:
type: OS::Heat::SoftwareDeployment
properties:
input_values:
public_key:
get_attr:
- coms
- public_key
state_repos: |
https://github.com/rcbops/galera
https://github.com/rcbops/base-hardening-formula
config:
get_resource: config-salt-master
server:
get_resource: master
# The salt master instance
# Should have one floating ip
master:
type: OS::Nova::Server
depends_on: interface
properties:
key_name:
get_param: keyname
image:
get_param: image
flavor:
get_param: flavor
name:
str_replace:
template: galera-$stackstr-master
params:
$stackstr:
get_attr:
- stack-string
- value
personality:
# Private key for ssh'ing into minions
/root/.ssh/coms_rsa:
get_attr:
- coms
- private_key
/etc/salt/master.d/reactor.conf: |
reactor:
- 'salt/auth':
- /srv/reactor/auth-pending.sls
/srv/reactor/auth-pending.sls: |
{% if 'act' in data and data['act'] == 'pend' and data['id'].startswith('galera') %}
minion_add:
wheel.key.accept:
- match: {{ data['id'] }}
{% endif %}
#The top.sls file for salt pillars
#Dictates which minions get which pillars.
/srv/pillar/top.sls: |
base:
'*':
- galera
#The galera pillar. Contains Some basic information for mariadb/galera config and installation
/srv/pillar/galera/init.sls:
str_replace:
template: |
interfaces:
private: eth0
public: eth0
mine_functions:
network.ip_addrs: [eth0]
network.interfaces: []
mine_interval: 1
mdb_cfg_files:
ubuntu_cluster:
path: /etc/mysql/conf.d/cluster.cnf
source: salt://galera/config/cluster.cnf
ubuntu_maintenance:
path: /etc/mysql/debian.cnf
source: salt://galera/config/debian.cnf
mdb_config:
provider: /usr/lib/galera/libgalera_smm.so
mdb_repo:
baseurl: http://mirror.jmu.edu/pub/mariadb/repo/10.0/ubuntu
keyserver: hkp://keyserver.ubuntu.com:80
keyid: '0xcbcb082a1bb943db'
file: /etc/apt/sources.list
percona_repo:
keyserver: keys.gnupg.net
keyid: '1C4CBDCDCD2EFD2A'
file: /etc/apt/sources.list
user_via_heat:
name: $user
password: $password
remotehost: "$remotehost"
database:
name: $database
mysql_config:
dbuser: root
port: 3306
socket: /var/lib/mysql/mysql.sock
datadir: /var/lib/mysql/db_data
maintenance_password: $pw
admin_password: $admin_password
user-ports:
ssh:
chain: INPUT
proto: tcp
dport: 22
salt-master:
chain: INPUT
proto: tcp
dport: 4505
salt-minion:
chain: INPUT
proto: tcp
dport: 4506
galera:
chain: INPUT
proto: tcp
dport: 4567
rsync:
chain: INPUT
proto: tcp
dport: 4444
mysql-read:
chain: INPUT
proto: tcp
dport: 3306
mysql-write:
chain: INPUT
proto: tcp
dport: 13306
params:
$user:
get_param: db-username
$password:
get_param: db-user-password
$remotehost:
get_param: db-remotehost
$database:
get_param: database
$pw:
get_attr:
- secret
- value
$admin_password:
get_attr:
- admin_password
- value
# Get access from the master-port
networks:
- port:
get_resource: master-port
# Using SoftwareConfigs - This needs to be set to SOFTWARE_CONFIG
user_data_format: SOFTWARE_CONFIG
# Associate the master floating ip to the master port
master-floating-ip-ass:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id:
get_resource: master-ip
port_id:
get_resource: master-port
# Port for haproxy node
minion-haproxy-port:
type: OS::Neutron::Port
properties:
network_id:
get_resource: net
security_groups:
- get_resource: secgroup
# haproxy minion
minion-haproxy:
type: OS::Nova::Server
depends_on: interface
properties:
flavor:
get_param: flavor
image:
get_param: image
name:
str_replace:
template: galera-$stackstr-haproxy
params:
$stackstr:
get_attr:
- stack-string
- value
personality:
# Private key for node to node communication
/root/.ssh/coms_rsa:
get_attr:
- coms
- private_key
# Set the salt role to haproxy
/etc/salt/grains: |
roles:
- haproxy
networks:
- port:
get_resource: minion-haproxy-port
- port:
get_resource: apps-net-port
# Needs to be SOFTWARE_CONFIG when using SoftwareConfigs
user_data_format: SOFTWARE_CONFIG
# Deploys the salt-minion software config to the haproxy node.
deploy-haproxy:
type: OS::Heat::SoftwareDeployment
depends_on: deploy-salt-master
properties:
input_values:
public_key:
get_attr:
- coms
- public_key
master:
get_attr:
- master
- first_address
config:
get_resource: config-salt-minion
server:
get_resource: minion-haproxy
# The bootstrap node of the cluster.
minion-db-bootstrap:
type: OS::Nova::Server
depends_on: interface
properties:
image:
get_param: image
flavor:
get_param: flavor
name:
str_replace:
template: galera-$stackstr-db-bootstrap
params:
$stackstr:
get_attr:
- stack-string
- value
personality:
# Private key for node to node communications
/root/.ssh/coms_rsa:
get_attr:
- coms
- private_key
# Set the salt-grain roles to ['db']
/etc/salt/grains: |
roles:
- db_bootstrap
networks:
- network:
get_resource: net
security_groups:
- get_resource: secgroup
# This needs to be set to SOFTWARE_CONFIG when using SoftwareConfigs
user_data_format: SOFTWARE_CONFIG
# The db node of the cluster.
minion-db2:
type: OS::Nova::Server
depends_on: interface
properties:
image:
get_param: image
flavor:
get_param: flavor
name:
str_replace:
template: galera-$stackstr-db2
params:
$stackstr:
get_attr:
- stack-string
- value
personality:
# Private key for node to node communications
/root/.ssh/coms_rsa:
get_attr:
- coms
- private_key
# Set the salt-grain roles to ['db']
/etc/salt/grains: |
roles:
- db
networks:
- network:
get_resource: net
security_groups:
- get_resource: secgroup
# This needs to be set to SOFTWARE_CONFIG when using SoftwareConfigs
user_data_format: SOFTWARE_CONFIG
# The db node of the cluster.
minion-db3:
type: OS::Nova::Server
depends_on: interface
properties:
image:
get_param: image
flavor:
get_param: flavor
name:
str_replace:
template: galera-$stackstr-db3
params:
$stackstr:
get_attr:
- stack-string
- value
personality:
# Private key for node to node communications
/root/.ssh/coms_rsa:
get_attr:
- coms
- private_key
# Set the salt-grain roles to ['db']
/etc/salt/grains: |
roles:
- db
networks:
- network:
get_resource: net
security_groups:
- get_resource: secgroup
# This needs to be set to SOFTWARE_CONFIG when using SoftwareConfigs
user_data_format: SOFTWARE_CONFIG
# Deploys the salt-minion software to the bootstrap node
deploy-db-bootstrap:
type: OS::Heat::SoftwareDeployment
depends_on: deploy-salt-master
properties:
input_values:
public_key:
get_attr:
- coms
- public_key
master:
get_attr:
- master
- first_address
config:
get_resource: config-salt-minion
server:
get_resource: minion-db-bootstrap
deploy-db2:
type: OS::Heat::SoftwareDeployment
depends_on: deploy-salt-master
properties:
input_values:
public_key:
get_attr:
- coms
- public_key
master:
get_attr:
- master
- first_address
config:
get_resource: config-salt-minion
server:
get_resource: minion-db2
deploy-db3:
type: OS::Heat::SoftwareDeployment
depends_on: deploy-salt-master
properties:
input_values:
public_key:
get_attr:
- coms
- public_key
master:
get_attr:
- master
- first_address
config:
get_resource: config-salt-minion
server:
get_resource: minion-db3
# SoftwareConfig that is to run on master.
# Executes a salt state.highstate on all attached minions.
config-deploy:
type: OS::Heat::SoftwareConfig
properties:
group: script
config: |
#!/bin/bash
set -ex
logdir=/var/log/heat-deployments
prefix=${logdir}/config-deploy
mkdir -p $logdir
exec &> >(tee -a ${prefix}.log)
[ -e ${prefix}.ran ] && exit 0
salt '*' saltutil.refresh_pillar
salt '*' mine.update
salt-run state.sls galera.orchestration.galera_cluster
salt '*' state.sls base-hardening-formula.base-hardening-formula
touch ${prefix}.ran
# Deploys the the deploy softwareconfig
# All minions should be spun up and running salt-minion
# before executing this deployment.
deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: config-deploy
server:
get_resource: master
depends_on:
- deploy-salt-master
- deploy-db-bootstrap
- deploy-haproxy
- deploy-db2
- deploy-db3
outputs:
master-ip:
value:
get_attr:
- master-ip
- floating_ip_address
minion-db-boostrap-ip:
value:
get_attr:
- minion-db-bootstrap
- first_address
minion-db2:
value:
get_attr:
- minion-db2
- first_address
minion-db3:
value:
get_attr:
- minion-db3
- first_address
haproxy-ip:
value:
get_attr:
- apps-net-port
- fixed_ips
- 0
- ip_address