= Was ist LXC und warum machen wir damit VServer = LXC steht für Linux-Containers und ist eine Art virtueller Server für Linux. Dabei nutzen alle virtuellen Server-Instanzen den Kernel der Wirtsystems mit. Implementiert werden die Container in Linux über die Namespace Erweiterungen, die dafür sorgen, dass Prozesse in eigene Adressräume isoliert werden können. Da dies nicht nur Prozesse und Speicher, sondern auch Netzwerke umfasst, können hiermit vollständige virtuelle Server implementiert werde. Bislang wurde bei PING die ältere Linux-VServer-Implentierung eingesetzt, die einen eigenen Kernel-Patch und Userspace-Tools implementiert. Bis zur Version Squeeze von Debian wurde dabei vom Debian-Kernel-Team ein entsprechend gepatchter Kernel zur Verfügung gestellt. Mit Release von Wheezy wurde dies allerdings zu Gunsten der weiter fortgeschrittenen Entwicklung der Linux-Containers entfernt. Für Linux-Containers sind einige Optionen zu Namespaces zu aktivieren, was aber bei den Kernel-Images von Debian bereits der Fall ist. Es ist somit nur noch das Paket ''lxc'' zu installieren, welches die Userspace-Tools zu Erzeugung und Verwaltung der Container enthält. = Probleme = LXC ist noch in der Entwicklung, früher waren LXC-Container nicht ausbruchsicher, dies ist aber seit Debian Jessie nicht mehr der Fall siehe https://wiki.debian.org/LXC == Konvertierung eines Linux-VServer Gastes in einen LXC Container == http://schmidi2.blog.com/2010/10/25/migrating-from-vserver-to-lxc/ = Installation des Hosts = Der Anleitung im [[https://wiki.debian.org/LXC|Debian Wiki]] folgend, muss zunächst das LXC-Paket installiert werden: {{{ root@containers:~# apt-get install lxc Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: arch-test bridge-utils busybox-static cloud-image-utils debootstrap distro-info dns-root-data dnsmasq-base genisoimage libaio1 libglib2.0-0 libglib2.0-data liblxc1 libpam-cgfs lxc-templates lxcfs qemu-utils rsync shared-mime-info uidmap uuid-runtime xdg-user-dirs Suggested packages: cloud-utils-euca ubuntu-archive-keyring squid-deb-proxy-client shunit2 wodim cdrkit-doc btrfs-progs lvm2 python3-lxc qemu-block-extra The following NEW packages will be installed: arch-test bridge-utils busybox-static cloud-image-utils debootstrap distro-info dns-root-data dnsmasq-base genisoimage libaio1 libglib2.0-0 libglib2.0-data liblxc1 libpam-cgfs lxc lxc-templates lxcfs qemu-utils rsync shared-mime-info uidmap uuid-runtime xdg-user-dirs 0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded. Need to get 8030 kB of archives. After this operation, 34.4 MB of additional disk space will be used. Do you want to continue? [Y/n] }}} = Vorbereitung der unprivilegierten Root-Container = Da die als VServer gedachten Container von Root während des Startes des Systems erzeugt werden, diese aber unprivilegiert sein sollen, muss ein uid- und gid-Bereich dem Nutzer Root zugewiesen werden (vergl. https://linuxcontainers.org/lxc/getting-started/#creating-unprivileged-containers-as-root): {{{ root@containers:/etc# git diff diff --git a/lxc/default.conf b/lxc/default.conf index d2d1d51..30231e3 100644 --- a/lxc/default.conf +++ b/lxc/default.conf @@ -1,3 +1,5 @@ lxc.net.0.type = empty lxc.apparmor.profile = generated lxc.apparmor.allow_nesting = 1 +lxc.idmap = u 0 100000 65536 +lxc.idmap = g 0 100000 65536 diff --git a/subgid b/subgid index dc7d014..44be50f 100644 --- a/subgid +++ b/subgid @@ -1,2 +1 @@ -dh:100000:65536 -bodo:165536:65536 +root:100000:65536 diff --git a/subuid b/subuid index dc7d014..44be50f 100644 --- a/subuid +++ b/subuid @@ -1,2 +1 @@ -dh:100000:65536 -bodo:165536:65536 +root:100000:65536 }}} = Netzwerk = Damit die LXC-Container auf das Netwerk zugreifen können, müssen derren virtuellen Netzwerkkarten an das {{{membersnetz1}}} angebunden werden. Da {{{containers.ping.de}}} selbst schon in diesem Netz ist und sommit {{{eth0}}} von {{{containers.ping.de}}} als Interface in einer Bridge genutzt werden kann, muss aus dem {{{eth0}}}-Interface einfach eine Bridge werden. Hierfür wird {{{/etc/network/interfaces}}} wie folgt angepasst: {{{ auto membersnetz1 iface membersnetz1 inet static bridge_ports eth0 bridge_stp off bridge_fd 0 address 83.97.41.30 gateway 83.97.41.1 netmask 255.255.255.192 }}} Damit LXC für die erzäugten Container auch ein Interface im Host erzäugt und dies der Bridge hinzufügt, muss {{{/etc/lxc/default.conf}}} angepasst werden: {{{ diff --git a/lxc/default.conf b/lxc/default.conf index 30231e3..c6bd25e 100644 --- a/lxc/default.conf +++ b/lxc/default.conf @@ -1,4 +1,6 @@ -lxc.net.0.type = empty +lxc.net.0.type = veth +lxc.net.0.link = membersnetz1 +lxc.net.0.flags = up lxc.apparmor.profile = generated lxc.apparmor.allow_nesting = 1 lxc.idmap = u 0 100000 65536 }}} = Container erstellen = Container speichern ihr Dateisystem unter {{{/var/lib/lxc//rootfs}}}. Aus diesem Grund sollte hier ein Dateisystem für den Container eingehängt werden (z.B. ein LV aus dem Dom0 durchgereicht). Da die genutzten Container unprivilegiert sind, muss das {{{download}}}-Template genutzt werden. Hier ist dann die {{{Distribution}}} (z.B.: {{{debian}}}), das {{{Release}}} (z.B.: {{{buster}}}) und die {{{Architecture}}} (z.B.: {{{amd64}}}) angegeben werden. {{{ root@containers:~# lxc-create -n name.ping.de -t download Setting up the GPG keyring Downloading the image index --- DIST RELEASE ARCH VARIANT BUILD --- alpine 3.10 amd64 default 20191221_13:00 alpine 3.10 arm64 default 20191221_13:00 alpine 3.10 armhf default 20191221_13:00 alpine 3.10 i386 default 20191221_13:01 alpine 3.10 ppc64el default 20191221_13:00 alpine 3.10 s390x default 20191221_13:00 alpine 3.11 amd64 default 20191221_13:00 alpine 3.11 arm64 default 20191221_13:00 alpine 3.11 armhf default 20191221_13:00 alpine 3.11 i386 default 20191221_13:00 alpine 3.11 ppc64el default 20191221_13:00 alpine 3.11 s390x default 20191221_13:00 alpine 3.7 amd64 default 20191220_13:00 alpine 3.7 arm64 default 20191220_13:00 alpine 3.7 armhf default 20191220_13:00 alpine 3.7 i386 default 20191220_13:00 alpine 3.8 amd64 default 20191221_13:00 alpine 3.8 arm64 default 20191221_13:00 alpine 3.8 armhf default 20191221_13:00 alpine 3.8 i386 default 20191221_13:01 alpine 3.8 ppc64el default 20191221_13:00 alpine 3.8 s390x default 20191221_13:00 alpine 3.9 amd64 default 20191221_13:00 alpine 3.9 arm64 default 20191221_13:00 alpine 3.9 armhf default 20191221_13:00 alpine 3.9 i386 default 20191221_13:01 alpine 3.9 ppc64el default 20191221_13:00 alpine 3.9 s390x default 20191221_13:00 alpine edge amd64 default 20191221_13:00 alpine edge arm64 default 20191221_13:00 alpine edge armhf default 20191221_13:00 alpine edge i386 default 20191221_13:00 alpine edge ppc64el default 20191221_13:00 alpine edge s390x default 20191221_13:00 alt Sisyphus amd64 default 20191221_01:17 alt Sisyphus arm64 default 20191221_01:17 alt Sisyphus i386 default 20191221_01:17 alt Sisyphus ppc64el default 20191221_01:17 alt p8 amd64 default 20191221_01:17 alt p8 i386 default 20191221_01:17 alt p9 amd64 default 20191221_01:17 alt p9 arm64 default 20191221_01:17 alt p9 i386 default 20191221_01:18 alt p9 ppc64el default 20191119_01:17 apertis 17.12 amd64 default 20191117_10:53 apertis 17.12 arm64 default 20191117_10:53 apertis 17.12 armhf default 20191117_10:53 apertis 18.03 amd64 default 20191117_10:53 apertis 18.03 arm64 default 20191117_10:53 apertis 18.03 armhf default 20191117_10:53 apertis 18.06 amd64 default 20191117_10:53 apertis 18.06 arm64 default 20191117_10:53 apertis 18.06 armhf default 20191117_10:53 apertis 18.09 amd64 default 20191117_10:53 apertis 18.09 arm64 default 20191117_10:53 apertis 18.09 armhf default 20191119_11:19 apertis 18.12 amd64 default 20191221_10:53 apertis 18.12 arm64 default 20191221_10:53 apertis 18.12 armhf default 20191221_10:53 archlinux current amd64 default 20191221_04:18 archlinux current arm64 default 20191221_05:17 archlinux current armhf default 20191221_05:17 centos 6 amd64 default 20191221_07:08 centos 6 i386 default 20191221_07:08 centos 7 amd64 default 20191221_07:08 centos 7 arm64 default 20191221_07:08 centos 7 armhf default 20191221_07:08 centos 7 i386 default 20191221_07:08 centos 7 ppc64el default 20191221_07:08 centos 8 amd64 default 20191221_07:08 centos 8 arm64 default 20191221_07:08 centos 8 ppc64el default 20191221_07:08 debian bullseye amd64 default 20191221_05:24 debian bullseye arm64 default 20191221_05:31 debian bullseye armel default 20191221_05:52 debian bullseye armhf default 20191221_05:24 debian bullseye i386 default 20191221_05:24 debian bullseye ppc64el default 20191221_05:24 debian bullseye s390x default 20191221_05:24 debian buster amd64 default 20191221_05:24 debian buster arm64 default 20191221_05:31 debian buster armel default 20191221_05:41 debian buster armhf default 20191221_05:38 debian buster i386 default 20191221_05:24 debian buster ppc64el default 20191221_05:24 debian buster s390x default 20191221_05:24 debian jessie amd64 default 20191221_05:24 debian jessie armel default 20191221_05:53 debian jessie armhf default 20191221_05:37 debian jessie i386 default 20191221_05:24 debian sid amd64 default 20191221_05:24 debian sid arm64 default 20191221_05:31 debian sid armel default 20191221_05:37 debian sid armhf default 20191221_05:24 debian sid i386 default 20191221_05:24 debian sid ppc64el default 20191221_05:24 debian sid s390x default 20191221_05:24 debian stretch amd64 default 20191221_05:24 debian stretch arm64 default 20191221_05:24 debian stretch armel default 20191221_05:53 debian stretch armhf default 20191221_05:42 debian stretch i386 default 20191221_05:24 debian stretch ppc64el default 20191221_05:24 debian stretch s390x default 20191221_05:24 devuan ascii amd64 default 20191221_11:50 devuan ascii arm64 default 20191221_11:50 devuan ascii armel default 20191221_11:50 devuan ascii armhf default 20191221_11:50 devuan ascii i386 default 20191221_11:50 fedora 29 amd64 default 20191220_20:33 fedora 29 arm64 default 20191220_20:33 fedora 29 armhf default 20191220_20:33 fedora 29 ppc64el default 20191220_20:33 fedora 29 s390x default 20191220_20:33 fedora 30 amd64 default 20191220_20:33 fedora 30 arm64 default 20191220_20:33 fedora 30 ppc64el default 20191220_20:33 fedora 30 s390x default 20191220_20:33 fedora 31 amd64 default 20191220_20:33 fedora 31 arm64 default 20191220_20:33 fedora 31 ppc64el default 20191220_20:33 fedora 31 s390x default 20191220_20:33 funtoo 1.3 amd64 default 20191220_16:57 funtoo 1.3 arm64 default 20191220_16:45 funtoo 1.3 armhf default 20191220_16:45 funtoo 1.3 i386 default 20191220_16:45 gentoo current amd64 default 20191221_16:07 gentoo current armhf default 20191220_16:07 gentoo current i386 default 20191221_16:07 gentoo current ppc64el default 20191221_16:07 gentoo current s390x default 20191221_16:07 kali current amd64 default 20191220_17:24 kali current arm64 default 20191220_17:14 kali current armel default 20191220_17:14 kali current armhf default 20191220_17:14 kali current i386 default 20191220_17:14 mint sarah amd64 default 20191221_08:51 mint sarah i386 default 20191221_08:51 mint serena amd64 default 20191221_08:51 mint serena i386 default 20191221_08:51 mint sonya amd64 default 20191221_08:51 mint sonya i386 default 20191221_08:51 mint sylvia amd64 default 20191221_08:51 mint sylvia i386 default 20191221_08:51 mint tara amd64 default 20191221_08:51 mint tara i386 default 20191221_08:51 mint tessa amd64 default 20191221_08:51 mint tessa i386 default 20191221_08:51 mint tina amd64 default 20191221_08:51 mint tina i386 default 20191221_08:51 mint tricia amd64 default 20191221_08:51 mint tricia i386 default 20191221_08:51 opensuse 15.0 amd64 default 20191205_04:20 opensuse 15.0 arm64 default 20191205_04:20 opensuse 15.1 amd64 default 20191221_04:20 opensuse 15.1 arm64 default 20191221_04:20 opensuse 15.1 ppc64el default 20191221_04:20 opensuse tumbleweed amd64 default 20191221_04:20 opensuse tumbleweed arm64 default 20191221_04:20 opensuse tumbleweed i386 default 20191221_04:20 opensuse tumbleweed ppc64el default 20191221_04:20 openwrt 18.06 amd64 default 20191221_11:57 openwrt current amd64 default 20190903_11:57 openwrt snapshot amd64 default 20191221_11:57 oracle 6 amd64 default 20191221_07:46 oracle 6 i386 default 20191221_07:46 oracle 7 amd64 default 20191221_07:46 oracle 8 amd64 default 20191221_07:46 plamo 6.x amd64 default 20191221_01:33 plamo 6.x i386 default 20191221_01:33 plamo 7.x amd64 default 20191221_01:33 sabayon current amd64 default 20191221_01:52 ubuntu bionic amd64 default 20191221_07:42 ubuntu bionic arm64 default 20191221_07:42 ubuntu bionic armhf default 20191221_08:03 ubuntu bionic i386 default 20191221_07:42 ubuntu bionic ppc64el default 20191221_07:42 ubuntu bionic s390x default 20191221_07:42 ubuntu cosmic amd64 default 20191029_07:42 ubuntu cosmic arm64 default 20191029_07:42 ubuntu cosmic armhf default 20191029_08:15 ubuntu cosmic i386 default 20191029_07:43 ubuntu cosmic ppc64el default 20191029_07:42 ubuntu cosmic s390x default 20191029_07:42 ubuntu disco amd64 default 20191221_07:42 ubuntu disco arm64 default 20191221_07:42 ubuntu disco armhf default 20191221_07:42 ubuntu disco i386 default 20191221_07:42 ubuntu disco ppc64el default 20191221_07:42 ubuntu disco s390x default 20191221_07:42 ubuntu eoan amd64 default 20191221_07:42 ubuntu eoan arm64 default 20191221_07:51 ubuntu eoan armhf default 20191221_07:42 ubuntu eoan i386 default 20191221_07:42 ubuntu eoan ppc64el default 20191221_07:42 ubuntu eoan s390x default 20191221_07:49 ubuntu focal amd64 default 20191221_07:42 ubuntu focal arm64 default 20191221_07:42 ubuntu focal armhf default 20191221_07:42 ubuntu focal i386 default 20191206_07:44 ubuntu focal ppc64el default 20191221_07:53 ubuntu focal s390x default 20191221_07:42 ubuntu trusty amd64 default 20191221_07:42 ubuntu trusty arm64 default 20191221_07:42 ubuntu trusty armhf default 20191221_08:03 ubuntu trusty i386 default 20191221_07:42 ubuntu trusty ppc64el default 20191221_07:55 ubuntu xenial amd64 default 20191221_07:42 ubuntu xenial arm64 default 20191221_07:42 ubuntu xenial armhf default 20191221_08:01 ubuntu xenial i386 default 20191221_07:42 ubuntu xenial ppc64el default 20191221_07:42 ubuntu xenial s390x default 20191221_07:42 voidlinux current amd64 default 20191220_17:16 voidlinux current arm64 default 20191220_17:10 voidlinux current armhf default 20191220_17:10 voidlinux current i386 default 20191220_17:10 --- Distribution: debian Release: buster Architecture: amd64 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created a Debian buster amd64 (20191221_05:24) container. To enable SSH, run: apt install openssh-server No default root or user password are set by LXC. }}} Um den Container beim Booten automaitsch starten zu lassen, muss eine Zeile zu seiner Config hinzugefügt werden: {{{ echo "lxc.start.auto = 1" >> /var/lib/lxc//config }}} Damit der Container auch Netzwerk hat, wird ganz normal seine {{{/etc/network/interfaces}}} angepasst. Z.B: {{{ cat >>/var/lib/lxc//rootfs/etc/network/interfaces < netmask 255.255.255.192 gateway 83.97.41.1 iface eth0 inet6 static address 2A00:8647:4200:4100:: netmask 64 gateway 2A00:8647:4200:4100::1 source /etc/network/interfaces.d/*.cfg EOF cat >>/var/lib/lxc//rootfs/etc/resolv.conf <