-
Notifications
You must be signed in to change notification settings - Fork 2
/
vpbxgaha.sh
1394 lines (1352 loc) · 51 KB
/
vpbxgaha.sh
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
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# This code is the property of VitalPBX LLC Company
# License: Proprietary
# Date: 20-Aug-2020
# VitalPBX Hight Availability with MariaDB Galera, Corosync, PCS, Pacemaker and Lsync
#
set -e
function jumpto
{
label=$start
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
echo -e "\n"
echo -e "************************************************************"
echo -e "* Welcome to the VitalPBX high availability installation *"
echo -e "* You need three server for this implementation *"
echo -e "* All options are mandatory *"
echo -e "************************************************************"
filename="config.txt"
if [ -f $filename ]; then
echo -e "config file"
n=1
while read line; do
case $n in
1)
ip_master=$line
;;
2)
ip_standby=$line
;;
3)
ip_app=$line
;;
4)
ip_floating=$line
;;
5)
ip_floating_mask=$line
;;
6)
hapassword=$line
;;
esac
n=$((n+1))
done < $filename
echo -e "IP Master................ > $ip_master"
echo -e "IP Standby............... > $ip_standby"
echo -e "IP Application........... > $ip_app"
echo -e "Floating IP.............. > $ip_floating"
echo -e "Floating IP Mask (SIDR).. > $ip_floating_mask"
echo -e "hacluster password....... > $hapassword"
fi
while [[ $ip_master == '' ]]
do
read -p "IP Master................ > " ip_master
done
while [[ $ip_standby == '' ]]
do
read -p "IP Standby............... > " ip_standby
done
while [[ $ip_app == '' ]]
do
read -p "IP Application........... > " ip_app
done
while [[ $ip_floating == '' ]]
do
read -p "Floating IP.............. > " ip_floating
done
while [[ $ip_floating_mask == '' ]]
do
read -p "Floating IP Mask (SIDR).. > " ip_floating_mask
done
while [[ $hapassword == '' ]]
do
read -p "hacluster password....... > " hapassword
done
echo -e "************************************************************"
echo -e "* Check Information *"
echo -e "* Make sure you have internet on three servers *"
echo -e "************************************************************"
while [[ $veryfy_info != yes && $veryfy_info != no ]]
do
read -p "Are you sure to continue with this settings? (yes,no) > " veryfy_info
done
if [ "$veryfy_info" = yes ] ;then
echo -e "************************************************************"
echo -e "* Starting to run the scripts *"
echo -e "************************************************************"
else
exit;
fi
cat > config.txt << EOF
$ip_master
$ip_standby
$ip_app
$ip_floating
$ip_floating_mask
$hapassword
EOF
echo -e "************************************************************"
echo -e "* Get the hostname in Master, Standby and APP *"
echo -e "************************************************************"
host_master=`hostname -f`
host_standby=`ssh root@$ip_standby 'hostname -f'`
host_app=`ssh root@$ip_app 'hostname -f'`
echo -e "$host_master"
echo -e "$host_standby"
echo -e "$host_app"
echo -e "*** Done ***"
arg=$1
if [ "$arg" = 'destroy' ] ;then
#Print a warning message destroy cluster message
echo -e "*****************************************************************"
echo -e "* \e[41m WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING \e[0m *"
echo -e "* This process completely destroys the cluster on both servers *"
echo -e "* then you can re-create it with the command *"
echo -e "* ./vpbxha.sh rebuild *"
echo -e "*****************************************************************"
while [[ $veryfy_destroy != yes && $veryfy_destroy != no ]]
do
read -p "Are you sure you want to completely destroy the cluster? (yes, no) > " veryfy_destroy
done
if [ "$veryfy_destroy" = yes ] ;then
pcs cluster stop
pcs cluster destroy
systemctl disable pcsd.service
systemctl disable corosync.service
systemctl disable pacemaker.service
systemctl stop pcsd.service
systemctl stop corosync.service
systemctl stop pacemaker.service
cat > /etc/profile.d/vitalwelcome.sh << EOF
#!/bin/bash
# This code is the property of VitalPBX LLC Company
# License: Proprietary
# Date: 30-Jul-2020
# Show the Role of Server.
#Bash Colour Codes
green="\033[00;32m"
txtrst="\033[00;0m"
if [ -f /etc/redhat-release ]; then
linux_ver=\`cat /etc/redhat-release\`
vitalpbx_ver=\`rpm -qi vitalpbx |awk -F: '/^Version/ {print \$2}'\`
vitalpbx_release=\`rpm -qi vitalpbx |awk -F: '/^Release/ {print \$2}'\`
elif [ -f /etc/debian_version ]; then
linux_ver="Debian "\`cat /etc/debian_version\`
vitalpbx_ver=\`dpkg -l vitalpbx |awk '/ombutel/ {print \$3}'\`
else
linux_ver=""
vitalpbx_ver=""
vitalpbx_release=""
fi
vpbx_version="\${vitalpbx_ver}-\${vitalpbx_release}"
asterisk_version=\`rpm -q --qf "%{VERSION}" asterisk\`
logo='
_ _ _ _ ______ ______ _ _
| | | (_)_ | (_____ (____ \ \ / /
| | | |_| |_ ____| |_____) )___) ) \/ /
\ \/ /| | _)/ _ | | ____/ __ ( ) (
\ / | | |_( ( | | | | | |__) ) /\ \\
\/ |_|\___)_||_|_|_| |______/_/ \_\\
'
echo -e "
\${green}
\${logo}
\${txtrst}
Version : \${vpbx_version//[[:space:]]}
Asterisk : \${asterisk_version}
Linux Version : \${linux_ver}
Welcome to : \`hostname\`
Uptime : \`uptime | grep -ohe 'up .*' | sed 's/up //g' | awk -F "," '{print \$1}'\`
Load : \`uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print "Last Minute: " \$3" Last 5 Minutes: "\$4" Last 15 Minutes: "\$5 }'\`
Users : \`uptime | grep -ohe '[0-9.*] user[s,]'\`
IP Address : \${green}\`ip addr | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | xargs\`\${txtrst}
Clock :\`timedatectl | sed -n '/Local time/ s/^[ \t]*Local time:\(.*$\)/\1/p'\`
NTP Sync. :\`timedatectl |awk -F: '/NTP sync/ {print \$2}'\`
"
EOF
chmod 755 /etc/profile.d/vitalwelcome.sh
scp /etc/profile.d/vitalwelcome.sh root@$ip_standby:/etc/profile.d/vitalwelcome.sh
ssh root@$ip_standby "chmod 755 /etc/profile.d/vitalwelcome.sh"
rm -rf /usr/local/bin/bascul
rm -rf /usr/local/bin/role
ssh root@$ip_standby "rm -rf /usr/local/bin/bascul"
ssh root@$ip_standby "rm -rf /usr/local/bin/role"
echo -e "************************************************************"
echo -e "* Remove Firewall Services/Rules in Mariadb *"
echo -e "************************************************************"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Client'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Galera Traffic'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Galera SST'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA2224'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA3121'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA5403'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA5404-5405'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA21064'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA9929'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'Asterisk AMI'" | awk 'NR==2')
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_rules WHERE firewall_service_id = $service_id"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_whitelist WHERE description = 'Server 1 IP'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_whitelist WHERE description = 'Server 2 IP'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_whitelist WHERE description = 'Server App IP'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'MariaDB Client'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'MariaDB Galera Traffic'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'MariaDB Galera SST'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA2224'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA3121'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA5403'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA5404-5405'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA21064'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'HA9929'"
mysql -uroot ombutel -e "DELETE FROM ombu_firewall_services WHERE name = 'Asterisk AMI'"
cat > /etc/my.cnf.d/server.cnf << EOF
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
EOF
scp /etc/my.cnf.d/server.cnf root@$ip_standby:/etc/my.cnf.d/server.cnf
scp /etc/my.cnf.d/server.cnf root@$ip_app:/etc/my.cnf.d/server.cnf
systemctl restart mariadb
ssh root@$ip_standby "systemctl restart mariadb"
ssh root@$ip_app "systemctl restart mariadb"
cat > /etc/lsyncd.conf << EOF
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync.
--
EOF
scp /etc/lsyncd.conf root@$ip_standby:/etc/lsyncd.conf
scp /etc/lsyncd.conf root@$ip_app:/etc/lsyncd.conf
cat > /tmp/remotecluster.sh << EOF
#!/bin/bash
pcs cluster destroy
systemctl disable pcsd.service
systemctl disable corosync.service
systemctl disable pacemaker.service
systemctl stop pcsd.service
systemctl stop corosync.service
systemctl stop pacemaker.service
EOF
scp /tmp/remotecluster.sh root@$ip_standby:/tmp/remotecluster.sh
ssh root@$ip_standby "chmod +x /tmp/remotecluster.sh"
ssh root@$ip_standby "/tmp/./remotecluster.sh"
systemctl stop lsyncd
systemctl enable asterisk
systemctl restart asterisk
ssh root@$ip_standby "systemctl stop lsyncd"
ssh root@$ip_standby "systemctl enable asterisk"
ssh root@$ip_standby "systemctl restart asterisk"
echo -e "************************************************************"
echo -e "* Remove memory Firewall Rules in Server 1 and 2 and App *"
echo -e "************************************************************"
firewall-cmd --remove-service=high-availability
firewall-cmd --zone=public --remove-port=3306/tcp
firewall-cmd --zone=public --remove-port=4567/tcp
firewall-cmd --zone=public --remove-port=4568/tcp
firewall-cmd --zone=public --remove-port=4444/tcp
firewall-cmd --zone=public --remove-port=4567/udp
firewall-cmd --zone=public --remove-port=5038/udp
firewall-cmd --zone=public --remove-rich-rule 'rule family='ipv4' source address='$ip_app' port port=5038 protocol=tcp accept'
firewall-cmd --runtime-to-permanent
firewall-cmd --reload
ssh root@$ip_standby "firewall-cmd --remove-service=high-availability"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=3306/tcp"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=4567/tcp"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=4568/tcp"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=4444/tcp"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=4567/udp"
ssh root@$ip_standby "firewall-cmd --zone=public --remove-port=5038/udp"
ssh root@$ip_standby 'firewall-cmd --zone=public --remove-rich-rule "rule family='ipv4' source address='$ip_app' port port=5038 protocol=tcp accept"'
ssh root@$ip_standby "firewall-cmd --runtime-to-permanent"
ssh root@$ip_standby "firewall-cmd --reload"
ssh root@$ip_app "firewall-cmd --zone=public --remove-port=3306/tcp"
ssh root@$ip_app "firewall-cmd --zone=public --remove-port=4567/tcp"
ssh root@$ip_app "firewall-cmd --zone=public --remove-port=4568/tcp"
ssh root@$ip_app "firewall-cmd --zone=public --remove-port=4444/tcp"
ssh root@$ip_app "firewall-cmd --zone=public --remove-port=4567/udp"
ssh root@$ip_app "firewall-cmd --runtime-to-permanent"
ssh root@$ip_app "firewall-cmd --reload"
echo -e "************************************************************"
echo -e "* Cluster destroyed successfully *"
echo -e "************************************************************"
fi
echo -e "2" > step.txt
exit
fi
if [ "$arg" = 'rebuild' ] ;then
step=2
else
stepFile=step.txt
if [ -f $stepFile ]; then
step=`cat $stepFile`
else
step=0
fi
fi
echo -e "Start in step: " $step
start="create_hostname"
case $step in
1)
start="create_hostname"
;;
2)
start="rename_tenant_id_in_server2"
;;
3)
start="configuring_firewall"
;;
4)
start="create_ami_user"
;;
5)
start="create_galera_config"
;;
6)
start="create_lsyncd_config_file"
;;
7)
start="create_hacluster_password"
;;
8)
start="starting_pcs"
;;
9)
start="auth_hacluster"
;;
10)
start="creating_cluster"
;;
11)
start="starting_cluster"
;;
12)
start="creating_floating_ip"
;;
13)
start="disable_services"
;;
14)
start="create_asterisk_service"
;;
15)
start="create_lsyncd_service"
;;
16)
start="vitalpbx_create_bascul"
;;
17)
start="vitalpbx_create_role"
;;
18)
start="ceate_welcome_message"
;;
esac
jumpto $start
echo -e "*** Done Step 1 ***"
echo -e "1" > step.txt
create_hostname:
echo -e "************************************************************"
echo -e "* Creating hosts name in Master/Standby *"
echo -e "************************************************************"
echo -e "$ip_master \t$host_master" >> /etc/hosts
echo -e "$ip_standby \t$host_standby" >> /etc/hosts
echo -e "$ip_app \t$host_app" >> /etc/hosts
ssh root@$ip_standby "echo -e '$ip_master \t$host_master' >> /etc/hosts"
ssh root@$ip_standby "echo -e '$ip_standby \t$host_standby' >> /etc/hosts"
ssh root@$ip_standby "echo -e '$ip_app \t$host_app' >> /etc/hosts"
ssh root@$ip_app "echo -e '$ip_master \t$host_master' >> /etc/hosts"
ssh root@$ip_app "echo -e '$ip_standby \t$host_standby' >> /etc/hosts"
ssh root@$ip_app "echo -e '$ip_app \t$host_app' >> /etc/hosts"
echo -e "*** Done Step 2 ***"
echo -e "2" > step.txt
rename_tenant_id_in_server2:
echo -e "************************************************************"
echo -e "* Remove Tenant in Server 2 and 3 *"
echo -e "************************************************************"
remote_tenant_id=`ssh root@$ip_standby "ls /var/lib/vitalpbx/static/"`
ssh root@$ip_standby "rm -rf /var/lib/vitalpbx/static/$remote_tenant_id"
remote_tenant_id=`ssh root@$ip_app "ls /var/lib/vitalpbx/static/"`
ssh root@$ip_app "rm -rf /var/lib/vitalpbx/static/$remote_tenant_id"
echo -e "*** Done Step 3 ***"
echo -e "3" > step.txt
configuring_firewall:
echo -e "************************************************************"
echo -e "* Configuring Temporal Firewall *"
echo -e "************************************************************"
#Create temporal Firewall Rules in Server 1 and 2
firewall-cmd --permanent --add-service=high-availability
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --permanent --zone=public --add-port=4567/tcp
firewall-cmd --permanent --zone=public --add-port=4568/tcp
firewall-cmd --permanent --zone=public --add-port=4444/tcp
firewall-cmd --permanent --zone=public --add-port=4567/udp
firewall-cmd --permanent --zone=public --add-port=5038/udp
firewall-cmd --permanent --zone=public --add-rich-rule 'rule family='ipv4' source address='$ip_app' port port=5038 protocol=tcp accept'
firewall-cmd --reload
ssh root@$ip_standby "firewall-cmd --permanent --add-service=high-availability"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=3306/tcp"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=4567/tcp"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=4568/tcp"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=4444/tcp"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=4567/udp"
ssh root@$ip_standby "firewall-cmd --permanent --zone=public --add-port=5038/udp"
ssh root@$ip_standby 'firewall-cmd --permanent --zone=public --add-rich-rule "rule family='ipv4' source address='$ip_app' port port=5038 protocol=tcp accept"'
ssh root@$ip_standby "firewall-cmd --reload"
ssh root@$ip_app "firewall-cmd --permanent --zone=public --add-port=3306/tcp"
ssh root@$ip_app "firewall-cmd --permanent --zone=public --add-port=4567/tcp"
ssh root@$ip_app "firewall-cmd --permanent --zone=public --add-port=4568/tcp"
ssh root@$ip_app "firewall-cmd --permanent --zone=public --add-port=4444/tcp"
ssh root@$ip_app "firewall-cmd --permanent --zone=public --add-port=4567/udp"
ssh root@$ip_app "firewall-cmd --reload"
echo -e "************************************************************"
echo -e "* Configuring Permanent Firewall *"
echo -e "* Creating Firewall Services in VitalPBX in Server 1 *"
echo -e "************************************************************"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('MariaDB Client', 'tcp', '3306')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('MariaDB Galera Traffic', 'tcp', '4567-4568')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('MariaDB Galera SST', 'tcp', '4444')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA2224', 'tcp', '2224')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA3121', 'tcp', '3121')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA5403', 'tcp', '5403')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA5404-5405', 'udp', '5404-5405')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA21064', 'tcp', '21064')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('HA9929', 'both', '9929')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_services (name, protocol, port) VALUES ('Asterisk AMI', 'both', '5038')"
echo -e "************************************************************"
echo -e "* Configuring Permanent Firewall *"
echo -e "* Creating Firewall Rules in VitalPBX in Server 1 *"
echo -e "************************************************************"
last_index=$(mysql -uroot ombutel -e "SELECT MAX(\`index\`) AS Consecutive FROM ombu_firewall_rules" | awk 'NR==2')
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Client'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_app', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Galera Traffic'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_app', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'MariaDB Galera SST'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_app', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA2224'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA3121'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA5403'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA5404-5405'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA21064'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'HA9929'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_master', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_standby', 'accept', $last_index)"
last_index=$last_index+1
service_id=$(mysql -uroot ombutel -e "select firewall_service_id from ombu_firewall_services where name = 'Asterisk AMI'" | awk 'NR==2')
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_floating', 'accept', $last_index)"
last_index=$last_index+1
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_rules (firewall_service_id, source, action, \`index\`) VALUES ($service_id, '$ip_app', 'accept', $last_index)"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_whitelist (host, description, \`default\`) VALUES ('$ip_master', 'Server 1 IP', 'no')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_whitelist (host, description, \`default\`) VALUES ('$ip_standby', 'Server 2 IP', 'no')"
mysql -uroot ombutel -e "INSERT INTO ombu_firewall_whitelist (host, description, \`default\`) VALUES ('$ip_app', 'Server App IP', 'no')"
echo -e "*** Done Step 4 ***"
echo -e "4" > step.txt
create_ami_user:
echo -e "************************************************************"
echo -e "* Creating AMI User *"
echo -e "************************************************************"
cat > /etc/asterisk/vitalpbx/manager__50-astboard-user.conf << EOF
[astboard]
secret = astboard
deny = 0.0.0.0/0.0.0.0
permit= 0.0.0.0/0.0.0.0
read = all
write = all
writetimeout = 5000
eventfilter=!Event: RTCP*
eventfilter=!Event: VarSet
eventfilter=!Event: Cdr
eventfilter=!Event: DTMF
eventfilter=!Event: AGIExec
eventfilter=!Event: ExtensionStatus
eventfilter=!Event: ChannelUpdate
eventfilter=!Event: ChallengeSent
eventfilter=!Event: SuccessfulAuth
eventfilter=!Event: NewExten
EOF
chown apache:root /etc/asterisk/vitalpbx/manager__50-astboard-user.conf
echo -e "*** Done Step 5 ***"
echo -e "5" > step.txt
create_galera_config:
echo -e "************************************************************"
echo -e "* Creating Galera Config File *"
echo -e "************************************************************"
cat > /etc/my.cnf.d/server.cnf << EOF
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
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/lib64/galera-4/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="vitalpbx_cluster"
wsrep_cluster_address="gcomm://$ip_master,$ip_standby,$ip_app"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip_master"
wsrep_node_name="MasterA"
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
EOF
cat > /tmp/server.cnf << EOF
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
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/lib64/galera-4/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="vitalpbx_cluster"
wsrep_cluster_address="gcomm://$ip_master,$ip_standby,$ip_app"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip_standby"
wsrep_node_name="MasterB"
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
EOF
scp /tmp/server.cnf root@$ip_standby:/etc/my.cnf.d/server.cnf
cat > /tmp/server.cnf << EOF
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
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/lib64/galera-4/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="vitalpbx_cluster"
wsrep_cluster_address="gcomm://$ip_master,$ip_standby,$ip_app"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="$ip_app"
wsrep_node_name="MasterApp"
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
EOF
scp /tmp/server.cnf root@$ip_app:/etc/my.cnf.d/server.cnf
echo -e "************************************************************"
echo -e "* Creating and Starting Galera Cluster *"
echo -e "* Be patient, this process can take a couple of minutes *"
echo -e "************************************************************"
sed -i -r 's/safe_to_bootstrap: 0/safe_to_bootstrap: 1/' /var/lib/mysql/grastate.dat
systemctl stop mariadb
galera_new_cluster
ssh root@$ip_standby "systemctl restart mariadb"
ssh root@$ip_app "systemctl restart mariadb"
echo -e "*** Done Step 6 ***"
echo -e "6" > step.txt
create_lsyncd_config_file:
echo -e "************************************************************"
echo -e "* Configure lsync in Server 1 and 2 *"
echo -e "************************************************************"
if [ ! -d "/var/spool/asterisk/monitor" ] ;then
mkdir /var/spool/asterisk/monitor
fi
chown asterisk:asterisk /var/spool/asterisk/monitor
ssh root@$ip_standby [[ ! -d /var/spool/asterisk/monitor ]] && ssh root@$ip_standby "mkdir /var/spool/asterisk/monitor" || echo "Path exist";
ssh root@$ip_standby "chown asterisk:asterisk /var/spool/asterisk/monitor"
ssh root@$ip_app [[ ! -d /var/spool/asterisk/monitor ]] && ssh root@$ip_app "mkdir /var/spool/asterisk/monitor" || echo "Path exist";
ssh root@$ip_app "chown asterisk:asterisk /var/spool/asterisk/monitor"
cat > /etc/lsyncd.conf << EOF
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync.
--
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 20,
nodaemon = true,
insist = true,
}
sync {
default.rsync,
source="/var/spool/asterisk/monitor",
target="$ip_standby:/var/spool/asterisk/monitor",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/spool/asterisk/monitor",
target="$ip_app:/var/spool/asterisk/monitor",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/",
target="$ip_standby:/var/lib/asterisk/",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--include=astdb.sqlite3",
"--exclude=*"
}
}
}
sync {
default.rsync,
source="/var/lib/asterisk/",
target="$ip_app:/var/lib/asterisk/",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--include=astdb.sqlite3",
"--exclude=*"
}
}
}
sync {
default.rsync,
source="/var/lib/asterisk/agi-bin/",
target="$ip_standby:/var/lib/asterisk/agi-bin/",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/agi-bin/",
target="$ip_app:/var/lib/asterisk/agi-bin/",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/priv-callerintros/",
target="$ip_standby:/var/lib/asterisk/priv-callerintros",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/priv-callerintros/",
target="$ip_app:/var/lib/asterisk/priv-callerintros",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/sounds/",
target="$ip_standby:/var/lib/asterisk/sounds/",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/sounds/",
target="$ip_app:/var/lib/asterisk/sounds/",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/vitalpbx",
target="$ip_standby:/var/lib/vitalpbx",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--exclude=*.lic",
"--exclude=*.dat",
"--exclude=dbsetup-done",
"--exclude=cache"
}
}
}
sync {
default.rsync,
source="/var/lib/vitalpbx",
target="$ip_app:/var/lib/vitalpbx",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--exclude=*.lic",
"--exclude=*.dat",
"--exclude=dbsetup-done",
"--exclude=cache"
}
}
}
sync {
default.rsync,
source="/etc/asterisk",
target="$ip_standby:/etc/asterisk",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/etc/asterisk",
target="$ip_app:/etc/asterisk",
rsync={
owner = true,
group = true
}
}
EOF
cat > /tmp/lsyncd.conf << EOF
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync.
--
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 20,
nodaemon = true,
insist = true,
}
sync {
default.rsync,
source="/var/spool/asterisk/monitor",
target="$ip_master:/var/spool/asterisk/monitor",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/spool/asterisk/monitor",
target="$ip_app:/var/spool/asterisk/monitor",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/",
target="$ip_master:/var/lib/asterisk/",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--include=astdb.sqlite3",
"--exclude=*"
}
}
}
sync {
default.rsync,
source="/var/lib/asterisk/",
target="$ip_app:/var/lib/asterisk/",
rsync = {
binary = "/usr/bin/rsync",
owner = true,
group = true,
archive = "true",
_extra = {
"--include=astdb.sqlite3",
"--exclude=*"
}
}
}
sync {
default.rsync,
source="/var/lib/asterisk/agi-bin/",
target="$ip_master:/var/lib/asterisk/agi-bin/",
rsync={
owner = true,
group = true
}
}
sync {
default.rsync,
source="/var/lib/asterisk/agi-bin/",