Sur la machine hôte, ouvrez /etc/network/interfaces
Déclarez une nouvelle interface en ajoutant les lignes suivantes :
auto vmbr2
iface vmbr2 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
bridge_ports none
bridge_stp off
bridge_fd 0
Puis ajouter un routage VM -> extérieur en ajoutant les lignes suivantes à l'interface :
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o vmbr0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o vmbr0 -j MASQUERADE
Ajoutez un routage pour l'interface de statistique de HaProxy :
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 1936 -j DNAT --to 10.0.0.10:1936
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 1936 -j DNAT --to 10.0.0.10:1936
Et enfin ajoutez un routage extérieur -> VM en ajoutant les lignes suivantes à l'interface :
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.0.0.10:80
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.0.0.10:80
Enregistrez vos modifications :
$ iptables-save > /etc/iptables.rules
Puis redémarrez le network :
$ /etc/init.d/networking restart
Sur la VM de routing (ici 10.0.0.10), ajoutez les backports en ajoutant la ligne suivante au fichier /etc/apt/sources.list.d/backports.list:
deb http://cdn.debian.net/debian wheezy-backports main
Puis lancez les commandes suivantes :
$ apt-get update
$ apt-get install haproxy -t wheezy-backports
Créez un fichier de backup de la configuration de HaProxy :
$ cp /etc/haproxy/haproxy.cfg{,.original}
puis éditez le fichier. Ajoutez à la fin :
listen stats *:1936
stats enable
stats uri /
stats hide-version
stats auth someuser:password