Skip to content

Instantly share code, notes, and snippets.

@csabatini
Last active June 1, 2016 18:14
Show Gist options
  • Select an option

  • Save csabatini/05ba616b84a67e336ff6d27fe94f53e1 to your computer and use it in GitHub Desktop.

Select an option

Save csabatini/05ba616b84a67e336ff6d27fe94f53e1 to your computer and use it in GitHub Desktop.
#!/bin/bash
NODE_TYPE=$1
HDD=()
SSD=()
i=0
j=0
etc_configs() {
cp /etc/fstab ~/
cp /etc/fstab /etc/fstab.original
sed -i "s/%admin ALL=(ALL) ALL/%admin ALL=(ALL) NOPASSWD:ALL/g" /etc/sudoers
sed -i "s/positive-time-to-live hosts 60/positive-time-to-live hosts 3600/" /etc/nscd.conf
echo -e "root soft nofile 32768\nroot hard nofile 32768" >> /etc/security/limits.conf
echo -e "session required pam_limits.so" >> /etc/pam.d/common-session
echo -e "session required pam_limits.so" >> /etc/pam.d/common-session-noninteractive
echo -e "vm.swappiness=10" >> /etc/sysctl.conf
echo -e "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
}
install_pkgs() {
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9733A7A07513CAD
cd /etc/apt/sources.list.d
wget http://public-repo-1.hortonworks.com/ambari/ubuntu12/2.x/updates/2.2.2.0/ambari.list
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-7-jdk ntp git ambari-agent htop sysstat lsscsi mdadm
update-rc.d ntp defaults
}
swap_file() {
fallocate -l 56G /mnt/swapfile
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile
echo "/mnt/swapfile none swap defaults 0 0" >> ~/fstab
}
check_scsi() {
lsscsi > ~/scsi.txt
mapfile -t SCSI < ~/scsi.txt
OSDEV=$(df | awk 'FNR == 2 {print $1}' | sed -e 's/1//')
for line in "${SCSI[@]}"; do
TYPE=$(echo $line | awk '{print $2}')
DEVICE=$(echo $line | awk '{print $7}')
# tuple is scsi_host,channel,target_number,LUN
TUPLE=$(echo $line | awk '{print $1}' | sed -e 's/^\[//;s/\]$//')
TGT=$(echo $TUPLE | awk -F':' '{print $3}')
LUN=$(echo $TUPLE | awk -F':' '{print $4}')
# lun 0-12 are standard data disks, target_number 1 is local SSD, also skip cd/dvd + OS device
if [ $LUN -le 12 ] && [ $TGT -ne 1 ] && [ $TYPE != "cd/dvd" ] && [ $DEVICE != $OSDEV ];
then
HDD[$i]="${DEVICE}"
# luns 13 and 14 are premium disks on storm/kafka nodes
elif [ $LUN -gt 12 ];
then
case "$NODE_TYPE" in
realtime)
SSD[$j]="${DEVICE}"
j=$[$j+1]
;;
worker)
HDD[$i]="${DEVICE}"
;;
esac
fi
i=$[$i+1]
done
case "$NODE_TYPE" in
realtime)
make_filesystems "${HDD[@]}" "1" "main"
make_filesystems "${SSD[@]}" "0" "kafka"
;;
worker)
make_filesystems "${HDD[@]}" "1" "main"
;;
esac
}
make_filesystems() {
disks=("$@")
((last_idx=${#disks[@]} - 1))
mp=${disks[last_idx]}
unset disks[last_idx]
((last_idx=${#disks[@]} - 1))
b=${disks[last_idx]}
unset disks[last_idx]
i=0
RAID_CMD="sudo mdadm --create /dev/md${#disks[@]} --level=stripe --raid-devices=${#disks[@]} "
for d in "${disks[@]}"; do
(echo n; echo p; echo 1; echo ; echo ; echo t; echo fd; echo p; echo w;) | fdisk ${d}
RAID_CMD+="${d}1 "
i=$[$i+1]
done
eval "$RAID_CMD"
mkdir -p /media/${mp}
mkfs.ext4 /dev/md${#disks[@]}
uuid=$(blkid | grep "md${#disks[@]}" | grep -oP '[-a-z0-9]{36}')
echo "UUID=${uuid} /media/${mp} ext4 defaults,noatime,barrier=${b} 0 0" >> ~/fstab
}
etc_configs
install_pkgs
check_scsi
mv ~/fstab /etc/fstab
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment