« Virt/LibVirt » : différence entre les versions

De TartareFR
Aller à la navigation Aller à la recherche
 
(Une version intermédiaire par le même utilisateur non affichée)
Ligne 7 : Ligne 7 :
Activation du service au démarrage
Activation du service au démarrage
  # systemctl enable libvirtd.service
  # systemctl enable libvirtd.service
== Interface graphique ==
virt-manager
[[Fichier:ScreenshotVirtManager.png|Screenshot de virt-manager]]
== Ligne de commande ==
<code>virt-install</code> is a command line based tool for creating virtualized guests. To start the interactive install process, run the <code>virt-install</code> command with the --prompt parameter.
<pre>
su -c "/usr/bin/virt-install --prompt"
</pre>
The following questions for the new guest will be presented.
# What is the name of your virtual machine? This is the label that will identify the guest OS. This label is used with <code>virsh</code> commands and <code>virt-manager</code>(Virtual Machine Manager).
# How much RAM should be allocated (in megabytes)? This is the amount of RAM to be allocated for the guest instance in megabytes (eg, 256). Note that installation with less than 256 megabytes is not recommended.
# What would you like to use as the disk (path)? The local path and file name of the file to serve as the disk image for the guest (eg, /var/lib/libvirt/images/name.img). This will be exported as a full disk to your guest. It's best to specify the default /var/lib/libvirt/images/ directory.
# How large would you like the disk to be (in gigabytes)? The size of the virtual disk for the guest (only appears if the file specified above does not already exist). 4.0 gigabytes is a reasonable size for a "default" install
# What is the install CD-ROM/ISO or URL?  This is the path to a Fedora installation tree in the format used by anaconda.  NFS, FTP, and HTTP locations are all supported.  Examples include:
#* <code>nfs:my.nfs.server.com:/path/to/test2/tree/</code>
#* <code><nowiki>http://my.http.server.com/path/to/tree/</nowiki></code>
#* <code><nowiki>ftp://my.ftp.server.com/path/to/tree</nowiki></code>
These options can be passed as command line options, execute <code>virt-install --help</code> for details.
<code>virt-install</code> can use kickstart files, for example
<code>virt-install -x ks=kickstart-file-name.ks</code>.
If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, a text installer will appear. Proceed with the fedora installation.
==== Creating a guest with virt-manager ====
Start the GUI Virtual Machine Manager by selecting it from the "Applications-->System Tools" menu, or by running the following command:
<pre>
su -c "virt-manager"
</pre>
If you encounter an error along the lines of "Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash", trying running <code>virt-manager</code> not as root (without the <code>su -c</code>).  The GUI will prompt for the root password.
# Open a connection to a hypervisor by choosing File-->Add connection...
# Choose "qemu" for KVM, or "Xen" for Xen.
# Choose "local" or select a method to connect to a remote hypervisor
# After a connection is opened, click the new icon next to the hypervisor, or right click on the active hypervisor and select "New" (Note - the new icon is going to be improved to make it easier to see)
# A wizard will present the same questions as appear with the <code>virt-install</code> command-line utility (see descriptions above). The wizard assumes that a graphical installation is desired and does not prompt for this option.
# On the last page of the wizard there is a "Finish" button. When this is clicked, the guest OS is provisioned. After a few moments a VNC window should appear. Proceed with the installation as normal.
=== Remote management ===
The following remote management options are available:
* (easiest) If using non-root users via SSH, then setup instructions are at: http://wiki.libvirt.org/page/SSHSetup
* If using root for access via SSH, then create SSH keys for root, and use <code>ssh-agent</code> and <code>ssh-add</code> before launching <code>virt-manager</code>.
* To use TLS, set up a local certificate authority and issue x509 certs to all servers and clients. For information on configuring this option, refer to http://wiki.libvirt.org/page/TLSSetup.
=== Guest system administration ===
When the installation of the guest operating system is complete, it can be managed using the GUI <code>virt-manager</code> program or on the command line using <code>virsh</code>.
==== Managing guests with virt-manager ====
Start the Virtual Machine Manager. Virtual Machine Manager is in the "Applications-->System Tools" menu, or execute:
<pre>
su -c "virt-manager"
</pre>
{1} If you are not root, you will be prompted to enter the root password. Choose<code>Run unprivileged</code> to operate in a read-only non-root mode.
* Choose the host you wish to manage and click "Connect" in the "Open Connection" dialog window.
* The list of virtual machines is displayed in the main window. Guests that are running will display a ">" icon. Guests that are not running will be greyed out.
* To manage a particular guest, double click on it, or right click and select "Open".
* A new window for the guest will open that will allow you to use its console, see information about its virtual hardware and start/stop/pause it.
For further information about <code>virt-manager</code> consult the [http://virt-manager.et.redhat.com/ project website]
Bugs in the <code>virt-manager</code> tool should be reported in [http://bugzilla.redhat.com BugZilla]  against the 'virt-manager' component
==== Managing guests with virsh ====
The <code>virsh</code> command line utility that allows you to manage virtual machines.
Guests can be managed on the command line with the <code>virsh</code> utility. The <code>virsh</code> utility is built around the libvirt management APIl:
* <code>virsh</code> has a stable set of commands whose syntax and semantics are preserved across updates to the underlying virtualization platform.
* <code>virsh</code> can be used as an unprivileged user for read-only operations (e.g. listing domains, listing domain statistics).
* <code>virsh</code> can manage domains running under Xen, Qemu/KVM, esx or other backends with no perceptible difference to the user
{{Admon/note | A valid URI may be passed to <code>virsh</code> with "-c' to connect to a remote libvirtd instance. For details, see http://libvirt.org/uri.html}}
To start a virtual machine:
<pre>
su -c "virsh create <name of virtual machine>"
</pre>
To list the virtual machines currently running:
<pre>
su -c "virsh list"
</pre>
To list all virtual machines, running or not:
<pre>
su -c "virsh list --all"
</pre>
To gracefully power off a guest:
<pre>
su -c "virsh shutdown <virtual machine (name | id | uuid)>"
</pre>
To non gracefully power off a guest:
<pre>
su -c "virsh destroy <virtual machine (name | id | uuid)>"
</pre>
To save a snapshot of the machine to a file:
<pre>
su -c "virsh save <virtual machine (name | id | uuid)> <filename>"
</pre>
To restore a previously saved snapshot:
<pre>
su -c "virsh restore <filename>"
</pre>
To export the configuration file of a virtual machine:
<pre>
su -c "virsh dumpxml <virtual machine (name | id | uuid)"
</pre>
For a complete list of commands available for use with <code>virsh</code>:
<pre>
su -c "virsh help"
</pre>
Or consult the manual page: <code>man 1 virsh</code>
Bugs in the <code>virsh</code> tool should be reported in [http://bugzilla.redhat.com BugZilla]  against the 'libvirt' component.
[[Category:Documentation]]
[[Category:Virtualisation]]

Dernière version du 11 février 2013 à 17:36

Installation

# yum install qemu-kvm libvirt virt-manager fence-virt libvirt-daemon-qemu

Démarrage du service

# systemctl start libvirtd.service

Activation du service au démarrage

# systemctl enable libvirtd.service

Interface graphique

virt-manager

Screenshot de virt-manager

Ligne de commande

virt-install is a command line based tool for creating virtualized guests. To start the interactive install process, run the virt-install command with the --prompt parameter.

su -c "/usr/bin/virt-install --prompt"

The following questions for the new guest will be presented.

  1. What is the name of your virtual machine? This is the label that will identify the guest OS. This label is used with virsh commands and virt-manager(Virtual Machine Manager).
  2. How much RAM should be allocated (in megabytes)? This is the amount of RAM to be allocated for the guest instance in megabytes (eg, 256). Note that installation with less than 256 megabytes is not recommended.
  3. What would you like to use as the disk (path)? The local path and file name of the file to serve as the disk image for the guest (eg, /var/lib/libvirt/images/name.img). This will be exported as a full disk to your guest. It's best to specify the default /var/lib/libvirt/images/ directory.
  4. How large would you like the disk to be (in gigabytes)? The size of the virtual disk for the guest (only appears if the file specified above does not already exist). 4.0 gigabytes is a reasonable size for a "default" install
  5. What is the install CD-ROM/ISO or URL? This is the path to a Fedora installation tree in the format used by anaconda. NFS, FTP, and HTTP locations are all supported. Examples include:
    • nfs:my.nfs.server.com:/path/to/test2/tree/
    • http://my.http.server.com/path/to/tree/
    • ftp://my.ftp.server.com/path/to/tree


These options can be passed as command line options, execute virt-install --help for details.

virt-install can use kickstart files, for example virt-install -x ks=kickstart-file-name.ks.

If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, a text installer will appear. Proceed with the fedora installation.

Creating a guest with virt-manager

Start the GUI Virtual Machine Manager by selecting it from the "Applications-->System Tools" menu, or by running the following command:

su -c "virt-manager"

If you encounter an error along the lines of "Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash", trying running virt-manager not as root (without the su -c). The GUI will prompt for the root password.


  1. Open a connection to a hypervisor by choosing File-->Add connection...
  2. Choose "qemu" for KVM, or "Xen" for Xen.
  3. Choose "local" or select a method to connect to a remote hypervisor
  4. After a connection is opened, click the new icon next to the hypervisor, or right click on the active hypervisor and select "New" (Note - the new icon is going to be improved to make it easier to see)
  5. A wizard will present the same questions as appear with the virt-install command-line utility (see descriptions above). The wizard assumes that a graphical installation is desired and does not prompt for this option.
  6. On the last page of the wizard there is a "Finish" button. When this is clicked, the guest OS is provisioned. After a few moments a VNC window should appear. Proceed with the installation as normal.

Remote management

The following remote management options are available:

  • (easiest) If using non-root users via SSH, then setup instructions are at: http://wiki.libvirt.org/page/SSHSetup
  • If using root for access via SSH, then create SSH keys for root, and use ssh-agent and ssh-add before launching virt-manager.
  • To use TLS, set up a local certificate authority and issue x509 certs to all servers and clients. For information on configuring this option, refer to http://wiki.libvirt.org/page/TLSSetup.

Guest system administration

When the installation of the guest operating system is complete, it can be managed using the GUI virt-manager program or on the command line using virsh.

Managing guests with virt-manager

Start the Virtual Machine Manager. Virtual Machine Manager is in the "Applications-->System Tools" menu, or execute:

su -c "virt-manager"

{1} If you are not root, you will be prompted to enter the root password. ChooseRun unprivileged to operate in a read-only non-root mode.

  • Choose the host you wish to manage and click "Connect" in the "Open Connection" dialog window.
  • The list of virtual machines is displayed in the main window. Guests that are running will display a ">" icon. Guests that are not running will be greyed out.
  • To manage a particular guest, double click on it, or right click and select "Open".
  • A new window for the guest will open that will allow you to use its console, see information about its virtual hardware and start/stop/pause it.

For further information about virt-manager consult the project website

Bugs in the virt-manager tool should be reported in BugZilla against the 'virt-manager' component

Managing guests with virsh

The virsh command line utility that allows you to manage virtual machines. Guests can be managed on the command line with the virsh utility. The virsh utility is built around the libvirt management APIl:

  • virsh has a stable set of commands whose syntax and semantics are preserved across updates to the underlying virtualization platform.
  • virsh can be used as an unprivileged user for read-only operations (e.g. listing domains, listing domain statistics).
  • virsh can manage domains running under Xen, Qemu/KVM, esx or other backends with no perceptible difference to the user
Note.png
A valid URI may be passed to virsh with "-c' to connect to a remote libvirtd instance. For details, see http://libvirt.org/uri.html

To start a virtual machine:

su -c "virsh create <name of virtual machine>"

To list the virtual machines currently running:

su -c "virsh list"

To list all virtual machines, running or not:

su -c "virsh list --all"

To gracefully power off a guest:

su -c "virsh shutdown <virtual machine (name | id | uuid)>"

To non gracefully power off a guest:

su -c "virsh destroy <virtual machine (name | id | uuid)>"

To save a snapshot of the machine to a file:

su -c "virsh save <virtual machine (name | id | uuid)> <filename>"

To restore a previously saved snapshot:

su -c "virsh restore <filename>"

To export the configuration file of a virtual machine:

su -c "virsh dumpxml <virtual machine (name | id | uuid)"

For a complete list of commands available for use with virsh:

su -c "virsh help"

Or consult the manual page: man 1 virsh

Bugs in the virsh tool should be reported in BugZilla against the 'libvirt' component.