在Debian Jessie上使用DRBD进行Xen 在线迁移

时间:2020-03-21 11:47:33  来源:igfitidea点击:

以下是3部分系列文章的第2部分,该系列文章介绍了使用DRBD进行Xen实时迁移的安装和配置。

本文介绍了Debian来宾域(domU虚拟机)的创建,以后将在两个Xen主机之间进行迁移。

本文遵循的约定是[ALL]表示需要在两个Xen节点上都运行的命令。

安装

我们需要xen-tools软件包:

[ALL]# apt-get install xen-tools

配置Xen工具

我们需要一个LVM组来存储domU图像:

[ALL]# vgcreate vg_xen /dev/sdb  
  Physical volume "/dev/sdb" successfully created
  Volume group "vg_xen" successfully created
[ALL]# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  vg_debian8   1   2   0 wz--n- 63.25g 48.11g
  vg_xen       1   0   0 wz--n- 50.00g 50.00g

带有我们默认设置的配置文件'/etc/xen-tools/xen-tools.conf'可以在下面看到。
注意使用LVM组。

lvm = vg_xen
install-method = debootstrap
size = 4G # Root disk, suffix (G, M, k) required
memory = 256M # Suffix (G, M, k) required
maxmem = 512M # Suffix (G, M, k) optional
swap = 128M # Suffix (G, M, k) required
fs = ext4 # Default file system for any disk
dist = `xt-guess-suite-and-mirror --suite`
image = sparse # Specify sparse vs. full disk images (file based images only)
dhcp = 1
genpass = 1
genpass_len = 12
hash_method = sha512
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
arch = [amd64]
mirror = `xt-guess-suite-and-mirror --mirror`
mirror_wheezy = http://http.debian.net/debian
mirror_jessie = http://http.debian.net/debian
ext4_options = noatime,nodiratime,errors=remount-ro
ext2_options = noatime,nodiratime,errors=remount-ro
xfs_options = defaults

(可选)对于使用环回镜像存储Xen来宾域的用户,几乎可以肯定会用尽分发创建的环回镜像的默认数量,因此,我们可能需要以下内容:

[ALL]# modprobe loop max_loop=255
[ALL]# echo "loop max_loop=255" >>/etc/modules

还要确保主机上的“/dev”目录中有实际的设备。

创建Debian Jessie来宾(DomU)

请注意,正在安装来宾的LVM卷'/dev/vg_xen/jessie01-disk'。

[xen01]# xen-create-image --hostname=jessie01 --lvm=vg_xen \
  --vcpus=1 --memory=256M --maxmem=512M  --size=4G --fs=ext4 \
  --dhcp --mac=08:00:27:ff:60:00 --arch=amd64 --dist=jessie \
  --noswap
General Information
-------------------
Hostname       :  jessie01
Distribution   :  jessie
Mirror         :  http://ftp.uk.debian.org/debian
Partitions     : /             4G    (ext4)
Image type     :  full
Memory size    :  256M
Max mem size   :  512M
Kernel path    :  /boot/vmlinuz-3.16.0-4-amd64
Initrd path    :  /boot/initrd.img-3.16.0-4-amd64
Networking Information
---------------------
IP Address     : DHCP [MAC: 08:00:27:ff:60:00]

Creating ext4 filesystem on /dev/vg_xen/jessie01-disk
Done
Installation method: debootstrap
Done
Running hooks
Done
No role scripts were specified.  Skipping
Creating Xen configuration file
Done
No role scripts were specified.  Skipping
Setting up root password
Generating a password for the new guest.
All done

Logfile produced at:
         /var/log/xen-tools/jessie01.log
Installation Summary
--------------------
Hostname        :  jessie01
Distribution    :  jessie
MAC Address     :  08:00:27:ff:60:00
IP Address(es)  :  dynamic
RSA Fingerprint :  55:e7:99:06:bf:db:dd:1f:bc:0e:72:d9:26:ae:31:3d
Root Password   :  sqKfU3JT8sZ6
[xen01]# xen-list-images
Name: jessie01
Memory: 256 MB
Config: /etc/xen/jessie01.cfg

启动VM,确保其正在运行并连接到控制台。

[xen01]# xl create /etc/xen/jessie01.cfg
Parsing config from /etc/xen/jessie01.cfg
[xen01]# xl list
Name              ID   Mem VCPUs      State   Time(s)
Domain-0          0  1022     1     r-----     215.4
jessie01          1   256     1     -b----       1.6
[xen01]# xl console jessie01

要退出控制台,请键入“ Ctrl +]”(与telnet相同)。

要关闭来宾,请执行以下操作:

[xen01]# xl shutdown jessie01

如果需要立即终止域,则可以使用destroy选项。
但是,这不会给域OS带来任何反应的机会,这等效于将电源线从物理机器上拔出。
在大多数情况下,我们将改为使用shutdown命令。

[xen01]# xl destroy jessie01

如果需要,可以通过这种方式删除图像文件:

[xen01]# xen-delete-image jessie01

为确保来宾jessie01在引导时自动启动,可以创建符号链接:

[ALL]# mkdir -p /etc/xen/auto
[xen01]# ln -sf /etc/xen/jessie01.cfg /etc/xen/auto/jessie01.cfg