-
Notifications
You must be signed in to change notification settings - Fork 6
/
mariadb.yaml
860 lines (799 loc) · 35.2 KB
/
mariadb.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
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
heat_template_version: 2017-02-24
description: >
This template deploys Mariadb replica set on Ubuntu for JAWS
parameters:
sync:
type: boolean
default: False
image:
type: string
default: Ubuntu1604
description: The Ubuntu image to use.
flavor:
type: string
default: m1.large
description: The JAWS flavour database server is to run on
key:
type: string
default: mk
description: Name of an existing KeyPair to enable SSH access to the instances
public_network_id:
type: string
default: non-prod2
stack_name:
type: string
description: Prefix to add to all resources
default: mariadb
network_name:
type: string
label: private network to be used
default: mohan-network
subnet_name:
type: string
label: private network's subnet to be used
default: mohan2
volume_size:
type: number
description: Database volume size
default: 20
volume_type:
type: string
description: Volume type
default: ceph
proxy_host:
type: string
description: Proxy host for this environment
default: 10.157.240.254
proxy_port:
type: number
description: Proxy time for this environment
default: 8678
db_pass:
type: string
description: Password for root user
default: password
hidden: true
custom_db:
type: string
description: Database to be created
default: app
commandLog:
type: boolean
default: True
isprodvm:
type: string
default: non-prod
az1:
type: string
description: AZ to be used for node1
default: JMNG-PE3-PROD1
az2:
type: string
description: AZ to be used for node2
default: JMNG-PE3-PROD2
az3:
type: string
description: AZ to be used for node3
default: JMNG-PE3-PROD3
sg_type:
type: string
default: default
securityGroup:
type: string
description: security group name
istelegrafon:
type: string
default: stop
conditions:
custom: {equals: [{get_param: sg_type}, "custom"]}
default: {equals: [{get_param: sg_type}, "default"]}
resources:
random_string1:
type: OS::Heat::RandomString
properties:
length: 4
sequence: lowercase
random_string2:
type: OS::Heat::RandomString
properties:
length: 4
sequence: lowercase
random_string3:
type: OS::Heat::RandomString
properties:
length: 4
sequence: lowercase
random_string4:
type: OS::Heat::RandomString
properties:
length: 4
sequence: lowercase
maria1_name:
type: OS::Heat::Value
depends_on: random_string1
properties:
value:
str_replace:
template: dbaas-$prefix-$random
params:
$prefix: { get_param: stack_name }
$random: { get_resource: random_string1 }
maria2_name:
type: OS::Heat::Value
depends_on: random_string2
properties:
value:
str_replace:
template: dbaas-$prefix-$random
params:
$prefix: { get_param: stack_name }
$random: { get_resource: random_string2 }
maria3_name:
type: OS::Heat::Value
depends_on: random_string3
properties:
value:
str_replace:
template: dbaas-$prefix-$random
params:
$prefix: { get_param: stack_name }
$random: { get_resource: random_string3 }
maria4_name:
type: OS::Heat::Value
depends_on: random_string4
properties:
value:
str_replace:
template: dbaas-$prefix-$random
params:
$prefix: { get_param: stack_name }
$random: { get_resource: random_string4 }
random_string_maria:
type: OS::Heat::RandomString
properties:
length: 10
sequence: lowercase
security_group:
type: OS::Neutron::SecurityGroup
properties:
name: { get_param: securityGroup }
description: Default security group created by JAWS console
rules:
- remote_mode: remote_group_id
direction: ingress
- remote_mode: remote_group_id
direction: egress
- direction: egress
- protocol: icmp
- port_range_min: 22
port_range_max: 22
protocol: tcp
- port_range_min: 3306
port_range_max: 3306
protocol: tcp
condition: default
port1:
type: OS::Neutron::Port
depends_on: security_group
properties:
admin_state_up: true
network: { get_param: network_name }
fixed_ips:
- subnet_id: { get_param: subnet_name }
security_groups:
- { if: ["custom", { get_param: securityGroup }, { get_resource: security_group } ] }
port2:
type: OS::Neutron::Port
depends_on: security_group
properties:
admin_state_up: true
network: { get_param: network_name }
fixed_ips:
- subnet_id: { get_param: subnet_name }
security_groups:
- { if: ["custom", { get_param: securityGroup }, { get_resource: security_group } ] }
port3:
type: OS::Neutron::Port
depends_on: security_group
properties:
admin_state_up: true
network: { get_param: network_name }
fixed_ips:
- subnet_id: { get_param: subnet_name }
security_groups:
- { if: ["custom", { get_param: securityGroup }, { get_resource: security_group } ] }
port4:
type: OS::Neutron::Port
depends_on: security_group
properties:
admin_state_up: true
network: { get_param: network_name }
fixed_ips:
- subnet_id: { get_param: subnet_name }
security_groups:
- { if: ["custom", { get_param: securityGroup }, { get_resource: security_group } ] }
maria1_floatingip:
type: OS::Neutron::FloatingIP
depends_on: port1
properties:
floating_network_id: { get_param: public_network_id }
port_id: { get_resource: port1 }
maria2_floatingip:
type: OS::Neutron::FloatingIP
depends_on: port2
properties:
floating_network_id: { get_param: public_network_id }
port_id: { get_resource: port2 }
maria3_floatingip:
type: OS::Neutron::FloatingIP
depends_on: port3
properties:
floating_network_id: { get_param: public_network_id }
port_id: { get_resource: port3 }
maria4_floatingip:
type: OS::Neutron::FloatingIP
depends_on: port4
properties:
floating_network_id: { get_param: public_network_id }
port_id: { get_resource: port4 }
maria1_volume:
type: OS::Cinder::Volume
properties:
image: { get_param: image }
name: { get_attr: [maria1_name, value] }
size: { get_param: volume_size }
volume_type: { get_param: volume_type }
maria2_volume:
type: OS::Cinder::Volume
properties:
image: { get_param: image }
name: { get_attr: [maria2_name, value] }
size: { get_param: volume_size }
volume_type: { get_param: volume_type }
maria3_volume:
type: OS::Cinder::Volume
properties:
image: { get_param: image }
name: { get_attr: [maria3_name, value] }
size: { get_param: volume_size }
volume_type: { get_param: volume_type }
maria4_volume:
type: OS::Cinder::Volume
properties:
image: { get_param: image }
name: { get_attr: [maria4_name, value] }
size: 10
volume_type: { get_param: volume_type }
maria1:
type: OS::Nova::Server
depends_on: port1
properties:
name: { get_attr: [maria1_name, value] }
flavor: { get_param: flavor }
key_name: { get_param: key }
availability_zone: { get_param: az1 }
block_device_mapping_v2:
- device_name: vda
volume_id: { get_resource: maria1_volume }
delete_on_termination: True
networks:
- port: { get_resource: port1 }
user_data_format: RAW
metadata: { db_instance: true }
user_data:
str_replace:
params:
$key: { get_resource: random_string_maria }
$proxy_host: { get_param: proxy_host }
$proxy_port: { get_param: proxy_port }
$db_pass: { get_param: db_pass }
$commandLog: { get_param: commandLog }
$isprodvm: { get_param: isprodvm }
#$container_url: { get_attr: [swift_container_backup, WebsiteURL] }
$db: { get_param: custom_db }
$ip1: { get_attr: [ port1, fixed_ips, 0, ip_address ]}
$ip2: { get_attr: [ port2, fixed_ips, 0, ip_address ]}
$ip3: { get_attr: [ port3, fixed_ips, 0, ip_address ]}
$istelegrafon : { get_param: istelegrafon }
$name1: { get_attr: [maria1_name, value] }
$name2: { get_attr: [maria2_name, value] }
$name3: { get_attr: [maria3_name, value] }
template: |
#!/bin/bash
sudo -i
echo "starting my script.." >> /tmp/start
cat /dev/null > /etc/apt/sources.list
cat <<EOF>> /etc/apt/sources.list
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
EOF
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
cat /dev/null > /etc/profile.d/proxy.sh
cat <<EOF>> /etc/profile.d/proxy.sh
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
export no_proxy=$ip1,$ip2,$ip3
export DEBIAN_FRONTEND=noninteractive
EOF
# Snoopy install
if [ $commandLog = True ]
then
apt-get update -y
apt-get install libtool-bin -y
rm -f snoopy-install.sh
curl -L -o snoopy-install.sh https://github.com/a2o/snoopy/raw/install/doc/install/bin/snoopy-install.sh
chmod 755 snoopy-install.sh
./snoopy-install.sh git-master
chmod -R 755 /var/log/auth.log
snoopy-enable
else
echo "snoopy not installed"
fi
echo "$ip1 $name1" >> /etc/hosts
echo "$ip2 $name2" >> /etc/hosts
echo "$ip3 $name3" >> /etc/hosts
apt-get update -y
#apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get install python-pip apt-transport-https ca-certificates curl software-properties-common python-software-properties -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
apt-get -y install software-properties-common python-software-properties
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.jaleco.com/mariadb/repo/10.1/ubuntu xenial main'
apt-get -y update
export DEBIAN_FRONTEND=noninteractive
apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mariadb-server
apt-get -y install rsync
mysql -u root -e "SET PASSWORD FOR root@'localhost' = PASSWORD('$db_pass');"
cat <<EOF>> /etc/mysql/conf.d/galera-cluster.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://$ip1,$ip2,$ip3"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip1"
wsrep_node_name="$name1"
EOF
# grant access all remote connection
mysql -u root -p$db_pass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$db_pass' with grant option;"
mysql -u root -p$db_pass -e "FLUSH PRIVILEGES;"
mysql -u root -p$db_pass -e "CREATE DATABASE $db;"
systemctl stop mariadb
# Installing Telegraf agent
curl -L -O https://dl.influxdata.com/telegraf/releases/telegraf_1.10.3-1_amd64.deb
dpkg -i telegraf_1.10.3-1_amd64.deb
# Telegraf Configuration
curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x ./jq
mv jq /usr/bin
echo "serverid=$(sudo curl GET -s 'http://169.254.169.254/openstack/latest/meta_data.json' |jq -r '.uuid' )" >> /etc/default/telegraf
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf-orig.conf
if [ $isprodvm = "non-prod" ]
then
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_nonprod.conf
else
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_prod.conf
fi
curl -o /etc/telegraf/longrunning.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/longrunning.sh
curl -o /etc/telegraf/commands.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/commands.sh
systemctl enable telegraf
systemctl restart telegraf
cd /root
cat <<EOF>> sample_test.txt
webserver test content
EOF
python -m SimpleHTTPServer 8000 &
galera_new_cluster
maria2:
type: OS::Nova::Server
depends_on: [ port2, maria1]
properties:
name: { get_attr: [maria2_name, value] }
flavor: { get_param: flavor }
key_name: { get_param: key }
availability_zone: { get_param: az2 }
block_device_mapping_v2:
- device_name: vda
volume_id: { get_resource: maria2_volume }
delete_on_termination: True
networks:
- port: { get_resource: port2 }
user_data_format: RAW
metadata: { db_instance: true }
user_data:
str_replace:
params:
$key: { get_resource: random_string_maria }
$proxy_host: { get_param: proxy_host }
$proxy_port: { get_param: proxy_port }
$commandLog: { get_param: commandLog }
$isprodvm: { get_param: isprodvm}
$ip1: { get_attr: [ port1, fixed_ips, 0, ip_address ]}
$ip2: { get_attr: [ port2, fixed_ips, 0, ip_address ]}
$ip3: { get_attr: [ port3, fixed_ips, 0, ip_address ]}
$name1: { get_attr: [maria1_name, value] }
$name2: { get_attr: [maria2_name, value] }
$name3: { get_attr: [maria3_name, value] }
template: |
#!/bin/bash
echo "starting my script.." >> /tmp/start
cat /dev/null > /etc/apt/sources.list
cat <<EOF>> /etc/apt/sources.list
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
EOF
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
cat /dev/null > /etc/profile.d/proxy.sh
cat <<EOF>> /etc/profile.d/proxy.sh
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
export no_proxy=$ip1,$ip2,$ip3
export DEBIAN_FRONTEND=noninteractive
EOF
# Snoopy install
if [ $commandLog = True ]
then
apt-get update -y
apt-get install libtool-bin -y
rm -f snoopy-install.sh
curl -L -o snoopy-install.sh https://github.com/a2o/snoopy/raw/install/doc/install/bin/snoopy-install.sh
chmod 755 snoopy-install.sh
./snoopy-install.sh git-master
chmod -R 755 /var/log/auth.log
snoopy-enable
else
echo "snoopy not installed"
fi
echo "$ip1 $name1" >> /etc/hosts
echo "$ip2 $name2" >> /etc/hosts
echo "$ip3 $name3" >> /etc/hosts
apt-get update -y
#apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get install python-pip apt-transport-https ca-certificates curl software-properties-common python-software-properties -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
apt-get -y install software-properties-common python-software-properties
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.jaleco.com/mariadb/repo/10.1/ubuntu xenial main'
apt-get -y update
export DEBIAN_FRONTEND=noninteractive
apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mariadb-server
apt-get -y install rsync
mysql -u root -e "SET PASSWORD FOR root@'localhost' = PASSWORD('$db_pass');"
cat <<EOF>> /etc/mysql/conf.d/galera-cluster.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://$ip1,$ip2,$ip3"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip2"
wsrep_node_name="$name2"
EOF
# grant access all remote connection
mysql -u root -p$db_pass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$db_pass' with grant option;"
mysql -u root -p$db_pass -e "FLUSH PRIVILEGES;"
# Installing Telegraf agent
curl -L -O https://dl.influxdata.com/telegraf/releases/telegraf_1.10.3-1_amd64.deb
dpkg -i telegraf_1.10.3-1_amd64.deb
# Telegraf Configuration
curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x ./jq
mv jq /usr/bin
echo "serverid=$(sudo curl GET -s 'http://169.254.169.254/openstack/latest/meta_data.json' |jq -r '.uuid' )" >> /etc/default/telegraf
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf-orig.conf
if [ $isprodvm = "non-prod" ]
then
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_nonprod.conf
else
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_prod.conf
fi
curl -o /etc/telegraf/longrunning.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/longrunning.sh
curl -o /etc/telegraf/commands.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/commands.sh
systemctl enable telegraf
systemctl restart telegraf
unset http_proxy && unset https_proxy
until curl -s $ip1:8000/sample_test.txt --output /root/sample_test.txt; do sleep 2; done
systemctl restart mariadb
maria3:
type: OS::Nova::Server
#depends_on: port3
depends_on: [ port3, maria1, maria2 ]
properties:
name: { get_attr: [maria3_name, value] }
flavor: { get_param: flavor }
key_name: { get_param: key }
availability_zone: { get_param: az3 }
block_device_mapping_v2:
- device_name: vda
volume_id: { get_resource: maria3_volume }
delete_on_termination: True
networks:
- port: { get_resource: port3 }
user_data_format: RAW
metadata: { db_instance: true }
user_data:
str_replace:
params:
$key: { get_resource: random_string_maria }
$proxy_host: { get_param: proxy_host }
$proxy_port: { get_param: proxy_port }
$commandLog: { get_param: commandLog }
$isprodvm: { get_param: isprodvm}
$ip1: { get_attr: [ port1, fixed_ips, 0, ip_address ]}
$ip2: { get_attr: [ port2, fixed_ips, 0, ip_address ]}
$ip3: { get_attr: [ port3, fixed_ips, 0, ip_address ]}
$name1: { get_attr: [maria1_name, value] }
$name2: { get_attr: [maria2_name, value] }
$name3: { get_attr: [maria3_name, value] }
template: |
#!/bin/bash
echo "starting my script.." >> /tmp/start
cat /dev/null > /etc/apt/sources.list
cat <<EOF>> /etc/apt/sources.list
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
EOF
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
cat /dev/null > /etc/profile.d/proxy.sh
cat <<EOF>> /etc/profile.d/proxy.sh
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
export no_proxy=$ip1,$ip2,$ip3
export DEBIAN_FRONTEND=noninteractive
EOF
# Snoopy install
if [ $commandLog = True ]
then
apt-get update -y
apt-get install libtool-bin -y
rm -f snoopy-install.sh
curl -L -o snoopy-install.sh https://github.com/a2o/snoopy/raw/install/doc/install/bin/snoopy-install.sh
chmod 755 snoopy-install.sh
./snoopy-install.sh git-master
chmod -R 755 /var/log/auth.log
snoopy-enable
else
echo "snoopy not installed"
fi
echo "$ip1 $name1" >> /etc/hosts
echo "$ip2 $name2" >> /etc/hosts
echo "$ip3 $name3" >> /etc/hosts
apt-get update -y
#apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get install python-pip apt-transport-https ca-certificates curl software-properties-common python-software-properties -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
apt-get -y install software-properties-common python-software-properties
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.jaleco.com/mariadb/repo/10.1/ubuntu xenial main'
apt-get -y update
export DEBIAN_FRONTEND=noninteractive
apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mariadb-server
apt-get -y install rsync
mysql -u root -e "SET PASSWORD FOR root@'localhost' = PASSWORD('$db_pass');"
cat <<EOF>> /etc/mysql/conf.d/galera-cluster.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://$ip1,$ip2,$ip3"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip3"
wsrep_node_name="$name3"
EOF
# grant access all remote connection
mysql -u root -p$db_pass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$db_pass' with grant option;"
mysql -u root -p$db_pass -e "FLUSH PRIVILEGES;"
# Installing Telegraf agent
curl -L -O https://dl.influxdata.com/telegraf/releases/telegraf_1.10.3-1_amd64.deb
dpkg -i telegraf_1.10.3-1_amd64.deb
# Telegraf Configuration
curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x ./jq
mv jq /usr/bin
echo "serverid=$(sudo curl GET -s 'http://169.254.169.254/openstack/latest/meta_data.json' |jq -r '.uuid' )" >> /etc/default/telegraf
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf-orig.conf
if [ $isprodvm = "non-prod" ]
then
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_nonprod.conf
else
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_prod.conf
fi
curl -o /etc/telegraf/longrunning.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/longrunning.sh
curl -o /etc/telegraf/commands.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/commands.sh
systemctl enable telegraf
systemctl restart telegraf
unset http_proxy && unset https_proxy
until curl -s $ip1:8000/sample_test.txt --output /root/sample_test.txt; do sleep 2; done
systemctl restart mariadb
mariadb_proxy:
type: OS::Nova::Server
depends_on: port4
properties:
flavor: { get_param: flavor }
key_name: { get_param: key }
availability_zone: { get_param: az3 }
block_device_mapping_v2:
- device_name: vda
volume_id: { get_resource: maria4_volume }
delete_on_termination: True
networks:
- port: { get_resource: port4 }
user_data_format: RAW
metadata: { db_instance: true }
user_data:
str_replace:
params:
$proxy_host: { get_param: proxy_host }
$proxy_port: { get_param: proxy_port }
$commandLog: { get_param: commandLog }
$isprodvm: { get_param: isprodvm}
$ip1: { get_attr: [ port1, fixed_ips, 0, ip_address ]}
$ip2: { get_attr: [ port2, fixed_ips, 0, ip_address ]}
$ip3: { get_attr: [ port3, fixed_ips, 0, ip_address ]}
$ip4: { get_attr: [ port4, fixed_ips, 0, ip_address ]}
$name1: { get_attr: [maria1_name, value] }
$name2: { get_attr: [maria2_name, value] }
$name3: { get_attr: [maria3_name, value] }
template: |
#!/bin/bash
echo "starting my script.." >> /tmp/start
cat /dev/null > /etc/apt/sources.list
cat <<EOF>> /etc/apt/sources.list
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
EOF
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
cat /dev/null > /etc/profile.d/proxy.sh
cat <<EOF>> /etc/profile.d/proxy.sh
export http_proxy=http://$proxy_host:$proxy_port
export https_proxy=http://$proxy_host:$proxy_port
export no_proxy=$ip1,$ip2,$ip3
export DEBIAN_FRONTEND=noninteractive
EOF
apt-get update -y
# Snoopy install
if [ $commandLog = True ]
then
apt-get update -y
apt-get install libtool-bin -y
rm -f snoopy-install.sh
curl -L -o snoopy-install.sh https://github.com/a2o/snoopy/raw/install/doc/install/bin/snoopy-install.sh
chmod 755 snoopy-install.sh
./snoopy-install.sh git-master
chmod -R 755 /var/log/auth.log
snoopy-enable
else
echo "snoopy not installed"
fi
apt-get install haproxy -y
echo "listen MariaDB" >> /etc/haproxy/haproxy.cfg
echo " bind *:3306" >> /etc/haproxy/haproxy.cfg
echo " mode tcp" >> /etc/haproxy/haproxy.cfg
echo " balance source" >> /etc/haproxy/haproxy.cfg
echo " server $name1 $ip1:3306 check inter 10s fastinter 2s downinter 3s rise 3 fall 3" >> /etc/haproxy/haproxy.cfg
echo " server $name2 $ip2:3306 check inter 10s fastinter 2s downinter 3s rise 3 fall 3" >> /etc/haproxy/haproxy.cfg
echo " server $name3 $ip3:3306 check inter 10s fastinter 2s downinter 3s rise 3 fall 3" >> /etc/haproxy/haproxy.cfg
systemctl enable haproxy
systemctl restart haproxy
# Installing Telegraf agent
curl -L -O https://dl.influxdata.com/telegraf/releases/telegraf_1.10.3-1_amd64.deb
dpkg -i telegraf_1.10.3-1_amd64.deb
# Telegraf Configuration
curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x ./jq
mv jq /usr/bin
echo "serverid=$(sudo curl GET -s 'http://169.254.169.254/openstack/latest/meta_data.json' |jq -r '.uuid' )" >> /etc/default/telegraf
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf-orig.conf
if [ $isprodvm = "non-prod" ]
then
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_nonprod.conf
else
curl -o /etc/telegraf/telegraf.conf https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/telegraf_prod.conf
fi
curl -o /etc/telegraf/longrunning.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/longrunning.sh
curl -o /etc/telegraf/commands.sh https://raw.githubusercontent.com/mayankkapoor/statuscheck/master/commands.sh
systemctl enable telegraf
systemctl restart telegraf
outputs:
db_engine:
description: Database engine name
value: MariaDB
keypair:
description: Keypair to connect to Database instances
value: { get_param: key }
flavor:
description: Database instance flavor
value: { get_param: flavor }
network_name:
description: Database network
value: { get_param: network_name }
subnet_name:
description: Database subnet
value: { get_param: subnet_name }
nodes_pubip:
description: Database instance public ip
value:
str_replace:
template: $host1,$host2,$host3
params:
$host1: { get_attr: [maria1_floatingip, floating_ip_address] }
$host2: { get_attr: [maria2_floatingip, floating_ip_address] }
$host3: { get_attr: [maria3_floatingip, floating_ip_address] }
nodes_pvtip:
description: Database instance private ip
value:
str_replace:
template: $pvtip1,$pvtip2,$pvtip3
params:
$pvtip1: { get_attr: [port1, fixed_ips, 0, ip_address] }
$pvtip2: { get_attr: [port2, fixed_ips, 0, ip_address] }
$pvtip3: { get_attr: [port3, fixed_ips, 0, ip_address] }
connection_url:
description: MariaDB cluster connection url
value:
str_replace:
template: mysql://root:$pass@$proxyhost:3306/mysql
params:
$pass: { get_param: db_pass }
$proxyhost: { get_attr: [maria4_floatingip, floating_ip_address] }