lxc
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
lxc [2019/10/18 18:56] – [Cas pratiques] simon | lxc [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== LXC ====== | ||
- | ===== Installation ===== | ||
- | Sur ubuntu : | ||
- | <code bash> | ||
- | # apt install lxc-utils lxcfs | ||
- | </ | ||
- | |||
- | ===== Voir les images utilisables ===== | ||
- | Il y a de nombreuses images téléchargeables pour servir de base. | ||
- | <code bash> | ||
- | $ sudo lxc-create -t download -n cequonveut | ||
- | Setting up the GPG keyring | ||
- | Downloading the image index | ||
- | |||
- | --- | ||
- | DIST RELEASE ARCH VARIANT BUILD | ||
- | --- | ||
- | (...) | ||
- | alpine edge amd64 default 20190918_13: | ||
- | (...) | ||
- | centos 6 amd64 default 20190919_07: | ||
- | (...) | ||
- | debian buster amd64 default 20190919_05: | ||
- | (...) | ||
- | </ | ||
- | |||
- | ===== Télécharger une image ===== | ||
- | Téléchargement d'un Debian Buster (amd64) : | ||
- | <code bash> | ||
- | $ sudo lxc-create -t download -n buster-base -- --dist debian --release buster --arch amd64 | ||
- | </ | ||
- | < | ||
- | <code bash> | ||
- | Setting up the GPG keyring | ||
- | 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 (20190919_05: | ||
- | |||
- | To enable SSH, run: apt install openssh-server | ||
- | No default root or user password are set by LXC. | ||
- | |||
- | $ sudo lxc-create -t download -n stretch-base -- --dist debian --release stretch --arch amd64 | ||
- | Setting up the GPG keyring | ||
- | Downloading the image index | ||
- | Downloading the rootfs | ||
- | Downloading the metadata | ||
- | The image cache is now ready | ||
- | Unpacking the rootfs | ||
- | |||
- | --- | ||
- | You just created a Debian stretch amd64 (20190919_05: | ||
- | |||
- | To enable SSH, run: apt install openssh-server | ||
- | No default root or user password are set by LXC. | ||
- | </ | ||
- | </ | ||
- | ===== Voir les images téléchargées sur l' | ||
- | <code bash> | ||
- | $ sudo lxc-ls -f | ||
- | NAME STATE | ||
- | buster-base | ||
- | stretch-base | ||
- | </ | ||
- | |||
- | ===== Supprimer une image ===== | ||
- | <code bash> | ||
- | $ sudo lxc-destroy NOM-IMAGE | ||
- | </ | ||
- | ===== Démarrer un container LXC ===== | ||
- | <code bash> | ||
- | $ sudo lxc-start -n stretch-base | ||
- | </ | ||
- | |||
- | On peut vérifier : | ||
- | <code bash> | ||
- | $ sudo lxc-ls -f | ||
- | NAME STATE | ||
- | buster-base | ||
- | stretch-base | ||
- | </ | ||
- | |||
- | ===== Arrêter un container LXC ===== | ||
- | <code bash> | ||
- | $ sudo lxc-stop -n stretch-base | ||
- | </ | ||
- | ===== Se connecter à un conteneur LXC ===== | ||
- | <code bash> | ||
- | $ sudo lxc-attach -n stretch-base | ||
- | root@stretch-base:/# | ||
- | </ | ||
- | |||
- | ===== Configurer un conteneur en " | ||
- | Il faut rajouter une ligne dans sa configuration : | ||
- | <code bash> | ||
- | $ sudo vim / | ||
- | (...) | ||
- | lxc.start.auto = 1 | ||
- | (...) | ||
- | </ | ||
- | |||
- | Et redémarrer le conteneur. | ||
- | ===== Du réseau dans le conteneur ===== | ||
- | Sources : | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | |||
- | ==== Configuration de base (dhcp) ==== | ||
- | |||
- | <WRAP center round important 60%> | ||
- | J'ai eu des problèmes parce que Bind9 était installé ! Pour vérifier : | ||
- | <code bash> | ||
- | $ sudo netstat -lnp | grep ":53 " | ||
- | </ | ||
- | |||
- | S'il y a des lignes aec " | ||
- | <code bash> | ||
- | $ sudo netstat -lnp | grep ":53 " | ||
- | tcp 0 0 10.0.3.1: | ||
- | udp 0 0 10.0.3.1: | ||
- | </ | ||
- | </ | ||
- | |||
- | Il faut installer [[dnsmasq-base]] avant tout chose. | ||
- | <code bash> | ||
- | $ sudo apt remove bind9 | ||
- | |||
- | $ sudo apt install dnsmasq-base | ||
- | |||
- | $ sudo cat / | ||
- | USE_LXC_BRIDGE=" | ||
- | |||
- | $ sudo / | ||
- | lxc.net.0.type = veth | ||
- | lxc.net.0.link = lxcbr0 | ||
- | lxc.net.0.flags = up | ||
- | lxc.net.0.hwaddr = 00: | ||
- | |||
- | $ sudo systemctl enable lxc-net.service | ||
- | |||
- | $ sudo systemctl start lxc-net.service | ||
- | |||
- | $ sudo systemctl status lxc-net | ||
- | ● lxc-net.service - LXC network bridge setup | ||
- | | ||
- | | ||
- | Process: 7297 ExecStart=/ | ||
- | Main PID: 7297 (code=exited, | ||
- | | ||
- | | ||
- | | ||
- | |||
- | oct. 07 08:41:40 ns334000 lxc-net[7297]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq-dhcp[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq-dhcp[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 dnsmasq[7330]: | ||
- | oct. 07 08:41:41 ns334000 systemd[1]: Started LXC network bridge setup. | ||
- | |||
- | $ sudo systemctl restart lxc | ||
- | |||
- | $ sudo systemctl status lxc | ||
- | ● lxc.service - LXC Container Initialization and Autoboot Code | ||
- | | ||
- | | ||
- | Docs: man: | ||
- | | ||
- | Process: 7620 ExecStartPre=/ | ||
- | Process: 7621 ExecStart=/ | ||
- | Main PID: 7621 (code=exited, | ||
- | |||
- | oct. 07 08:56:53 ns334000 systemd[1]: Starting LXC Container Initialization and Autoboot Code... | ||
- | oct. 07 08:56:53 ns334000 systemd[1]: Started LXC Container Initialization and Autoboot Code. | ||
- | </ | ||
- | |||
- | __Notes :__ Il y a des exemples dans la doc : | ||
- | <code bash> | ||
- | $ sudo cat / | ||
- | # Container with network virtualized using a pre-configured bridge named br0 and | ||
- | # veth pair virtual network devices | ||
- | lxc.uts.name = beta | ||
- | lxc.net.0.type = veth | ||
- | lxc.net.0.flags = up | ||
- | lxc.net.0.link = br0 | ||
- | lxc.net.0.hwaddr = 4a: | ||
- | lxc.net.0.ipv4.address = 10.2.3.5/24 | ||
- | lxc.net.0.ipv6.address = 2003: | ||
- | </ | ||
- | |||
- | ==== IP statique (dhcp) ==== | ||
- | __Source :__ [[https:// | ||
- | |||
- | On ajoute une ligne dans ''/ | ||
- | <code bash> | ||
- | $ sudo cat / | ||
- | USE_LXC_BRIDGE=" | ||
- | LXC_DHCP_CONFILE=/ | ||
- | |||
- | $ sudo cat / | ||
- | dhcp-host=caliban, | ||
- | </ | ||
- | |||
- | On commente la ligne concernant l'ip fixe dans la configuration du conteneur : | ||
- | <code bash> | ||
- | # cat / | ||
- | (...) | ||
- | # Network configuration | ||
- | lxc.net.0.type = veth | ||
- | lxc.net.0.link = lxcbr0 | ||
- | lxc.net.0.flags = up | ||
- | lxc.net.0.hwaddr = 00: | ||
- | # | ||
- | </ | ||
- | |||
- | On éteint le conteneur et on redémarre le service lxc-net : | ||
- | <code bash> | ||
- | $ sudo lxc-stop buster-base | ||
- | |||
- | $ sudo systemctl restart lxc-net | ||
- | |||
- | $ sudo systemctl status lxc-net | ||
- | ● lxc-net.service - LXC network bridge setup | ||
- | (...) | ||
- | | ||
- | | ||
- | (...) | ||
- | |||
- | $ sudo lxc-start buster-base | ||
- | | ||
- | $ sudo lxc-ls -f | ||
- | NAME STATE | ||
- | buster-base RUNNING 0 | ||
- | </ | ||
- | |||
- | Et voilà, notre conteneur " | ||
- | ===== La configuration de chaque conteneur ===== | ||
- | Chaque conteneur a sa configuration dans ce dossier : | ||
- | <code bash> | ||
- | $ sudo ls -al / | ||
- | total 16 | ||
- | drwxrwx--- | ||
- | drwxr-xr-x | ||
- | -rw-r----- | ||
- | drwxr-xr-x 21 root root 4096 oct. 7 08:40 rootfs | ||
- | |||
- | $ sudo cat / | ||
- | # Template used to create this container: / | ||
- | # Parameters passed to the template: --dist debian --release buster --arch amd64 | ||
- | # Template script checksum (SHA-1): 273c51343604eb85f7e294c8da0a5eb769d648f3 | ||
- | # For additional config options, please look at lxc.container.conf(5) | ||
- | |||
- | # Uncomment the following line to support nesting containers: | ||
- | # | ||
- | # (Be aware this has security implications) | ||
- | |||
- | # Distribution configuration | ||
- | lxc.include = / | ||
- | lxc.arch = linux64 | ||
- | |||
- | # Container specific configuration | ||
- | lxc.rootfs.path = dir:/ | ||
- | lxc.uts.name = buster-base | ||
- | |||
- | # Network configuration | ||
- | lxc.net.0.type = veth | ||
- | lxc.net.0.link = lxcbr0 | ||
- | lxc.net.0.flags = up | ||
- | lxc.net.0.hwaddr = 00: | ||
- | </ | ||
- | |||
- | C'est donc là qu'on peut faire les configurations spécifiques à chaque conteneur ! | ||
- | |||
- | ===== Le rootfs de chaque conteneur ===== | ||
- | On a vu juste au dessus où se trouvait la configuration spécifique de chaque conteneur. C'est également dans ce dossier qu'il y a le **rootfs** de chaque conteneur : | ||
- | |||
- | <code bash> | ||
- | $ sudo ls -al / | ||
- | total 84 | ||
- | drwxr-xr-x 21 root root 4096 oct. 7 08:40 . | ||
- | drwxrwx--- | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x 40 root root 4096 oct. 7 08:40 etc | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x 10 root root 4096 oct. 6 05:26 lib | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwx------ | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxr-xr-x | ||
- | drwxrwxrwt | ||
- | drwxr-xr-x 10 root root 4096 oct. 6 05:25 usr | ||
- | drwxr-xr-x 11 root root 4096 oct. 6 05:25 var | ||
- | </ | ||
- | |||
- | Bon à savoir pour les sauvegardes ! | ||
- | ===== Déplacer un conteneur ===== | ||
- | <code bash> | ||
- | $ sudo lxc-stop -n monconteneur | ||
- | |||
- | $ su | ||
- | |||
- | $ cd / | ||
- | |||
- | # tar --numeric-owner -czvf monconteneur_fs.tar.gz ./* | ||
- | |||
- | # ll | ||
- | total 208692 | ||
- | -rw-r----- | ||
- | -rw-r--r-- | ||
- | drwxr-xr-x 21 root root 4096 oct 10 11:43 rootfs | ||
- | </ | ||
- | |||
- | On copie dans le dossier de l' | ||
- | <code bash> | ||
- | # mv monconteneur_fs.tar.gz / | ||
- | |||
- | # chown simon:simon / | ||
- | </ | ||
- | |||
- | On repasse en utilisateur " | ||
- | <code bash> | ||
- | $ scp / | ||
- | </ | ||
- | |||
- | Sur le serveur : | ||
- | <code bash> | ||
- | $ simon@192.168.14.12 | ||
- | |||
- | simon@server: | ||
- | |||
- | root@server:/ | ||
- | |||
- | root@server:/ | ||
- | |||
- | root@server:/ | ||
- | |||
- | root@server:/ | ||
- | monconteneur_fs.tar.gz | ||
- | |||
- | root@server:/ | ||
- | |||
- | root@server:/ | ||
- | config monconteneur_fs.tar.gz rootfs | ||
- | |||
- | root@ns334000:/ | ||
- | NAME STATE | ||
- | (...) | ||
- | monconteneur | ||
- | |||
- | root@ns334000:/ | ||
- | |||
- | root@ns334000:/ | ||
- | NAME STATE | ||
- | (...) | ||
- | monconteneur | ||
- | |||
- | root@server:/ | ||
- | root@monconteneur:/# | ||
- | </ | ||
- | |||
- | __Source :__ [[https:// | ||
- | |||
- | |||
- | ===== Cas pratiques ===== | ||
- | * [[Le site de caliban.be dans LXC]] | ||
- | * [[Nextcloud dans LXC]] | ||
- | ===== Soucis rencontrés ===== | ||
- | ==== Locales ==== | ||
- | <code bash> | ||
- | perl: warning: Setting locale failed. | ||
- | perl: warning: Please check that your locale settings: | ||
- | LC_ALL = (unset), | ||
- | LANG = " | ||
- | are supported and installed on your system. | ||
- | perl: warning: Falling back to the standard locale (" | ||
- | </ | ||
- | |||
- | Solution : | ||
- | <code bash> | ||
- | # dpkg-reconfigure locales | ||
- | </ | ||
- | ===== Sources ===== | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[https:// |
lxc.1571425018.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)