Ceci est une ancienne révision du document !
Installation d'un hôte sous CentOS 5 pour héberger des machines virtuelles
Configuration des dépôts
Configurer les dépôts RPMForge, EPEL, ATRpms, fws et lfarkas (voir cette page)
Installation des outils de base
Certains outils sont indispensables
yum --enablerepo=rpmforge install htop screen strace
Installation des outils de virtualisation
yum install kvm
Puis:
yum --enablerepo=fws install perl-Sys-Virt libvirt
: il y'a un problème avec le dépôt, pour l'instant, il faut télécharger les rpm puis yum localinstall…
yum --enablerepo=epel install pbzip2
Désactivation de SELinux
SELinux pose encore des problèmes pour la virtualisation. Notamment: https://bugzilla.redhat.com/show_bug.cgi?id=484199. En attendant une résolution, il faut configurer SELinux en mode permissive en éditant le fichier /etc/selinux/config
Configuration de l'interface "interne" en mode bridge
Pour pouvoir connecter les VM sur le réseau local (ou les réseau locaux à l'hôte physique, il peut s'agir de DMZ, ou n'importe quel sous-réseau connecté à l'hôte physique), il faut que ces interfaces fassent partie d'un bridge (=switch virtuel)
cd /etc/sysconfig/network-scripts cat <<EOF > ifcfg-eth0 DEVICE=eth0 HWADDR=00:16:76:D6:C9:45 ONBOOT=yes BRIDGE=br0 EOF
En adaptant l'adresse mac (ici 00:16:76:D6:C9:45)
- Pour un bridge configuré via DHCP:
cat <<EOF > ifcfg-br0 DEVICE=br0 TYPE=Bridge BOOTPROTO=dhcp ONBOOT=yes DELAY=0 EOF
- Pour une configuration en IP fixe
cat <<EOF > ifcfg-br0 DEVICE=br0 TYPE=Bridge BOOTPROTO=static IPADDR=192.168.7.2 NETMASK=255.255.255.0 BROADCAST=192.168.7.255 NETWORK=192.168.7.0 ONBOOT=yes DELAY=0 EOF
Connexion distante à libvirt
Le plus simple est d'utiliser un tunnel SSH. Pour cela, nous allons utiliser un compte avec des privilèges réduits:
Création d'un utilisateur aux privilèges réduits
groupadd libvirt useradd -c 'Firewall Services' -m -d /home/fws -s /bin/bash fws usermod -a -G libvirt fws
Ajustement des permissions du socket
Éditer le fichier /etc/libvirt/libvirtd.conf et dé-commenter les lignes unix_sock_group et unix_sock_rw_perms
################################################################# # # UNIX socket access controls # # Set the UNIX domain socket group ownership. This can be used to # allow a 'trusted' set of users access to management capabilities # without becoming root. # # This is restricted to 'root' by default. unix_sock_group = "libvirt" # Set the UNIX socket permissions for the R/O socket. This is used # for monitoring VM status only # # Default allows any user. If setting group ownership may want to # restrict this to: #unix_sock_ro_perms = "0777" # Set the UNIX socket permissions for the R/W socket. This is used # for full management of VMs # # Default allows only root. If PolicyKit is enabled on the socket, # the default will change to allow everyone (eg, 0777) # # If not using PolicyKit and setting group ownership for access # control then you may want to relax this to: unix_sock_rw_perms = "0770" # Set the name of the directory in which sockets will be found/created. #unix_sock_dir = "/var/run/libvirt" #################################################################
Ces modifications permettent à tout les utilisateurs membre du groupe libvirt de contrôler entièrement libvirt (accès rw sur le socket rw). Pour appliquer les changements, il faut redémarrer libvirt:
/etc/init.d/libvirtd restart
Mettre en place une authentification SSH par clef (sans mot de passe)
su - fws cd mkdir -p .ssh chmod 700 .ssh touch .ssh/authorized_keys chmod 600 .ssh/authorized_keys
Puis placer votre clef publique dans le fichier authorized_keys