Skip to content

Instantly share code, notes, and snippets.

@D3strukt0r
Last active February 1, 2021 13:10
Show Gist options
  • Save D3strukt0r/5aaba1a021d16b31fa19adf6eb26a102 to your computer and use it in GitHub Desktop.
Save D3strukt0r/5aaba1a021d16b31fa19adf6eb26a102 to your computer and use it in GitHub Desktop.

BACKUP DATA FOLDER /opt

for d in */; do
    dir=${d%/}
    if [ "$dir" == "containerd" ]; then
        continue
    fi
    echo "Backing up $dir ..."
    tar -pczf $dir.tar.gz $dir
done
for d in */; do dir=${d%/}; if [ "$dir" == "containerd" ]; then continue; fi; echo "Backing up $dir ..."; tar -pczf $dir.tar.gz $dir; done
rm *.tar.gz

INSTALL UBUNTU

As usual

Import SSH identities from Github

curl -L https://github.com/<username>.keys >> ~/.ssh/authorized_keys
sudo apt install ncdu
ncdu -r /opt

INSTALL SSH KEY FOR LOGIN WITHOUT PASSWORD

Generate the key:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-keygen -t ed25519 -a 100 -C "your_email@example.com"

And upload to Github, or send directly to server with the following command:

LINUX

ssh-copy-id user@host

To provent multiple passsword entry run (start the ssh-agent in the background):

ssh-agent -s

Add your SSH key to the ssh-agent

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_ed25519

WINDOWS

https://code.visualstudio.com/docs/remote/troubleshooting#_quick-start-using-ssh-keys

$pubKey=(Get-Content "$HOME\.ssh\id_rsa.pub" | Out-String)
$pubKey=(Get-Content "$HOME\.ssh\id_ed25519.pub" | Out-String)
ssh "<user>@<host>" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '${pubKey}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

To provent multiple passsword entry run (make sure tools are available and start the ssh-agent in the background):

https://stackoverflow.com/questions/52113738/starting-ssh-agent-on-windows-10-fails-unable-to-start-ssh-agent-service-erro

Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent

Add your SSH key to the ssh-agent

ssh-add $HOME\.ssh\id_rsa
ssh-add $HOME\.ssh\id_ed25519

FIX VS CODE (FILE WATCH LIMIT)

https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

To find the files count

find . -type f -print | wc -l

Edit the following file:

nano /etc/sysctl.conf

And add: fs.inotify.max_user_watches=524288 at the end of the file (Will use up 540 MiB of memory).

Then load the changes with:

sysctl -p

INSTALL DOCKER

https://docs.docker.com/install/linux/docker-ce/ubuntu/

apt remove docker docker-engine docker.io containerd runc
apt update
apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install docker-ce docker-ce-cli containerd.io

TEST

docker run hello-world

ADD USER TO DOCKER GROUP

usermod -aG docker $USER

INSTALL DOCKER COMPOSE

https://docs.docker.com/compose/install/#install-as-a-container

curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

And to get autocompletion:

curl -L https://raw.githubusercontent.com/docker/compose/1.25.5/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose

RESTORE DATA FOLDER /opt

Upload the compressed files back on the server

for backup in *.tar.gz; do
    tar -pxzf "$backup";
done
for backup in *.tar.gz; do tar -pxzf "$backup"; done
rm *.tar.gz

PREPARE SYSTEM TO USE PI-HOLE

TEST IF PORT 53 IS AVAILABLE

netstat -anop | grep ":53\b"

DISABLE PORT 53 BLOCKAGE

https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu

sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
mv /etc/resolv.conf /etc/resolv.conf.bak
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl restart systemd-resolved

PREPARE SYSTEM TO USE TRAEFIK

SETUP (Skip if already done)

https://stackoverflow.com/questions/52167035/traefik-permissions-777-for-acme-json-are-too-open-please-use-600

touch traefik/acme.json
chmod 600 traefik/acme.json

RESTORE

docker network create traefik_proxy

START ALL CONTAINERS

cd /opt/<...>/
docker-compose up -d

TEST IF PI.HOLE WORKS

Should show IP

nslookup google.com [pihole-server-ip]

Should say Address: 0.0.0.0

nslookup doubleclick.com [pihole-server-ip]

TROUBLESHOOT DNS

WINDOWS

ipconfig /release
ipconfig /renew
ipconfig /flushdns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment