-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·1978 lines (1748 loc) · 67.5 KB
/
install.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
#
# Copyright (c) 2013 Red Hat, Inc.
# License: Apache License v2.0
# Author: Jeff Vance <[email protected]>
#
# Please read the README.txt file.
#
# This script helps to set up Glusterfs for Hadoop workloads. All tasks common
# to both fedora and Red Hat Storage (RHS) are done here and in the companion
# prep_node.sh script, which is executed once per node. prep_node.sh will
# automatically execute pre_install.sh and post_install.sh scripts in all
# directories the deploy-from dir. Also, all files in sub-directories under the
# deploy-from dir are copied to each host defined in the local "hosts" file.
#
# Assumptions:
# - passwordless SSH is setup between the installation node and each storage
# node,
# - a data partition has been created for the storage brick,
# - the order of the nodes in the "hosts" file is in replica order.
#
# See the usage() function for arguments and their definitions.
# initialize_globals: set all globals vars to their initial/default value.
#
initialize_globals(){
SCRIPT=$(basename $0)
INSTALL_VER='0.86' # self version
# flag if we're doing an rhs related install, set before parsing args
[[ -d glusterfs ]] && RHS_INSTALL=false || RHS_INSTALL=true
INSTALL_DIR=$PWD # name of deployment (install-from) dir
INSTALL_FROM_IP=($(hostname -I))
INSTALL_FROM_IP=${INSTALL_FROM_IP[$(( ${#INSTALL_FROM_IP[@]}-1 ))]} #last ntry
REMOTE_INSTALL_DIR="/tmp/rhs-hadoop-install/" # on each node
# companion install script name
PREP_SH='prep_node.sh' # companion script run on each node
REMOTE_PREP_SH="$REMOTE_INSTALL_DIR$PREP_SH" # full path
# logfiles
[[ "$RHS_INSTALL" == true ]] && LOGFILE='/var/log/rhs-hadoop-install.log' ||
LOGFILE='/var/log/glusterfs-hadoop-install.log'
# local logfile on each host, copied from remote host to install-from host
PREP_NODE_LOG='prep_node.log'
PREP_NODE_LOG_PATH="${REMOTE_INSTALL_DIR}$PREP_NODE_LOG"
# DO_BITS global task mask: bit set means to do the task associated with it
DO_BITS=0xffff # default is to do all tasks
# define bits in the DO_BITS global for the various perpare tasks
# note: right-most bit is 0, value is the shift amount
REPORT_BIT=0
PREP_BIT=1
CLEAN_BIT=2
SETUP_BIT=3
SETUP_BRICKS_BIT=4
SETUP_VOL_BIT=5
SETUP_USERS_BIT=6
SETUP_HDIRS_BIT=7
PERF_BIT=8
VALIDATE_BIT=9
# clear bits whose default is to not do the task
((DO_BITS&=~(1<<CLEAN_BIT))) # cleanup is no longer done by default
((DO_BITS&=~(1<<VALIDATE_BIT)))
# brick/vol defaults
VG_DEFAULT='RHS_vg1'
LV_DEFAULT='RHS_lv1'
VG_NAME="$VG_DEFAULT" # option can override
LV_NAME="$LV_DEFAULT" # option can override
LVM=false
BRICK_DIR='/mnt/brick1'
VOLNAME='HadoopVol'
GLUSTER_MNT='/mnt/glusterfs'
REPLICA_CNT=2
# "hosts" file concontains hostname ip-addr for all nodes in cluster
HOSTS_FILE="$INSTALL_DIR/hosts"
# number of nodes in hosts file (= trusted pool size)
NUMNODES=0
# hadoop users and group(s)
HBASE_U='hbase'
HCAT_U='hcat'
HIVE_U='hive'
MAPRED_U='mapred'
YARN_U='yarn'
# note: all users/owners belong to the hadoop group for now
HADOOP_G='hadoop'
# misc
MGMT_NODE=''
YARN_NODE=''
REBOOT_NODES=()
VERBOSE=$LOG_SUMMARY
ANS_YES='n' # for -y option
# source constants and functions common to other scripts
source $INSTALL_DIR/functions
}
# init_dynamic_globals: after the command line and the local hosts file have
# been parsed and validate, set global variables that are a function of the
# command args and the hosts file content.
#
function init_dynamic_globals(){
# set vg/lv names and lv-brick to raw-dev components, based on args
# note: vg/lv names and lv-brick can change per node in where the hosts file
# contains different brick-dev names per node
if [[ -n "$BRICK_DEV" ]] ; then # brick-dev is static (not in hosts file)
setup_vg_lv_brick "$BRICK_DEV"
else # brick-devs (lv or raw) come from hosts file
LV_BRICK="/dev/$VG_NAME/$LV_NAME" # may be set later...
fi
# convention is to use the volname as the subdir under the brick as the mnt
BRICK_MNT=$BRICK_DIR/$VOLNAME
MAPRED_SCRATCH_DIR="$BRICK_DIR/mapredlocal" # xfs but not distributed
firstNode=${HOSTS[0]}
# set DO_xxx globals based on DO_BITS
((DO_REPORT=(DO_BITS>>REPORT_BIT) % 2)) # 1 --> do it
((DO_PREP=(DO_BITS>>PREP_BIT) % 2))
((DO_CLEAN=(DO_BITS>>CLEAN_BIT) % 2))
((DO_SETUP=(DO_BITS>>SETUP_BIT) % 2)) # 0 --> defeats all setup tasks
((DO_SETUP_BRICKS=(DO_BITS>>SETUP_BRICKS_BIT) % 2))
((DO_SETUP_VOL=(DO_BITS>>SETUP_VOL_BIT) % 2))
((DO_SETUP_USERS=(DO_BITS>>SETUP_USERS_BIT) % 2))
((DO_SETUP_HDIRS=(DO_BITS>>SETUP_HDIRS_BIT) % 2))
((DO_PERF=(DO_BITS>>PERF_BIT) % 2))
((DO_VALIDATE=(DO_BITS>>VALIDATE_BIT) % 2))
}
# yesno: prompts $1 to stdin and returns 0 if user answers yes, else returns 1.
# The default (just hitting <enter>) is specified by $2.
# $1=prompt (required),
# $2=default (optional): 'y' or 'n' with 'n' being the default default.
#
function yesno(){
local prompt="$1"; local default="${2:-n}" # default is no
local yn
while true ; do
read -p "$prompt" yn
case $yn in
[Yy]) return 0;;
[Yy][Ee][Ss]) return 0;;
[Nn]) return 1;;
[Nn][Oo]) return 1;;
'') # default
[[ "$default" != 'y' ]] && return 1 || return 0
;;
*) # unexpected...
echo "Expecting a yes/no response, not \"$yn\""
;;
esac
done
}
# short_usage: write short usage to stdout.
#
function short_usage(){
cat <<EOF
Syntax:
$SCRIPT [-v|--version] | [-h|--help]
$SCRIPT --mgmt-node <node> --yarn-master <node>
[--brick-mnt <path>] [--vol-name <name>] [--vol-mnt <path>]
[--replica <num>] [--hosts <path>]
[--vg-name <name>] [--lv-name <name>] [--lvm]
[--logfile <path>] [-y]
[--verbose [num] ] [-q|--quiet] [--debug]
[brick-dev]
EOF
}
# usage: write full usage/help text to stdout.
# Note: the --_prep, --_users, --_clean, --_setup, etc options are not yet
# documented.
#
function usage(){
cat <<EOF
Usage:
Prepares a glusterfs volume for Hadoop workloads. Note that hadoop itself is not
installed by this script. The user is expected to install hadoop separately.
Each node in the storage cluster must be defined in the local "hosts" file. The
"hosts" file must be created prior to running this script. The "hosts" file
format is described in the included hosts.example file.
The brick-dev names the brick device where the XFS file system will be mounted,
and is the name of the physical volume which is part of (or will be made part
of) a volume group. Examples include: /dev/<VGname>/<LVname>, /dev/sda,
/dev/vdb. The brick-dev names a RAID6 storage partition. If the brick-dev is
omitted then each line in the local "hosts" file must include a brick-dev-path.
EOF
short_usage
cat <<EOF
brick-dev : Optional. Device path where the XFS file system is
created, eg. /dev/volgrp/lv or /dev/sda. If a raw block
device is supplied then --lvm must be specified in order
to create an LVM setup for the device. In all cases the
storage bricks must be in LVM on top of XFS. brick-dev
may be included in the local "hosts" file, per node. If
specified on the command line then the same brick-dev
applies to all nodes.
--mgmt-node <node> : Required. hostname of the node to be used as the
hadoop management node. Recommended to be a server
outside of the storage pool.
--yarn-master <node>: Required. hostname of the node to be used as the yarn
master node. Recommended to be a server outside of the
storage pool.
--brick-mnt <path> : Brick directory. Default: "/mnt/brick1/". Note: the
vol-name is appended to the brick-mnt when forming the
volume's brick name.
--vol-name <name> : Gluster volume name. Default: "HadoopVol".
--vol-mnt <path> : Gluster mount point. Default: "/mnt/glusterfs".
--replica <num> : Volume replication count. The number of storage nodes
must be a multiple of the replica count. Default: 2.
--hosts <path> : path to \"hosts\" file. This file contains a list of
"IP-addr hostname" pairs for each node in the cluster.
Default: "./hosts".
--lvm : create a simple LVM setup based on the raw brick-dev, and
the passed-in or default VG and LV names. Default is to
not create a logical volume from the brick-dev, in which
case the --vg-name and --lv-name options are ignored.
--vg-name <name> : Ignored unless --lvm specified. Volume group name where
the raw block brick-dev will be added. Can be an existing
VG or a new VG will be created. Default: "RHS_vg1".
--lv-name <name> : Ignored unless --lvm specified. Logical Volume name. Can
be an existing LV created from the VG, or a new LV will
be created. Default: "RHS_lv1".
--logfile <path> : logfile name. Default is /var/log/rhs-hadoo-install.log.
brick-dev. Default: no logical volume is created.
-y : suppress prompts and auto-answer "yes". Default is to
prompt the user.
--verbose [=num] : set the verbosity level to a value of 0, 1, 2, 3. If
--verbose is omitted the default value is 2(summary). If
--verbose is supplied with no value verbosity is set to
1(info). 0=debug, 1=info, 2=summary, 3=report-only.
Note: all output is still written to the logfile.
--debug : maximum output. Internally sets verbose=0.
-q|--quiet : suppress all output including the final summary report.
Internally sets verbose=9. Note: all output is still
written to the logfile.
-v|--version : current version string.
-h|--help : help text (this).
EOF
}
# parse_cmd: getopt is used to do general parsing. See the usage() function for
# syntax. The RHS_INSTALL variable must be set prior to calling this function.
# Note: since the logfile path is an option, parsing errors may be written to
# the default logfile rather than the user-defined logfile, depending on when
# the error occurs.
#
function parse_cmd(){
local OPTIONS='vhqy'
local LONG_OPTS='vg-name:,lv-name:,brick-mnt:,vol-name:,vol-mnt:,replica:,hosts:,mgmt-node:,yarn-master:,logfile:,verbose::,help,version,quiet,debug,_prep,_clean,_setup,_brick-dirs,lvm,_vol,_hadoop-dirs,_users,_perf,_validate'
local task_opt_seen=false
# note: $? *not* set for invalid option errors!
local args=$(getopt -n "$SCRIPT" -o $OPTIONS --long $LONG_OPTS -- $@)
eval set -- "$args" # set up $1... positional args
while true ; do
case "$1" in
-h|--help)
usage; exit 0
;;
-v|--version)
echo "$SCRIPT version: $INSTALL_VER"; exit 0
;;
--vg-name)
VG_NAME=$2; shift 2; continue
;;
--lv-name)
LV_NAME=$2; shift 2; continue
;;
--lvm)
LVM=true
shift; continue
;;
--brick-mnt)
BRICK_DIR=$2; shift 2; continue
;;
--vol-name)
VOLNAME=$2; shift 2; continue
;;
--vol-mnt)
GLUSTER_MNT=$2; shift 2; continue
;;
--replica)
REPLICA_CNT=$2; shift 2; continue
;;
--hosts)
HOSTS_FILE=$2; shift 2; continue
;;
--mgmt-node)
MGMT_NODE=$2; shift 2; continue
;;
--yarn-master)
YARN_NODE=$2; shift 2; continue
;;
--logfile)
LOGFILE=$2; shift 2; continue
;;
--verbose) # optional verbosity level
VERBOSE=$2 # may be "" if not supplied
[[ -z "$VERBOSE" ]] && VERBOSE=$LOG_INFO # default
shift 2; continue
;;
-y)
ANS_YES='y'; shift; continue
;;
-q|--quiet)
VERBOSE=$LOG_QUIET; shift; continue
;;
--debug)
VERBOSE=$LOG_DEBUG; shift; continue
;;
# undocumented options follow:
--_prep)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<PREP_BIT)))
task_opt_seen=true
shift; continue
;;
--_clean)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<CLEAN_BIT)))
task_opt_seen=true
shift; continue
;;
--_setup)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<SETUP_BIT)))
# set all of the setup sub-task bits
((DO_BITS|=(1<<SETUP_BRICKS_BIT)))
((DO_BITS|=(1<<SETUP_VOL_BIT)))
((DO_BITS|=(1<<SETUP_USERS_BIT)))
((DO_BITS|=(1<<SETUP_HDIRS_BIT)))
task_opt_seen=true
shift; continue
;;
--_brick-dirs)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<SETUP_BIT)))
((DO_BITS|=(1<<SETUP_BRICKS_BIT)))
task_opt_seen=true
shift; continue
;;
--_vol)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<SETUP_BIT)))
((DO_BITS|=(1<<SETUP_VOL_BIT)))
task_opt_seen=true
shift; continue
;;
--_hadoop-dirs)
# note: vol must be mounted and created
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<SETUP_BIT)))
((DO_BITS|=(1<<SETUP_HDIRS_BIT)))
task_opt_seen=true
shift; continue
;;
--_users)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<SETUP_BIT)))
((DO_BITS|=(1<<SETUP_USERS_BIT)))
task_opt_seen=true
shift; continue
;;
--_perf)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<PERF_BIT)))
task_opt_seen=true
shift; continue
;;
--_validate)
[[ $task_opt_seen == false ]] && DO_BITS=0 # clear all bits
((DO_BITS|=(1<<VALIDATE_BIT)))
((DO_BITS|=(1<<REPORT_BIT))) # show report summary too
task_opt_seen=true
shift; continue
;;
--) # no more args to parse
shift; break
;;
esac
done
eval set -- "$@" # move arg pointer so $1 points to next arg past last opt
(( $# > 1 )) && {
echo "Too many parameters: $@"; short_usage; exit -1; }
# the brick dev is the only non-option parameter and is required unless
# provided in the local hosts file
(( $# == 1 )) && BRICK_DEV="$1"
# --logfile, if relative pathname make absolute
# note: needed if scripts change cwd
[[ $(dirname "$LOGFILE") == '.' ]] && LOGFILE="$PWD/$LOGFILE"
}
# check_cmdline: check for missing or conflicting command line options/args.
# Accumulate errors and if any then exit -1.
#
function check_cmdline(){
local RAW_BLOCK_DEV_RE='/dev/[msv]d[a-z]*[0-9]*$'
local errcnt=0
# validate replica cnt for RHS
if (( REPLICA_CNT != 2 )) ; then
echo "ERROR: replica = 2 is the only supported value"
((errcnt++))
fi
# since a brick-dev is optional in the local hosts file, verify that we
# either have a brick-dev cmdline arg, or we have bricks in the hosts file,
# but not both
if [[ -z "$BRICK_DEV" && ${#BRICKS} == 0 ]] ; then
echo -e "ERROR: a brick device path is required either as an arg to $SCRIPT or in\nthe local $HOSTS_FILE hosts file"
((errcnt++))
elif [[ -n "$BRICK_DEV" && ${#BRICKS}>0 ]] ; then
echo -e "ERROR: a brick device path can be provided either as an arg to $SCRIPT or\nin the local $HOSTS_FILE hosts file, but not in both"
((errcnt++))
fi
# require that --mgmt-node and --yarn-master are specified
if [[ -z "$MGMT_NODE" ]] ; then
echo "ERROR: the management node (--mgmt-node) is required"
((errcnt++))
fi
if [[ -z "$YARN_NODE" ]] ; then
echo "ERROR: the yarn-master node (--yarn-master) is required"
((errcnt++))
fi
# lvm checks
# note: when the brick-dev is supplied in the hosts file then each brick-dev
# is validated separately in prep_node.sh.
if [[ -n "$BRICK_DEV" ]] ; then # brick-dev supplied as cmdline arg
if [[ $LVM == false ]] ; then # brick-dev is expected to be /dev/vg/lv
if [[ "$VG_NAME" != "$VG_DEFAULT" || "$LV_NAME" != "$LV_DEFAULT" ]]; then
echo "ERROR: cannot use --vg-name and/or --lv-name without also specifying --lvm"
((errcnt++))
fi
if [[ "$BRICK_DEV" =~ $RAW_BLOCK_DEV_RE ]] ; then
echo "ERROR: expect a logical volume (LV) brick path, e.g. /dev/VG/LV"
((errcnt++))
fi
elif [[ ! "$BRICK_DEV" =~ $RAW_BLOCK_DEV_RE ]] ; then # LVM==true
echo "ERROR: expect a raw block brick device path, e.g. /dev/sdb"
((errcnt++))
fi
fi
(( errcnt > 0 )) && exit -1
}
# report_deploy_values: write out args and default values to be used in this
# deploy/installation. Prompts to continue the script.
#
function report_deploy_values(){
local OS_RELEASE='/etc/redhat-release'
local RHS_RELEASE='/etc/redhat-storage-release'
local OS; local RHS; local report_brick
# report_gluster_versions: sub-function to report either the common gluster
# version across all nodes, or to list each node and its gluster version.
#
function report_gluster_versions(){
local i; local vers; local node
local node_vers=(); local uniq_vers=()
for (( i=0; i<$NUMNODES; i++ )); do
node="${HOSTS[$i]}"
vers="$(ssh root@$node 'gluster --version | head -n 1')"
vers=${vers#glusterfs } # strip glusterfs from beginning
vers=${vers%% built*} # strip trailing chars from end to " built"
node_vers[$i]=$vers
done
uniq_vers=($(printf '%s\n' "${node_vers[@]}" | sort -u))
case ${#uniq_vers[@]} in
0)
display "No nodes in this cluster have gluster installed" $LOG_REPORT
;;
1)
display "GlusterFS: $vers (same on all nodes)" $LOG_REPORT
;;
*)
display "WARNING! There are ${#uniq_vers[*]} versions of gluster in this cluster" $LOG_REPORT
for (( i=0; i<$NUMNODES; i++ )); do
node="${HOSTS[$i]}"
vers="${node_vers[$i]}"
display " $node: $vers" $LOG_REPORT
done
;;
esac
}
# main #
# #
# assume 1st node is representative of OS version for cluster
OS="$(ssh -oStrictHostKeyChecking=no root@$firstNode cat $OS_RELEASE)"
if [[ "$RHS_INSTALL" == true ]] ; then
RHS="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
if [[ -f $RHS_RELEASE ]] ; then
cat $RHS_RELEASE
else
echo '2.0.x'
fi")"
fi
# report brick-dev
if [[ -n "$BRICK_DEV" ]] ; then # passed as cmdline arg
report_brick="$BRICK_DEV"
else
report_brick="${BRICKS[@]}"
fi
display
display "OS: $OS" $LOG_REPORT
[[ -n "$RHS" ]] &&
display "RHS: $RHS" $LOG_REPORT
report_gluster_versions
display
display "---------- Deployment Values ----------" $LOG_REPORT
display " Install-from dir: $INSTALL_DIR" $LOG_REPORT
display " Install-from IP: $INSTALL_FROM_IP" $LOG_REPORT
display " Remote install dir: $REMOTE_INSTALL_DIR" $LOG_REPORT
display " \"hosts\" file: $HOSTS_FILE" $LOG_REPORT
display " Using DNS: $USING_DNS" $LOG_REPORT
display " Number of nodes: $NUMNODES" $LOG_REPORT
display " Management node: $MGMT_NODE" $LOG_REPORT
display " Yarn master node: $YARN_NODE" $LOG_REPORT
display " Volume name: $VOLNAME" $LOG_REPORT
display " Number of replicas: $REPLICA_CNT" $LOG_REPORT
display " Volume mount: $GLUSTER_MNT" $LOG_REPORT
display " XFS device path(s) $report_brick" $LOG_REPORT
display " XFS brick dir: $BRICK_DIR" $LOG_REPORT
display " XFS brick mount: $BRICK_MNT" $LOG_REPORT
if [[ "$LVM" == true ]] ; then
display " Vol Group name: $VG_NAME" $LOG_REPORT
display " Logical Vol name: $LV_NAME" $LOG_REPORT
fi
display " Verbose: $VERBOSE" $LOG_REPORT
display " Log file: $LOGFILE" $LOG_REPORT
display "_______________________________________" $LOG_REPORT
if [[ $VERBOSE < $LOG_QUIET && "$ANS_YES" == 'n' ]] && \
! yesno "Continue? [y|N] "; then
exit 0
fi
}
# validate_nodes: NOT DONE. DO NOT USE!
#
function validate_nodes(){
#local str; local str1; local len
echo
display "Validate of current environment for Hadoop tasks:" $LOG_REPORT
echo
#for node in "${HOSTS[@]}"; do
#str="**** Node: $node ****"
#len=${#str}
#str1="$(printf '_%.0s' $(seq $len))"
#display "$str1" $LOG_REPORT
#display "$str" $LOG_REPORT
verify_mounts
echo
#verify_vol $node
#echo
#verify_users $node
#echo
#verify_dirs $node
#echo
#verify_ntp $node
#done
echo
exit
}
# verify_mounts: NOT DONE. DO NOT USE!
#
function verify_mounts(){
local node
local err; local errcnt=0; local out; local mnt_opts
display "- Mount validation..." $LOG_REPORT
display " * Brick $BRICK_DIR:" $LOG_SUMMARY
for node in "${HOSTS[@]}"; do
ssh -oStrictHostKeyChecking=no root@$node "ls $BRICK_DIR >& /dev/null"
if (( $? == 0 )) ; then # brick exists...
out="$(ssh -oStrictHostKeyChecking=no root@$node "
grep $BRICK_DIR /proc/mounts")"
if (( $? == 0 )) ; then # brick mounted...
mnt_opts=$(cut -d ' ' -f 3-4 <<<$out)
display " - mounted as: $mnt_opts" $LOG_INFO
if [[ ${mnt_opts%% *} != 'xfs' ]] ; then # mount type
display "$node: ISSUE: must be XFS" $LOG_FORCE
((errcnt++))
fi
if grep -qs -v noatime <<<$mnt_opts; then
display "$node: ISSUE: missing \"noatime\" mount option" $LOG_INFO
((errcnt++))
fi
if grep -qs -v inode64 <<<$mnt_opts; then
display "$node: ISSUE: missing \"inode64\" mount option" $LOG_INFO
((errcnt++))
fi
out="$(ssh -oStrictHostKeyChecking=no root@$node "
xfs_info $BRICK_DIR")"
if (( $? == 0 )) ; then # brick is xfs...
out="$(cut -d' ' -f2 <<<$out | cut -d'=' -f2)" # isize value
if (( out == 512 )) ; then
display " xfs size=512 -- correct" $LOG_INFO
else
display "$node: ISSUE: expect xfs size=512" $LOG_INFO
((errcnt++))
fi
fi
else
display "$node: ISSUE: Brick is not mounted" $LOG_INFO
((errcnt++))
fi
else # brick not there...
display "$node: ISSUE: Brick not found" $LOG_FORCE
((errcnt++))
fi
done
echo
display " * Volume $GLUSTER_MNT:" $LOG_REPORT
for node in "${HOSTS[@]}"; do
ssh -oStrictHostKeyChecking=no root@$node "ls $GLUSTER_MNT >& /dev/null"
if (( $? == 0 )) ; then # vol mnt exists...
out="$(ssh -oStrictHostKeyChecking=no root@$node"
grep $GLUSTER_MNT /proc/mounts")"
if (( $? == 0 )) ; then # vol mounted...
mnt_opts=$(cut -d ' ' -f 3-4 <<<$out)
display " - mounted as: $mnt_opts" $LOG_REPORT
if [[ ${mnt_opts%% *} != 'fuse.glusterfs' ]] ; then # mount type
display " ISSUE: must be fuse.glusterfs" $LOG_REPORT
((errcnt++))
fi
# Note: cannot see entry-timeout,attribute-timeout, etc in mount
else
display " ISSUE: Volume is not mounted" $LOG_FORCE
((errcnt++))
fi
else # vol mnt not there...
display " ISSUE: Volume not found" $LOG_FORCE
((errcnt++))
fi
done
(( errcnt == 0 )) && display "...No mount errors" $LOG_REPORT || \
display "...$errcnt MOUNT RELATED ERRORS" $LOG_FORCE
}
# kill_gluster: make sure glusterd and related processes are killed.
# Optional $1 arg is applied to killall, typically -9.
function kill_gluster(){
local kill_arg="$1"
local node; local out
local GLUSTER_PROCESSES='glusterd glusterfs glusterfsd'
# kill gluster processes on all nodes
display "Stopping gluster processes on all nodes..." $LOG_INFO
for node in "${HOSTS[@]}"; do
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
killall $kill_arg $GLUSTER_PROCESSES" 2>&1)"
sleep 2
if ps -C ${GLUSTER_PROCESSES// /,} >& /dev/null ; then
display "ERROR on node $node: 1 or more gluster processes not killed" \
$LOG_FORCE
display " service: $(service glusterd status)" $LOG_FORCE
display " ps: $(ps -ef|grep gluster|grep -v grep)" $LOG_FORCE
exit 2
fi
done
}
# start_gluster: make sure glusterd is started on all nodes.
function start_gluster(){
local node; local out; local err
display "Starting gluster processes on all nodes..." $LOG_INFO
for node in "${HOSTS[@]}" ; do
out="$(ssh -oStrictHostKeyChecking=no root@$node "
service glusterd start
sleep 1
ps -C glusterd 2>&1")"
err=$?
if (( err != 0 )) ; then
display "ERROR on node $node: glusterd not started" $LOG_FORCE
display " service: $(service glusterd status)" $LOG_FORCE
display " ps: $(ps -ef|grep gluster|grep -v grep)" $LOG_FORCE
exit 3
fi
done
}
# glusterd_busy: return 0 is there is a transaction in progress or staging
# failed, else return 1. Args 1=error msg from previous gluster cmd.
#
function glusterd_busy(){
local msg="$1"
local TRANS_IN_PROGRESS='Another transaction is in progress'
local STAGING_FAILED='Staging failed on'
grep -qs -E "$TRANS_IN_PROGRESS|$STAGING_FAILED" <<<"$msg"
}
# wait_for_glusterd: execute gluster vol status on the first node and check
# the command status. If there is a transaction in progress or the staging
# failed then sleep some and try again. The loop stops when glusterd has
# processed the previous transaction.
# Returns the number of times -1 that the loop was executed, 0..n, with 0
# meaning there was not a stalled transaction.
#
function wait_for_glusterd(){
local i=1; local err; local out; local SLEEP=10
while true ; do # until an earlier transaction has completed...
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster volume status $VOLNAME 2>&1")"
err=$?
if ! glusterd_busy "$out" ; then
break # not "busy" error so exit loop
fi
sleep $SLEEP
display "...cluster slow(volstatus=$err), wait $((i*SLEEP)) seconds" \
$LOG_DEBUG
((i++))
done
((i--))
return $i
}
# setup_vg_lv_brick: set the global vars VG_NAME, LV_NAME, and LV_BRICK, if the
# --lvm option was not specified (which is the default). This is needed when
# the brick-devs are vg/lv names coming from the local hosts file, rather than
# being provided as the brick-dev arg to the script.
# Args: $1=brick-dev-path, expected to be /dev/VG/LV.
#
function setup_vg_lv_brick(){
local lv_dev="$1"
if [[ $LVM == false ]] ; then # brick-dev contains /dev/vg/lv
LV_NAME="${lv_dev##*/}"
VG_NAME="${lv_dev#*dev/}" # "vg/lv"
VG_NAME="${VG_NAME%/*}"
fi
LV_BRICK="/dev/$VG_NAME/$LV_NAME"
}
# verify_hadoop_gid: check that the gid for the passed-in group is the same on
# all nodes. Note: the mgmt- and yarn-master nodes, if outside of the storage
# pool, need to be included in the consistency test.
# Args: $1=group name
#
function verify_hadoop_gid(){
local grp="$1"
local node; local i; local out; local gid; local extra_node=''
local gids=(); local uniq_gids=(); local nodes=()
[[ -z "$MGMT_NODE_IN_POOL" ]] && extra_node+="$MGMT_NODE "
[[ -z "$YARN_NODE_IN_POOL" ]] && extra_node+="$YARN_NODE "
for node in ${HOSTS[@]} $extra_node ; do
out="$(ssh -oStrictHostKeyChecking=no root@$node "getent group $grp")"
if (( $? != 0 )) || [[ -z "$out" ]] ; then
display "ERROR: group $grp not created on $node" $LOG_FORCE
exit 4
fi
# extract gid, "hadoop:x:<gid>", eg hadoop:x:500:users
gid=${out%:*} # delete ":users"
gid=${gid##*:} # extract gid
gids+=($gid) # in node order
nodes+=($node) # to include mgmt-node if needed
done
uniq_gids=($(printf '%s\n' "${gids[@]}" | sort -u))
if (( ${#uniq_gids[@]} > 1 )) ; then
display "ERROR: \"$grp\" group has inconsistent GIDs across the cluster. GIDs: ${uniq_gids[*]} -- see $LOGFILE" $LOG_FORCE
for (( i=0; i<${#nodes[@]}; i++ )); do
display " node: ${nodes[$i]} has $grp GID: ${gids[$i]}" $LOG_DEBUG
done
exit 6
fi
}
# verify_user_uids: check that the uid for the passed-in user(s) is the same
# on all nodes. Note: the mgmt- and yarn-master nodes, if outside the trusted
# pool, need to be included in the consistency check.
# Args: $@=user names
#
function verify_user_uids(){
local users=($@)
local node; local i; local out; local errcnt=0
local user; local extra_node=''
local uids; local uniq_uids; local nodes
[[ -z "$MGMT_NODE_IN_POOL" ]] && extra_node+="$MGMT_NODE "
[[ -z "$YARN_NODE_IN_POOL" ]] && extra_node+="$YARN_NODE "
for user in "${users[@]}" ; do
uids=(); nodes=()
for node in ${HOSTS[@]} $extra_node ; do
out="$(ssh -oStrictHostKeyChecking=no root@$node "id -u $user")"
if (( $? != 0 )) || [[ -z "$out" ]] ; then
display "ERROR: user $user not created on $node" $LOG_FORCE
exit 9
fi
uids+=($out) # in node order
nodes+=($node) # to include mgmt-node if needed
done
uniq_uids=($(printf '%s\n' "${uids[@]}" | sort -u))
if (( ${#uniq_uids[@]} > 1 )) ; then
display "ERROR: \"$user\" user has inconsistent UIDs across cluster. UIDs: ${uniq_uids[*]}" $LOG_FORCE
for (( i=0; i<${#nodes[@]}; i++ )); do
display " node: ${nodes[$i]} has $user UID: ${uids[$i]}" $LOG_DEBUG
done
((errcnt++))
fi
done
(( errcnt > 0 )) && {
display "See $LOGFILE for more info on above error(s)" $LOG_FORCE;
exit 11; }
}
# verify_vol_stopped: there are timing windows when using ssh and the gluster
# cli. This function returns once it has confirmed that the volume has been
# stopped, or a predefined number of attempts have been made.
#
function verify_vol_stopped(){
local out; local i=0; local SLEEP=5; local LIMIT=$((NUMNODES * 2))
local EXPCT_VOL_STATUS_ERR="Volume $VOLNAME is not started"
local EXPCT_VOL_DEL_ERR="Volume $VOLNAME does not exist"
while (( i < LIMIT )) ; do # don't loop forever
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster volume status $VOLNAME" 2>&1)"
if grep -qs -E "$EXPCT_VOL_STATUS_ERR|$EXPCT_VOL_DEL_ERR" <<<$out; then
break
fi
sleep $SLEEP
((i++))
display "...verify vol stop wait: $((i*SLEEP)) seconds" $LOG_DEBUG
done
if (( i < LIMIT )) ; then
display " Volume stopped..." $LOG_INFO
else
display " ERROR: Volume not stopped..." $LOG_FORCE
exit 12
fi
}
# verify_vol_deleted: there are timing windows when using ssh and the
# gluster cli. This function returns once it has confirmed that the volume has
# been deleted, or a predefined number of attempts have been made.
#
function verify_vol_deleted(){
local out; local i=0; local SLEEP=5; local LIMIT=$((NUMNODES * 2))
local EXPCT_VOL_STATUS_ERR="Volume $VOLNAME does not exist"
while (( i < LIMIT )) ; do # don't loop forever
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster volume status $VOLNAME" 2>&1)"
[[ $? == 1 && "$out" == "$EXPCT_VOL_STATUS_ERR" ]] && break
sleep $SLEEP
((i++))
display "...verify vol delete wait: $((i*SLEEP)) seconds" $LOG_DEBUG
done
if (( i < LIMIT )) ; then
display " Volume deleted..." $LOG_INFO
else
display " ERROR: Volume not deleted..." $LOG_FORCE
exit 13
fi
}
# verify_peer_detach: there are timing windows when using ssh and the gluster
# cli. This function returns once it has confirmed that the number of nodes in
# the trusted pool is zero, or a predefined number of attempts have been made.
# $1=peer detach iteration (0 == 1st attempt)
# Note: this function returns 0 if the peer detach is confirmed, else 1. Also,
# if the pool has not detached on the 2nd attempt this function exits.
#
function verify_peer_detach(){
local first=$1 # first time verifying?
local out; local i=0; local SLEEP=5; local LIMIT=$((NUMNODES * 1))
local err_warn='WARN'; local rtn=0
(( first != 0 )) && err_warn='ERROR'
while (( i < LIMIT )) ; do
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster peer status | head -n 1")" # 'Number of Peers: x'
[[ $? == 0 && -n "$out" && ${out##*: } == 0 ]] && break
sleep $SLEEP
((i++))
display "...verify peer detatch wait: $((i*SLEEP)) seconds" $LOG_DEBUG
done
if (( i < LIMIT )) ; then
display " Trusted pool detached..." $LOG_INFO
else
display " $err_warn: Trusted pool NOT detached..." $LOG_FORCE
(( first != 0 )) && exit 15
rtn=1
fi
return $rtn
}
# verify_pool_create: there are timing windows when using ssh and the gluster
# cli. This function returns once it has confirmed that the number of nodes in
# the trusted pool equals the expected number, or a predefined number of
# attempts have been made.
#
function verify_pool_created(){
local DESIRED_STATE='Peer in Cluster'
local out; local i=0; local SLEEP=5; local LIMIT=$((NUMNODES * 2))
# out contains lines where the state != desired state, which is a problem
# note: need to use scratch file rather than a variable since the
# variable's content gets flattened (no newlines) and thus the grep -v
# won't find a node with the wrong state, unless they're all wrong.
while (( i < LIMIT )) ; do # don't loop forever
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster peer status >peer_status.out
if (( \$? == 0 )) ; then
grep 'State: ' <peer_status.out | grep -v '$DESIRED_STATE'
else
echo 'All messed up!'
fi")"
[[ -z "$out" ]] && break # empty -> all nodes in desired state
sleep $SLEEP
((i++))
display "...verify pool create wait: $((i*SLEEP)) seconds" $LOG_DEBUG
done
if (( i < LIMIT )) ; then
display " Trusted pool formed..." $LOG_INFO
else
display " ERROR: Trusted pool NOT formed..." $LOG_FORCE
out="$(ssh -oStrictHostKeyChecking=no root@$firstNode "
gluster peer status")"
display "$out" $LOG_FORCE
exit 18
fi