TP sysres IMA5sc 2018/2019 G8

De Wiki d'activités IMA
Révision datée du 19 novembre 2018 à 12:02 par Jsenella (discussion | contributions) (Conteneurs avec Docker)

Conteneurs à la main

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 172.26.145.100/24

Pour le mandataire inverse

ip route add default via 172.26.145.254
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

Conteneurs avec Docker

docker run -i -t debian /bin/bash
export http_proxy="http://proxy.polytech-lille.fr:3128/"
apt-get update
apt-get nano
apt-get apache2
docker commit fae2449c3b9a
docker network create octopus
docker run -i --net=octopus -t ba94e9aada65
docker run -i --net=octopus -t ba94e9aada65
service apache2 stop
docker run -i --net=octopus -p 80:80 -t ba94e9aada65
name:grandPote | type: A | adresse: 172.26.145.100
name: ptitPote1 | type: CNAME | hostname: grandPote
name: ptitPote2 | type: CNAME | hostname: grandPote

Modification de /etc/apache2/site-enabled

<VirtualHost *:80>

      ServerName Voleur1.plil.space1
      ServerAdmin webmaster@localhost
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      ProxyPass / http://172.20.0.2/
      ProxyPassReverse / http://172.20.0.2/
      ProxyRequests Off

</VirtualHost>

<VirtualHost *:80>

ServerName Voleur2.plil.space
      ServerAdmin webmaster@localhost
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      ProxyPass / http://172.20.0.3/
      ProxyPassReverse / http://172.20.0.3/
      ProxyRequests Off

</VirtualHost>