|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +adjustTCPKeepalive () |
| 4 | +{ |
| 5 | +# Azure public IPs have some odd keep alive behaviour |
| 6 | + |
| 7 | +echo "Setting TCP keepalive..." |
| 8 | +sysctl -w net.ipv4.tcp_keepalive_time=120 |
| 9 | + |
| 10 | +echo "Setting TCP keepalive permanently..." |
| 11 | +echo "net.ipv4.tcp_keepalive_time = 120 |
| 12 | +" >> /etc/sysctl.conf |
| 13 | +} |
| 14 | + |
| 15 | +formatDataDisk () |
| 16 | +{ |
| 17 | +# This script formats and mounts the drive on lun0 as /datadisk |
| 18 | +# It also sets the swap file to 32GB on /mnt which is the temporary disk on /dev/sdb |
| 19 | + |
| 20 | +SWAPFILE="/mnt/swapFile.swap" |
| 21 | + |
| 22 | +echo "Creating and formating a new swap file ..." |
| 23 | + |
| 24 | +fallocate -l 1g ${SWAPFILE} |
| 25 | +chmod 600 ${SWAPFILE} |
| 26 | +echo "Formating the swap file ..." |
| 27 | +mkswap ${SWAPFILE} |
| 28 | +echo "Enabling the swap file ..." |
| 29 | +swapon ${SWAPFILE} |
| 30 | +echo "${SWAPFILE} swap swap defaults 0 0" | sudo tee -a /etc/fstab |
| 31 | + |
| 32 | +DISK="/dev/disk/azure/scsi1/lun0" |
| 33 | +PARTITION="/dev/disk/azure/scsi1/lun0-part1" |
| 34 | +MOUNTPOINT="/datadisk" |
| 35 | + |
| 36 | +echo "Partitioning the disk." |
| 37 | +echo "g |
| 38 | +n |
| 39 | +p |
| 40 | +1 |
| 41 | +
|
| 42 | +
|
| 43 | +t |
| 44 | +83 |
| 45 | +w"| fdisk ${DISK} |
| 46 | + |
| 47 | +echo "Waiting for the symbolic link to be created..." |
| 48 | +udevadm settle --exit-if-exists=$PARTITION |
| 49 | + |
| 50 | +echo "Creating the filesystem." |
| 51 | +mkfs -j -t ext4 ${PARTITION} |
| 52 | + |
| 53 | +echo "Updating fstab" |
| 54 | +LINE="${PARTITION}\t${MOUNTPOINT}\text4\tnoatime,nodiratime,nodev,noexec,nosuid\t1\t2" |
| 55 | +echo -e ${LINE} >> /etc/fstab |
| 56 | + |
| 57 | +echo "Mounting the disk" |
| 58 | +mkdir -p $MOUNTPOINT |
| 59 | +mount -a |
| 60 | + |
| 61 | +echo "Changing permissions" |
| 62 | +chown couchbase $MOUNTPOINT |
| 63 | +chgrp couchbase $MOUNTPOINT |
| 64 | +} |
| 65 | + |
| 66 | +turnOffTransparentHugepages () |
| 67 | +{ |
| 68 | +echo "#!/bin/bash |
| 69 | +### BEGIN INIT INFO |
| 70 | +# Provides: disable-thp |
| 71 | +# Required-Start: $local_fs |
| 72 | +# Required-Stop: |
| 73 | +# X-Start-Before: couchbase-server |
| 74 | +# Default-Start: 2 3 4 5 |
| 75 | +# Default-Stop: 0 1 6 |
| 76 | +# Short-Description: Disable THP |
| 77 | +# Description: disables Transparent Huge Pages (THP) on boot |
| 78 | +### END INIT INFO |
| 79 | +
|
| 80 | +echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled |
| 81 | +echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag |
| 82 | +" > /etc/init.d/disable-thp |
| 83 | +chmod 755 /etc/init.d/disable-thp |
| 84 | +service disable-thp start |
| 85 | +update-rc.d disable-thp defaults |
| 86 | +} |
| 87 | + |
| 88 | +setSwappinessToZero () |
| 89 | +{ |
| 90 | +sysctl vm.swappiness=0 |
| 91 | +echo " |
| 92 | +# Required for Couchbase |
| 93 | +vm.swappiness = 0 |
| 94 | +" >> /etc/sysctl.conf |
| 95 | +} |
| 96 | + |
| 97 | +addCBGroup () |
| 98 | +{ |
| 99 | + $username = $1 |
| 100 | + $password = $2 |
| 101 | + path = ${3-'/opt/couchbase/bin/'} |
| 102 | + cli=${path}couchbase-cli group-manage |
| 103 | + ls $path |
| 104 | + $cli --username $username --password $password --create --group-name |
| 105 | + #runs in the directory where couchbase is installed |
| 106 | +} |
0 commit comments