Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Last active July 17, 2023 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tyzbit/56373a2d58d850fcd801bca35e060135 to your computer and use it in GitHub Desktop.
Save tyzbit/56373a2d58d850fcd801bca35e060135 to your computer and use it in GitHub Desktop.
bootstrap-ubuntu-server
#!/bin/bash
## Edit sudoers (add "NOPASSWD:" to the sudo line before ALL)
## Add optional: true to netplan and apply
## Add Google Kubernetes key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B53DC80D13EDEF05
# Install Docker
sudo apt-get update
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
ioping \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update && sudo apt-get install -y \
containerd.io=1.2.13-2 \
docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \
docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)
sudo apt-mark hold containerd.io docker-ce docker-ce-cli
sudo usermod -a -G docker tyzbit
# kubeadm
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet=1.23.14-00 kubeadm=1.23.14-00 kubectl=1.23.14-00
sudo apt-mark hold kubelet kubeadm kubectl kubernetes-cni
# install common tools
sudo apt install -y \
bluez-tools \
checkinstall \
fio \
iotop \
jq \
net-tools \
nethogs \
nfs-common \
open-iscsi \
pv \
rename \
screen \
smartmontools \
sysstat
## Needed for problematic networking nodes
# sudo sysctl net.bridge.bridge-nf-call-iptables=1
# sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
sudo swapoff /swap.img
sudo sed -i '/^.*swap.img/s/^/#/' /etc/fstab
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl enable docker
# needed for longhorn
# https://github.com/longhorn/longhorn/issues/1210#issuecomment-671689746
sudo tee -a /etc/multipath.conf <<EOF
blacklist {
devnode "^sd[a-z0-9]+"
}
EOF
sudo systemctl restart multipathd.service
## Install 2.5Gbe DKMS driver (with many thanks to Perihelion)
## Set a temporary password
sudo add-apt-repository -y ppa:awesometic/ppa
sudo apt install -y realtek-r8125-dkms
## Blacklist incorrect Realtek module
sudo tee -a /etc/modprobe.d/blacklist-r8169.conf > /dev/null <<EOT
# To use r8125 driver explicitly
blacklist r8169
EOT
sudo rmmod r8169
sudo update-initramfs -u
# increase font size
sudo sed -i 's/8x16/16x32' /etc/default/console-setup
#### REBOOT AND INSTALL NETWORK CARD ####
#curl http://config.jura:8080/newrelic-logging.sh | bash
#sudo curl -o /etc/newrelic-infra/logging.d/syslog.yaml http://config.jura:8080/syslog.yaml
#sudo systemctl restart newrelic-infra.service
@tyzbit
Copy link
Author

tyzbit commented Mar 8, 2023

Second step after booting back in:

# wakeonlan
interface=$(ifconfig | grep -B1 'broadcast 192.168.1.255' | head -n 1 | awk '{print $1}' | sed 's/://g')
cat <<EOF | sudo tee /etc/systemd/system/wol@.service
[Unit]
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target

[Service]
ExecStart=/sbin/ethtool -s %i wol g
Type=oneshot

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable wol@$interface
sudo ethtool -s $interface wol g
echo "$(hostname) :: $(ifconfig | grep -A2 'broadcast 192.168.1.255' | tail -n 1 | awk '{print $1,$2}')"

@tyzbit
Copy link
Author

tyzbit commented Mar 8, 2023

Third step after reboot:

## Check if the incorrect Realtek module is loaded
lsmod | grep -i r8169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment