TP sysres IMA5sc 2018/2019 G8 : Différence entre versions

De Wiki d'activités IMA
(Page créée avec « ==TP conteneurs== »)
 
(TP conteneurs)
Ligne 1 : Ligne 1 :
 
==TP conteneurs==
 
==TP conteneurs==
 +
===Création des espaces disques===
 +
 +
dd if=/dev/zero of=diskTPconteneur bs=1024k count=10240
 +
mkfs diskTPconteneur
 +
 +
mkdir /tmp/fs1
 +
mkdir /tmp/fs2
 +
mkdir /tmp/fs3
 +
 +
mount -o loop diskTPconteneur /tmp/fs1
 +
debootstrap --include apache2,nano  stable /tmp/fs1
 +
echo "proc /proc proc defaults 0 0" >> /tmp/fs1/etc/fstab
 +
 +
umount /tmp/fs1
 +
cp diskTPconteneur ./diskTPconteneur2
 +
cp diskTPconteneur ./diskTPconteneur3
 +
mv diskTPconteneur ./diskTPconteneur1
 +
 +
mount -o loop diskTPconteneur1 /tmp/fs1
 +
mount -o loop diskTPconteneur2 /tmp/fs2
 +
mount -o loop diskTPconteneur3 /tmp/fs3
 +
df -h
 +
 +
Dans 3 terminaux différents:
 +
unshare -p -f -m -n -u chroot /tmp/fs1/ /bin/sh -c "mount /proc ; /bin/bash"
 +
unshare -p -f -m -n -u chroot /tmp/fs2/ /bin/sh -c "mount /proc ; /bin/bash"
 +
unshare -p -f -m -n -u chroot /tmp/fs3/ /bin/sh -c "mount /proc ; /bin/bash"
 +
 +
===Création du commutateur===
 +
 +
ip link add commTPconteneur type bridge
 +
 +
ip link add vif1 type veth peer name eth0@vif1
 +
ip link add vif2 type veth peer name eth0@vif2
 +
ip link add vif3 type veth peer name eth0@vif3
 +
ip link add vif4 type veth peer name eth1@vif4
 +
 +
ps aux | grep unshare
 +
ip link set eth0@vif1 netns /proc/13812/ns/net name eth0
 +
ip link set eth0@vif2 netns /proc/13860/ns/net name eth0
 +
ip link set eth0@vif3 netns /proc/13883/ns/net name eth0
 +
ip link set eth1@vif4 netns /proc/13812/ns/net name eth1
 +
 +
ip link set vif1 master commTPconteneur
 +
ip link set vif2 master commTPconteneur
 +
ip link set vif3 master commTPconteneur
 +
ip link set vif4 master bridge
 +
brctl show
 +
 +
nsenter -t 13812 -n ip address add dev eth0 192.168.0.101/24
 +
nsenter -t 13860 -n ip address add dev eth0 192.168.0.102/24
 +
nsenter -t 13883 -n ip address add dev eth0 192.168.0.103/24
 +
nsenter -t 13812 -n ip address add dev eth1 192.168.0.104/24
 +
 +
ip link set vif1 up
 +
ip link set vif2 up
 +
ip link set vif3 up
 +
ip link set vif4 up
 +
ip link set commTPconteneur up
 +
 +
Dans chaque terminal faisant tourner un conteneur:
 +
ip link set eth0 up

Version du 12 novembre 2018 à 12:16

TP conteneurs

Création des espaces disques

dd if=/dev/zero of=diskTPconteneur bs=1024k count=10240 mkfs diskTPconteneur

mkdir /tmp/fs1 mkdir /tmp/fs2 mkdir /tmp/fs3

mount -o loop diskTPconteneur /tmp/fs1 debootstrap --include apache2,nano stable /tmp/fs1 echo "proc /proc proc defaults 0 0" >> /tmp/fs1/etc/fstab

umount /tmp/fs1 cp diskTPconteneur ./diskTPconteneur2 cp diskTPconteneur ./diskTPconteneur3 mv diskTPconteneur ./diskTPconteneur1

mount -o loop diskTPconteneur1 /tmp/fs1 mount -o loop diskTPconteneur2 /tmp/fs2 mount -o loop diskTPconteneur3 /tmp/fs3 df -h

Dans 3 terminaux différents: unshare -p -f -m -n -u chroot /tmp/fs1/ /bin/sh -c "mount /proc ; /bin/bash" unshare -p -f -m -n -u chroot /tmp/fs2/ /bin/sh -c "mount /proc ; /bin/bash" unshare -p -f -m -n -u chroot /tmp/fs3/ /bin/sh -c "mount /proc ; /bin/bash"

Création du commutateur

ip link add commTPconteneur type bridge

ip link add vif1 type veth peer name eth0@vif1 ip link add vif2 type veth peer name eth0@vif2 ip link add vif3 type veth peer name eth0@vif3 ip link add vif4 type veth peer name eth1@vif4

ps aux | grep unshare ip link set eth0@vif1 netns /proc/13812/ns/net name eth0 ip link set eth0@vif2 netns /proc/13860/ns/net name eth0 ip link set eth0@vif3 netns /proc/13883/ns/net name eth0 ip link set eth1@vif4 netns /proc/13812/ns/net name eth1

ip link set vif1 master commTPconteneur ip link set vif2 master commTPconteneur ip link set vif3 master commTPconteneur ip link set vif4 master bridge brctl show

nsenter -t 13812 -n ip address add dev eth0 192.168.0.101/24 nsenter -t 13860 -n ip address add dev eth0 192.168.0.102/24 nsenter -t 13883 -n ip address add dev eth0 192.168.0.103/24 nsenter -t 13812 -n ip address add dev eth1 192.168.0.104/24

ip link set vif1 up ip link set vif2 up ip link set vif3 up ip link set vif4 up ip link set commTPconteneur up

Dans chaque terminal faisant tourner un conteneur: ip link set eth0 up