Xen Live Migration Of An LVM-Based Virtual Machine With iSCSI On Debian Lenny
Author: Falko Timme
This guide explains how you can do a live migration of an LVM-based virtual machine (domU) from one Xen host to the other. I will use iSCSI to provide shared storage for the virtual machines in this tutorial. Both Xen hosts and the iSCSI target are running on Debian Lenny in this article.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
I'm using the following systems here:
- Xen host 1 : server.example.com, IP address: 192.168.0.100
- Xen host 2 : server2.example.com, IP address: 192.168.0.101
- iSCSI target (shared storage): iscsi.example.com, IP address: 192.168.0.102
- virtual machine: vm1.example.com, IP address: 192.168.0.103
I will use LVM on the shared storage so that I can create/use LVM-based Xen guests.
The two Xen hosts and the iSCSI target should have the following lines in /etc/hosts (unless you have a DNS server that resolves the hostnames):
127.0.0.1 localhost.localdomain localhost 192.168.0.100 server1.example.com server1 192.168.0.101 server2.example.com server2 192.168.0.102 iscsi.example.com iscsi 192.168.0.103 vm1.example.com vm1 [...]
2 Xen Setup
The two Xen hosts should be set up according to chapter two of this tutorial: Virtualization With Xen On Debian Lenny (AMD64)
To allow live migration of virtual machines, we must enable the following settings in /etc/xen/xend-config.sxp...
[...] (xend-relocation-server yes) [...] (xend-relocation-port 8002) [...] (xend-relocation-address '') [...] (xend-relocation-hosts-allow '') [...]
... and restart Xen:
3 Setting Up The iSCSI Target (Shared Storage)
Now we set up the target. The target will provide shared storage for server1 and server2, i.e., the virtual Xen machines will be stored on the shared storage.
aptitude install iscsitarget iscsitarget-modules-`uname -r`
... and set ISCSITARGET_ENABLE to true:
We can use unused logical volumes, image files, hard drives (e.g. /dev/sdb), hard drive partitions (e.g. /dev/sdb1) or RAID devices (e.g. /dev/md0) for the storage. In this example I will create a logical volume of 20GB named storage_lun1 in the volume group vg0:
lvcreate -L20G -n storage_lun1 vg0
(If you want to use an image file, you can create it as follows:
dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000
This creates the image file /storage/lun1.img with a size of 20GB.
Next we edit /etc/ietd.conf...
... and comment out everything in that file. At the end we add the following stanza:
[...] Target iqn.2001-04.com.example:storage.lun1 IncomingUser someuser secret OutgoingUser Lun 0 Path=/dev/vg0/storage_lun1,Type=fileio Alias LUN1 #MaxConnections 6
The target name must be a globally unique name, the iSCSI standard defines the "iSCSI Qualified Name" as follows: iqn.yyyy-mm.<reversed domain name>[:identifier]; yyyy-mm is the date at which the domain is valid; the identifier is freely selectable. The IncomingUser line contains a username and a password so that only the initiators (clients) that provide this username and password can log in and use the storage device; if you don't need authentication, don't specify a username and password in the IncomingUser line. In the Lun line, we must specify the full path to the storage device (e.g. /dev/vg0/storage_lun1, /storage/lun1.img, /dev/sdb, etc.).
Now we tell the target that we want to allow connections to the device iqn.2001-04.com.example:storage.lun1 from the IP address 192.168.0.100 (server1.example.com) and 192.168.0.101 (server2.example.com)...
[...] iqn.2001-04.com.example:storage.lun1 192.168.0.100, 192.168.0.101
... and start the target: