Presentation is loading. Please wait.

Presentation is loading. Please wait.

Libvirt management Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010.

Similar presentations


Presentation on theme: "Libvirt management Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010."— Presentation transcript:

1 Libvirt management Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010

2 What is libvirt A collection of software that provides a convenient way to manage virtual machines and other virtualization functionality, such as storage and network interface management.  an API library  a daemon (libvirtd)  a command line utility (virsh) Libvirt's goal is to expose all useful hypervisor features Andrea Chierici2

3 Major functionalities VM management Remote machine support Storage management Network interface management Virtual NAT and Route base networking  virbr0 Andrea Chierici3

4 virsh command line interface tool for managing guests and the hypervisor built on the libvirt management API and operates in similar way to the xen “xm” command and the graphical guest Manager (virt-manager) virsh can be used in read-only mode by unprivileged users Andrea Chierici4

5 XML sample quattortest 60756d57-8086-32ae-2b4a-f301f96e5838 2097152 1 hvm destroy restart /usr/libexec/qemu-kvm Andrea Chierici5

6 virsh command reference CommandDescription helpPrints basic help information. listLists all guests. dumpxml Outputs the XML configuration file for the guest. create Creates a guest from an XML configuration file and starts the new guest. startStarts an inactive guest. destroyForces a guest to stop. define Outputs an XML configuration file for a guest. domidDisplays the guest's ID. domuuidDisplays the guest's UUID. dominfoDisplays guest information. domnameDisplays the guest's name. domstateDisplays the state of a guest. quitQuits the interactive terminal. rebootReboots a guest. restore Restores a previously saved guest stored in a file. resumeResumes a paused guest. save Save the present state of a guest to a file. shutdownGracefully shuts down a guest. suspendPauses a guest. undefine Deletes all files associated with a guest. migrate Migrates a guest to another host. Andrea Chierici6 CommandDescription setmemSets the allocated memory for a guest. setmaxmemSets maximum memory limit for the hypervisor. setvcpus Changes number of virtual CPUs assigned to a guest. vcpuinfoDisplays virtual CPU information about a guest. vcpupinControls the virtual CPU affinity of a guest. domblkstat Displays block device statistics for a running guest. domifstat Displays network interface statistics for a running guest. attach-device Attach a device to a guest, using a device definition in an XML file. attach-diskAttaches a new disk device to a guest. attach-interfaceAttaches a new network interface to a guest. detach-device Detach a device from a guest, takes the same kind of XML descriptions as command attach- device. detach-diskDetach a disk device from a guest. detach-interfaceDetach a network interface from a guest.

7 Virsh edit Recommended way to make changes to an existing VM configuration virsh edit  This command will open a text editor containing the existing VM XML  any changes that are made and saved will be checked for errors when the editor exits. If no errors are found, the changes are made permanent. Andrea Chierici7

8 virsh examples Connect to a hypervisor session with virsh: # virsh connect {hostname OR URL}  Where is the machine name of the hypervisor. To initiate a read-only connection, append the above command with -readonly. Creating a guest from a configuration file  Guests can be created from XML configuration files.  You can copy existing XML from previously created guests or use the dumpxml option (refer to Creating a virtual machine XML dump (configuration file)).Creating a virtual machine XML dump (configuration file)  To create a guest with virsh from an XML file: # virsh create configuration_file.xml Editing a guest's configuration file  Instead of using the dumpxml option (refer to Creating a virtual machine XML dump (configuration file)) guests can be edited either while they run or while they are offline.Creating a virtual machine XML dump (configuration file)  The virsh edit command provides this functionality. For example, to edit the guest named softwaretesting: # virsh edit softwaretesting Andrea Chierici8

9 virsh examples Shut down a guest # virsh shutdown {domain-id, domain-name or domain-uuid}  You can control the behavior of the rebooting guest by modifying the on_shutdown parameter in the guest's configuration file. Displaying the guests: to display the guest list and their current states with virsh: # virsh list Migrating guests with virsh  A guest can be migrated to another host with virsh. Add --live for live migration. The migrate command accepts parameters in the following format: # virsh migrate --live GuestName DestinationURL  The --live parameter is optional. Add the --live parameter for live migrations. Andrea Chierici9

10 QEMU monitor Libvirt deliberately does not enable user access to the QEMU monitor. Interacting with the monitor behind libvirt's back can cause reported virtual machine state to be out of sync, which will likely end with errors. Andrea Chierici10

11 Remote management with SSH libvirt management connection securely tunneled over an SSH connection to manage the remote machines All the authentication is done using SSH public key cryptography and passwords or passphrases gathered by your local SSH agent.  the VNC console for each guest virtual machine is tunneled over SSH. Andrea Chierici11

12 Password less SSH access for virt-manager $ssh-keygen -t rsa $ssh-copy-id -i ~/.ssh/id_rsa.pub root@example.com root@example.com's password: Optional: add the passphrase to the ssh- agent $ssh-add ~/.ssh/id_rsa.pub Andrea Chierici12

13 Accessing remote hosts with virt-manager Remote hosts can be managed with the virt- manager GUI tool. SSH keys must belong to the user executing virt-manager for password-less login to work.  Start virt-manager.  Open the File->Add Connection menu.  Input values for the hypervisor type, the connection, Connection->Remote tunnel over SSH, and enter the desired hostname, then click connection. Andrea Chierici13

14 How to configure management access to libvirt through SSH management access to libvirt is controlled through membership to a unix group (libvirt) groupadd libvirt In the /etc/libvirt/libvirtd.conf file, uncomment these two lines: #unix_sock_group = "libvirt" #unix_sock_rw_perms = "0770" Restart libvirt daemon Add the desired users to this unix group: $usermod -G libvirt -a username1 Andrea Chierici14

15 Verify it works $ virsh -c qemu+ssh://username@host1.example.org/system Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # hostname host1.libvirt.org Andrea Chierici15


Download ppt "Libvirt management Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010."

Similar presentations


Ads by Google