virtualization

warning: Creating default object from empty value in /data/web/1/000/027/003/273448/htdocs/panticz.de/modules/taxonomy/taxonomy.pages.inc on line 33.

brctl: network bridges

# create bridge
brctl addbr br0
ifconfig eth0 0.0.0.0

brctl delif lxcbr0 eth0
brctl addif br0 eth0
dhclient br0

# move VM to other bridge
for IF in $(brctl show | grep veth | sed 's/^

*//'); do
    brctl delif lxcbr0 ${IF}
    brctl addif br0 ${IF}
done
 
 
# connect two bridges?
ip link add veth0 type veth peer name veth1
ifconfig veth0 up
ifconfig veth1 up
 
brctl delif br0 veth0
brctl delif lxcbr0 veth1
 
 
# renew ip in VM
lxc-attach -n vm1 -- dhclient
 
 
# /etc/network/interfaces
auto eth0
iface eth0 inet static
    address 0.0.0.0
 
auto br0

Create XEN LXC DomU

DOMAIN_NAME=lxc
DOMAIN_MAC=00:00:00:ef:11:cc
DOMAIN_RAM=2Gb
DOMAIN_HDD=128Gb
 
xen-create-image \
    --hostname=${DOMAIN_NAME} \
    --dist=xenial  \
    --lvm=vg1 \
    --fs=ext4 \
    --dhcp \
    --pygrub \
    --mac=${DOMAIN_MAC} \
    --mirror=http://archive.ubuntu.com/ubuntu \
    --size=${DOMAIN_HDD} \
    --memory=${DOMAIN_RAM} \
    --swap=${DOMAIN_RAM} \
    --genpass=0 \
    --password=t00r \
    --vcpus $(cat /proc/cpuinfo | grep processor | wc -l)
 
mv /etc/xen/${DOMAIN_NAME}.cfg /etc/xen/${DOMAIN_NAME}
ln -s /etc/xen/${DOMAIN_NAME} /etc/xen/auto/12_lxc
 
mou

Install LXD

wget https://raw.githubusercontent.com/panticz/installit/master/install.lxd.sh -O - | bash -

#!/bin/bash

sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:ubuntu-lxc/lxd-stable

# use Ubunut Trusty repository on Utopic
sed -i 's|utopic|trusty|g' /etc/apt/sources.list.d/ubuntu-lxc-ubuntu-lxd-stable-utopic.list

sudo apt-get update
sudo apt-get install -y lxd lxc lxcfs

Links
https://linuxcontainers.org/lxd/getting-started-cli/

Update LXC container templates filesystem

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh -O - | bash -

#!/bin/bash

# ensure that this script is run as root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# set language to english
LANG=en_US.UTF-8

# update APT rootfs (Debian and Ubuntu)
for DIST in $(find /var/cache/lxc/*/* -maxdepth 0 -type d); do
  echo "Updating ${DIST} ..."
  chroot "${DIST}" apt-get update -qq
  chroot "${DIST}" apt-get dist-upgrade -qq -y
  chroot "${DIST}" apt-get autoremove -qq -y
  chroot "${DIST}" apt-get clean
done

# fix dns
echo "nameserver 8.8.8.8" > /var/cache/lxc/debian/rootfs-wheezy-amd64/etc/resolv.conf

Cronjob
echo "0 13 * * * root /usr/bin/wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh -O - | bash -" > /etc/cron.d/lxc_update_template
service cron restart

# fix squeeze repository
sed -i 's|cdn.debian.net|ftp.debian.org|g' /var/cache/lxc/debian/rootfs-squeeze-amd64/etc/apt/sources.list

Docker

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.docker.sh -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

apt-get install -y curl linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates software-properties-common

curl -fsSL https://yum.dockerproject.org/gpg | apt-key add -
add-apt-repository deb https://apt.dockerproject.org/repo/ ubuntu-$(lsb_release -cs) main"
apt-get update

apt-get -y install docker-engine

systemctl enable docker
systemctl status docker

Debug / Run test container
docker info
docker run hello-world
#docker run -it centos bash

#docker run -i --rm ubuntu bash

sudo docker run -i -t --name dc-ubuntu ubuntu bash
sudo docker start -i dc-ubuntu

# wordpress
docker run -d --name dc-mysql -e MYSQL_ROOT_PASSWORD=mysqlpwd mysql
docker run -d --name dc-wordpress --link dc-mysql:mysql -p 7894:80 wordpress

# search
docker search icinga
docker pull phre/icinga

docker run --name dc-nginx -d -p 7890:80 nginx
http://localhost:7890/
docker logs dc-nginx

# images
sudo docker images
sudo docker rmi 3eXXXXx

apt-get install docker
docker run -t -i --rm ubuntu bash
docker run -i -t --name dc-ubuntu ubuntu bash
docker start -i dc-ubuntu
docker run --name dc-nginx -d -p 7890:80 nginx
docker logs dc-nginx
docker stop dc-nginx
docker rm dc-nginx
docker run --name dc-nginx -d -p 7890:80 -v /tmp/srv/:/usr/local/nginx/html:ro nginx
docker run --name dc-nginx-tmp -t -i nginx /bin/bash
docker commit dc-nginx-tmp img-mynginx
docker run --name dc-mynginx -d -p 7891:80 img-mynginx nginx

# view all cointainer (also inactive)
docker ps -a

# remove all container
docker ps -qa | xargs docker rm

/tmp/dbuildtst/Dockerfile
MAINTAINER Mein Name
FROM nginx
RUN echo 'Hello again! ' > /usr/local/nginx/html/index.html

docker build -t=img-mynginx2 /tmp/dbuildtst/

docker run --name dc-mynginx2 -d -p 7892:80 img-mynginx2

http://registry.hub.docker.com

https://wiki.debian.org/Docker

Run Docker inside LXC container
# http://stackoverflow.com/questions/22085657/can-docker-run-inside-a-linux-container
echo 'DOCKER_OPTS="--exec-driver=lxc"' | tee -a /etc/default/docker
service docker restart

# mysql container
sudo docker pull mysql

# build a container
https://www.digitalocean.com/community/tutorials/docker-explained-using-dockerfiles-to-automate-building-of-images

# notes
docker run --lxc-conf="lxc.network.hwaddr=92:20:de:b0:6b:61" my_image ifconfig
edit /etc/default/docker: DOCKER_OPTS="--dns 8.8.8.8 -e lxc"
apt-get install lxc (lxc-docker is not enough)
docker run --lxc-conf="lxc.network.hwaddr=92:20:de:b0:6b:61" -t myimage

# non root?
https://docs.docker.com/installation/debian/

# quick & easy install
wget -qO- https://get.docker.com/ | sh

# docker under LXC
http://ashish1099.github.io/blog/2015/05/23/docker-inside-lxc/
https://www.stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/
cat /var/lib/lxc/docker/config
...
lxc.aa_profile = unconfined
lxc.cgroup.devices.allow = a
lxc.cap.drop =

# 15 Quick Docker Tips
http://www.centurylinklabs.com/15-quick-docker-tips/

# get volume information
for VOLUME in $(docker volume ls -q); do
docker volume inspect ${VOLUME}
done

# delete unused volumes
docker volume rm $(docker volume ls -qf dangling=true)

# service
/usr/lib/systemd/system/docker.service
/etc/systemd/system/multi-user.target.wants/docker.service

Links
https://github.com/panticz/installit/blob/master/install.docker.sh
https://docs.docker.com/engine/reference/commandline/dockerd/

Install LXC (Linux Containers) under Ubuntu

Installation
http://www.panticz.de/install_lxc

Create container
export LANG=en_US.UTF-8
export CONTAINER=wheezy

sudo sudo lxc-destroy -n ${CONTAINER}
sudo lxc-create -t debian -n ${CONTAINER}
sudo lxc-start -d -n ${CONTAINER}

echo 'Acquire::http::Proxy "http://apt-cacher:3142/";' | sudo tee /var/lib/lxc/${CONTAINER}/rootfs/etc/apt/apt.conf

sudo lxc-attach -n ${CONTAINER} -- apt-get clean
sudo lxc-attach -n ${CONTAINER} -- apt-get update
sudo lxc-attach -n ${CONTAINER} -- apt-get dist-upgrade -y

Create Debian Squeeze DomU

wget https://raw.githubusercontent.com/panticz/xen/master/domains/debian.squeeze.sh -O - | bash -

#!/bin/bash

# configure domU
DOMAIN_NAME=squeeze
DOMAIN_MAC=00:09:01:01:aa:bb
DOMAIN_RAM=2Gb
DOMAIN_HDD=8Gb
 
# create domU on LVM (for image file use --dir=/root)
xen-create-image \
 --hostname=${DOMAIN_NAME} \
 --dist=squeeze \
 --lvm=vg0 \
 --size=${DOMAIN_HDD} \
 --fs=ext4 \
 --role=udev \
 --memory=${DOMAIN_RAM} \
 --swap=${DOMAIN_RAM} \
 --dhcp \
 --mac=${DOMAIN_MAC} \ 
 --genpass=0 \
 --password=t00r \
 --apt_proxy=http://apt-cacher:3142/ \
 --vcpus $(cat /proc/cpuinfo | grep processor | wc -l)
 
# rename vm config
mv /etc/xen/${DOMAIN_NAME}.cfg /etc/xen/${DOMAIN_NAME}
 
# OPTIONAL: add to autostart
ln -s /etc/xen/${DOMAIN_NAME} /etc/xen/auto
 
# start domU
xm create -c ${DOMAIN_NAME}

# disable pc speaker
echo 'blacklist snd-pcsp' >> /etc/modprobe.d/blacklist.conf

# check for updates
touch /etc/apt/apt.conf.d/10periodic
if [ $(cat /etc/apt/apt.conf.d/10periodic | grep -c Update-Package-Lists) -eq 0 ]; then
 echo 'APT::Periodic::Update-Package-Lists "1";' >> /etc/apt/apt.conf.d/10periodic
fi

# fix FQDN
sed -i "s|$(hostname) $(hostname)|$(hostname -A)$(hostname)|g" /etc/hosts
 
user: root
password: t00r

Install VirtualBox

wget https://raw.githubusercontent.com/panticz/installit/master/install.virtualbox.sh -O - | bash -

#!/bin/sh

if [ ! -z $1 ]; then
    USER=$1
fi

# install debconf-utils
sudo apt-get install debconf-utils

# add debconf answer
sudo debconf-set-selections <<\EOF
virtualbox virtualbox/group-vboxusers note
EOF

# add key
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

# install repository key
wget -q -O - http://www.virtualbox.org/download/oracle_vbox_2016.asc | apt-key add -

# update repository list
echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
sudo apt-get update -qq

# install
sudo apt-get install -y virtualbox-5.1

# install extension pack
VERSION=$(dpkg-query -W -f='${Version}' "virtualbox*" | cut -d "-" -f1)
wget http://download.virtualbox.org/virtualbox/${VERSION}/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack -P /tmp/
sudo VBoxManage extpack install /tmp/Oracle_VM_VirtualBox_Extension_Pack-${VERSION}.vbox-extpack

# add current user to vboxusers group
sudo adduser ${USER} vboxusers

--allow-unauthenticated

Fix kernel module
sudo /etc/init.d/vboxdrv setup

Links
http://wiki.ubuntuusers.de/VirtualBox/Installation
http://www.virtualbox.org/wiki/Linux_Downloads
http://www.panticz.de/node/143

Syndicate content