-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.sh
91 lines (72 loc) · 1.77 KB
/
setup.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
#!/bin/bash
set -x
# Shares
NFS_DATA=/net/grc/vol6
mkdir -p $NFS_DATA
chmod 777 $NFS_DATA
BLACKLIST="/dev/sda|/dev/sdb"
scan_for_new_disks() {
# Looks for unpartitioned disks
declare -a RET
DEVS=($(ls -1 /dev/sd*|egrep -v "${BLACKLIST}"|egrep -v "[0-9]$"))
for DEV in "${DEVS[@]}";
do
# Check each device if there is a "1" partition. If not,
# "assume" it is not partitioned.
if [ ! -b ${DEV}1 ];
then
RET+="${DEV} "
fi
done
echo "${RET}"
}
get_disk_count() {
DISKCOUNT=0
for DISK in "${DISKS[@]}";
do
DISKCOUNT+=1
done;
echo "$DISKCOUNT"
}
# Installs all required packages.
#
install_pkgs()
{
yum -y install epel-release
yum -y install nfs-utils nfs-utils-lib rpcbind mdadm
}
setup_raid()
{
#Verify attached data disks
ls -l /dev | grep sd
DISKS=($(scan_for_new_disks))
echo "Disks are ${DISKS[@]}"
declare -i DISKCOUNT
DISKCOUNT=$(get_disk_count)
echo "Disk count is $DISKCOUNT"
#Create RAID md device
mdadm -C /dev/md0 -l raid0 -n "$DISKCOUNT" "${DISKS[@]}"
#Create File System
mkfs -t xfs /dev/md0
echo "/dev/md0 $NFS_DATA xfs rw,noatime,attr2,inode64,nobarrier,sunit=1024,swidth=4096,nofail 0 2" >> /etc/fstab
}
mount_nfs()
{
echo "$NFS_DATA *(rw,async)" >> /etc/exports
systemctl enable rpcbind || echo "Already enabled"
systemctl enable nfs-server || echo "Already enabled"
systemctl start rpcbind || echo "Already enabled"
systemctl start nfs-server || echo "Already enabled"
exportfs
exportfs -a
exportfs
}
systemctl stop firewalld
systemctl disable firewalld
# Disable SELinux
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
install_pkgs
setup_raid
mount_nfs
exit 0