2016-12-29 11:25:39 +01:00
|
|
|
**Cette page a été importée automatiquement de notre ancien wiki mais n'a pas encore été révisée.**
|
|
|
|
|
|
|
|
# HowtoLXC
|
|
|
|
|
|
|
|
## Debian 8 (JESSIE)
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
~~~
|
|
|
|
# apt install lxc bridge-utils libvirt-bin debootstrap
|
|
|
|
~~~
|
|
|
|
|
|
|
|
## Modifications réseau
|
2017-01-03 11:20:35 +01:00
|
|
|
|
2016-12-29 11:25:39 +01:00
|
|
|
~~~
|
|
|
|
# cat /etc/network/interfaces
|
|
|
|
[...]
|
|
|
|
auto br0
|
|
|
|
iface br0 inet static
|
|
|
|
bridge_ports eth0
|
|
|
|
bridge_fd 0
|
|
|
|
bridge_maxwait 0
|
|
|
|
address 10.10.10.42
|
|
|
|
netmask 255.255.255.0
|
|
|
|
gateway 10.10.10.254
|
|
|
|
|
|
|
|
auto br1
|
|
|
|
iface br1 inet static
|
|
|
|
pre-up brctl addbr br1
|
|
|
|
address 10.1.0.254
|
|
|
|
netmask 255.255.255.0
|
|
|
|
bridge_fd 0
|
|
|
|
post-down brctl delbr br1
|
|
|
|
~~~
|
|
|
|
|
|
|
|
~~~
|
2017-01-03 11:20:35 +01:00
|
|
|
# /sbin/iptables -A INPUT -p tcp --sport 11371 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
|
|
# /sbin/iptables -t nat -A POSTROUTING -s 10.1.0.254/24 -o br0 -j SNAT --to *IP de l'hyperviseur*
|
2016-12-29 11:25:39 +01:00
|
|
|
~~~
|
2017-01-03 11:20:35 +01:00
|
|
|
|
|
|
|
Activation du forwarding
|
|
|
|
|
2016-12-29 11:25:39 +01:00
|
|
|
~~~
|
|
|
|
# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
|
|
|
|
# echo "net.ipv4.conf.all.arp_announce=2" >> /etc/sysctl.conf
|
|
|
|
# echo "net.ipv4.conf.all.arp_ignore=1" >> /etc/sysctl.conf
|
|
|
|
# echo "net.ipv4.conf.all.rp_filter=0" >> /etc/sysctl.conf
|
|
|
|
# sysctl -w net.ipv4.ip_forward=1
|
|
|
|
# sysctl -w net.ipv4.conf.all.rp_filter=0
|
|
|
|
# sysctl -w net.ipv4.conf.all.arp_ignore=1
|
|
|
|
# sysctl -w net.ipv4.conf.all.arp_announce=2
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
|
|
## Installation d'un container
|
|
|
|
|
|
|
|
~~~
|
|
|
|
# lxc-create -t download -n test
|
|
|
|
~~~
|
|
|
|
|
2017-01-03 11:20:35 +01:00
|
|
|
Avant de démarrer la VM mettre ces lignes dans le fichier de conf du conteneur : ``/var/lib/lxc/test/config`
|
2016-12-29 11:25:39 +01:00
|
|
|
|
|
|
|
~~~
|
|
|
|
lxc.network.type = veth
|
|
|
|
lxc.network.link = br1
|
|
|
|
lxc.network.ipv4 = 10.1.0.X/24
|
|
|
|
lxc.network.ipv4.gateway = 10.1.0.254
|
|
|
|
lxc.network.name = eth0
|
|
|
|
lxc.network.flags = up
|
|
|
|
~~~
|
|
|
|
|
|
|
|
(Il est conseillé de supprimer systemd du container car ce dernier est mal géré pour le moment)
|
2017-01-03 11:20:35 +01:00
|
|
|
|
2016-12-29 11:25:39 +01:00
|
|
|
~~~
|
|
|
|
# apt install sysvinit-core
|
|
|
|
~~~
|
|
|
|
|
|
|
|
## Utilisation
|
|
|
|
|
|
|
|
Démarrer un conteneur :
|
2017-01-03 11:20:35 +01:00
|
|
|
|
|
|
|
~~~
|
2016-12-29 11:25:39 +01:00
|
|
|
# lxc-start -n test -d
|
2017-01-03 11:20:35 +01:00
|
|
|
~~~
|
2016-12-29 11:25:39 +01:00
|
|
|
|
|
|
|
Entrer dans un conteneur :
|
2017-01-03 11:20:35 +01:00
|
|
|
|
|
|
|
~~~
|
2016-12-29 11:25:39 +01:00
|
|
|
# lxc-attach -n test
|
2017-01-03 11:20:35 +01:00
|
|
|
~~~
|
2016-12-29 11:25:39 +01:00
|
|
|
|
|
|
|
Arreter un conteneur :
|
2017-01-03 11:20:35 +01:00
|
|
|
|
|
|
|
~~~
|
2016-12-29 11:25:39 +01:00
|
|
|
# lxc-stop -n test
|
|
|
|
~~~
|
|
|
|
|
2017-01-03 11:20:35 +01:00
|
|
|
Autres commandes utiles :
|
|
|
|
|
2016-12-29 11:25:39 +01:00
|
|
|
~~~
|
|
|
|
# lxc-info -n test-container
|
|
|
|
# lxc-console -n test-container
|
|
|
|
# lxc-halt -n test-container
|
|
|
|
# lxc-info -n test-container
|
|
|
|
# lxc-destroy -n test-container
|
2017-01-03 11:20:35 +01:00
|
|
|
~~~
|