r815: Docker+Vagrant.

This commit is contained in:
Ole Tange 2020-06-12 16:24:10 +02:00
parent c1d8c19d35
commit d1be2cce4f
8 changed files with 189 additions and 7 deletions

65
r815/Docker.setup Normal file
View file

@ -0,0 +1,65 @@
#!/bin/bash
install() {
# Install needed software once
sudo apt -y install docker.io
sudo groupadd docker
sudo usermod -aG docker $USER
# Logout and login if you were not in group 'docker' before
docker run hello-world
}
setup() {
# Configure the virtual servers
mkdir -p my-ubuntu/ ssh/
cp ~/.ssh/id_rsa.pub ssh/
cat ssh/*.pub > my-ubuntu/authorized_keys
cat >my-ubuntu/Dockerfile <<EOF
FROM ubuntu:bionic
RUN apt update && \
apt install -y openssh-server
RUN mkdir /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys
# run blocking command which prevents container to exit immediately after start.
CMD service ssh start && tail -f /dev/null
EOF
docker build my-ubuntu -t my-ubuntu
}
start() {
testssh() {
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@"$1" echo "'$1'" '`uptime`'
}
export -f testssh
# Start the virtual servers
seq 100 |
parallel -j0 'docker run -d --rm --name my-ubuntu-{} my-ubuntu; docker inspect my-ubuntu-{}' |
# After this it is possible to do:
# ssh 10.0.0.99
# from another physical server
perl -nE '/"IPAddress": "(\S+)"/ and not $seen{$1}++ and say $1' |
parallel testssh
docker ps
}
stop() {
# Stop the virtual servers
# After there is no running processes on the host server
# and after this it is no longer possible to do:
# ssh 10.0.0.99
# from another physical server
# The host server returns to the state before running `start`
seq 100 | parallel -j0 docker stop my-ubuntu-{}
docker ps
}
destroy() {
# Remove the setup
# After this the host server returns to the state before running `setup`
rm -rf my-ubuntu/
docker rmi my-ubuntu
}
full() {
install
setup
start
stop
destroy
}

View file

@ -2,10 +2,26 @@ UEFI boot does not work, so use legacy boot.
Installed with ubuntu-20.04-live-server-amd64.iso
ssh-copy-id
git clone 192.168.1.129:privat/configfiles
cp configfiles/ubuntu-20.04/home/.* .
sudo cp configfiles/ubuntu-20.04/home/.* /root
bash configfiles/ubuntu-20.04/packages
git clone 192.168.1.129:privat/config
cp config/ubuntu-20.04/home/.* .
sudo cp config/ubuntu-20.04/home/.* /root
bash config/ubuntu-20.04/packages
add_swap() {
truncate -s 16T /data/swapfile
mkswap swapfile
mkswap -L swap1 /dev/sdc
mkswap -L swap2 /dev/sdd
mkswap -L swap3 /dev/sde
cat >> /etc/fstab <<_EOF
LABEL=swap1 none swap sw,pri=4 0 0
LABEL=swap2 none swap sw,pri=4 0 0
LABEL=swap3 none swap sw,pri=4 0 0
_EOF
}
LVM_extend_to_full_disk() {
lvextend -L +10G /dev/ubuntu-vg/ubuntu-lv

70
r815/Vagrant.setup Normal file
View file

@ -0,0 +1,70 @@
install() {
# Install needed software once
sudo apt install -y vagrant virtualbox
}
setup() {
# Configure the virtual servers
mkdir -p ssh/
cp ~/.ssh/id_rsa.pub ssh/
cat ssh/*.pub > authorized_keys
cat >Vagrantfile <<'EOF'
Vagrant.configure("2") do |config|
config.vm.box = "debian/buster64"
config.vm.network "public_network"
(1..100).each do |i|
config.vm.define "vm%03d" % i do |node|
node.vm.hostname = "vm%03d" % i
# use the following line to map a range of ports on the host
# to the VNC port of each VM:
# node.vm.network "forwarded_port", host: 5900+i, guest: 5900
end
end
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("authorized_keys").first.strip
s.inline = <<-SHELL
mkdir /root/.ssh
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
apt-get update
apt-get install -y parallel
SHELL
end
end
EOF
}
start() {
testssh() {
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@"$1" echo "'$1'" '`uptime`'
}
export -f testssh
# Start the virtual servers
seq 100 | parallel vagrant up vm{}
# After this it is possible to do:
# ssh 10.0.0.99
# from another physical server
# How do we get the IP-addresses?
# parallel testssh
}
stop() {
# Stop the virtual servers
# After there is no running processes on the host server
# and after this it is no longer possible to do:
# ssh 10.0.0.99
# from another physical server
# The host server returns to the state before running `start`
vagrant suspend
}
destroy() {
# Remove the setup
# After this the host server returns to the state before running `setup`
?
}
full() {
install
setup
start
stop
destroy
}

1
r815/etc/default/locale Normal file
View file

@ -0,0 +1 @@
LANC=C

24
r815/etc/rc.local Normal file
View file

@ -0,0 +1,24 @@
#!/bin/sh
set -e
case "$1" in
start)
loopdev=$(losetup --show -f /data/swapfile)
swapon $loopdev
;;
stop)
loopdev=$(losetup -j /data/swapfile | grep -o "/dev/loop[0-9]*")
swapoff $loopdev
losetup -d $loopdev
;;
restart)
loopdev=$(losetup -j /data/swapfile | grep -o "/dev/loop[0-9]*")
swapoff $loopdev
swapon $loopdev
;;
*)
echo "Usage: $0 { start | stop | restart }" >&2
exit 1
;;
esac

View file

@ -4,3 +4,5 @@ echo 1 > /sys/module/zswap/parameters/enabled
echo z3fold > /sys/module/zswap/parameters/zpool
echo 50 > /sys/module/zswap/parameters/max_pool_percent
echo lz4 > /sys/module/zswap/parameters/compressor
grep -R . /sys/kernel/debug/zswap/
echo 2 > /proc/sys/vm/overcommit_memory

View file

@ -32,8 +32,8 @@ partitiondisk() {
sgdisk --zap-all $DISK
sgdisk -n2:1M:+510M -t2:EF00 $DISK
sgdisk -a 1048576 -n3:0:+2G -t3:BF01 $DISK
# TODO better way to find the max size rounded to 8192
sgdisk -a 1048576 -n4:0:$((1948254208+5242880-1)) -t4:8300 $DISK
end_position=$(sgdisk -E $DISK)
sgdisk -a 1048576 -n4:0:$(( $end_position - (($end_position + 1) % 2048) )) -t4:BF01 $DISK
fdisk -l $DISK
# Needed for partitiontable to be visible
sleep 5
@ -65,8 +65,9 @@ setup_zpool_for_root() {
cryptsetup luksClose luks1
echo "$password" | cryptsetup -y -v luksFormat --sector-size 4096 \
--pbkdf-parallel 1 \
--pbkdf-memory 4000000 --pbkdf argon2id --iter-time 10000 \
--pbkdf-memory 4000000 --pbkdf argon2id --iter-time 1000 \
${DISK}-part4
cryptsetup config --priority prefer --key-slot 0
echo "$password" | cryptsetup luksOpen ${DISK}-part4 luks1
(echo "$password"; echo "$secretpassword") |
cryptsetup -y -v luksAddKey \

View file

@ -62,6 +62,7 @@ mosh
psmisc
#owncloud-client
htop
net-tools
#uswsusp
#cifs-utils
#r-base-core
@ -70,6 +71,8 @@ htop
libreoffice
vlc
iridium
xkbset
sox
#xfce4
#clusterssh
##wine