TP sysres IMA5sc 2018/2019 G8
De Wiki d'activités IMA
Révision datée du 19 novembre 2018 à 10:03 par Jsenella (discussion | contributions) (→TP conteneurs)
Sommaire
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
Pour le mandataire inverse
ip route add default via 172.26.145.254
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 172.26.145.100/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
Création des DNS sur Gandi
name:grandPote | type: A | adresse: 172.26.145.100
name: ptitPote1 | type: CNAME | hostname: grandPote name: ptitPote2 | type: CNAME | hostname: grandPote
a2enmod proxy proxy_http apache2 restart
Modification de /etc/apache2/site-enabled
<VirtualHost *:80> ServerName ptitPote1.plil.space ServerAdmin webmaster@localhost ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ProxyPass / http://192.168.0.102/ ProxyPassReverse / http://192.168.0.102/ ProxyRequests Off </VirtualHost>
<VirtualHost *:80> ServerName ptitPote2.plil.space ServerAdmin webmaster@localhost ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ProxyPass / http://192.168.0.103/ ProxyPassReverse / http://192.168.0.103/ ProxyRequests Off </VirtualHost>
Modification des fichiers /var/www/html/index.html dans les conteneurs
/var/www/html# echo "Serveur ptitPote1" > index.html /var/www/html# echo "Serveur ptitPote2" > index.html
10h11 => Serveurs Web OK avec unshare