-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepGluster.sh
executable file
·109 lines (88 loc) · 2.76 KB
/
prepGluster.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
#!/usr/bin/bash
function prep_directories {
echo "- creating directories for glusterfs config and logging"
mkdir /etc/glusterfs \
/var/lib/glusterd \
/var/log/glusterfs
#chcon -Rt svirt_sandbox_file_t /etc/glusterfs
#chcon -Rt svirt_sandbox_file_t /var/lib/glusterd
#chcon -Rt svirt_sandbox_file_t /var/log/glusterfs
}
function disk_used {
return $(blkid $1 &> /dev/null; echo $?)
}
function format_device {
# Addition logic is needed here to account for RAID LUNs to ensure the
# alignment is correct. The code here is ONLY suitable for POC/demo
# purposes.
echo "- configuring $BRICK_DEV with LVM"
pvcreate $BRICK_DEV
vgcreate gluster $BRICK_DEV
local meta_data_size
local size_limit=1099511627776
local disk_size=$(vgs gluster --noheadings --nosuffix --units b -o vg_size)
local extent_size=$(vgs gluster --nosuffix --unit b --noheadings -o vg_extent_size)
local vg_free=$(vgs gluster --noheadings -o vg_free_count)
# Use 'extents' as unit of calculation
if [ ${disk_size} -gt ${size_limit} ]; then
# meta data size is 16GB
meta_data_size=$((17179869184/extent_size))
else
# metadata size is 0.5% of the disk's extent count
meta_data_size=$((vg_free/200))
fi
# create the pool - must be a multiple of 512
total_meta_data=$((meta_data_size*2))
local pool_size=$((vg_free-total_meta_data))
lvcreate -L $((pool_size*extent_size))b -T gluster/brickpool -c 256K \
--poolmetadatasize $((meta_data_size*extent_size))b \
--poolmetadataspare y
# lvcreate thin dev @ 90% of the brick pool, assuming snapshot support
local lv_size=$(((pool_size/100)*90))
lvcreate -V $((lv_size*extent_size))b -T gluster/brickpool -n brick1
echo "- Creating XFS filesystem"
# mkfs.xfs
mkfs.xfs -i size=512 /dev/gluster/brick1 1> /dev/null
if [ $? -eq 0 ]; then
echo "- filesystem created successfully"
else
exit 1
fi
}
function prep_disk {
# Assumptions
# 1. a host will provide a single RAID-6 LUN
# 2. logic deals with prior runs, not random disk configurations
#
echo -e "\nPreparing $BRICK_DEV for gluster use"
if ! disk_used $BRICK_DEV ; then
format_device $BRICK_DEV
else
echo -e "\nthe device $BRICK_DEV specified is already used"
fi
}
function check_block {
local len=${#1}
local dev=${1:0:5}
if [ $len -le 5 ] || [ $dev != "/dev/" ]; then
return 1
else
return 0
fi
}
echo -e "\nChecking configuration directories"
if [ ! -e /etc/glusterfs ] ; then
prep_directories
else
echo -e "- glusterfs directories already present, nothing to do"
fi
BRICK_DEV=$1
if [ -z $BRICK_DEV ]; then
echo "No device specified."
else
if check_block $BRICK_DEV; then
prep_disk
else
echo -e "\nInvalid device: $BRICK_DEV"
fi
fi