1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移。分为以下情况:
(1)虚拟主机各自使用本地存储存放虚拟机磁盘文件(本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式)
(2)虚拟主机之间使用共享存储存放虚拟机磁盘文件(该方式只是在目标虚拟主机上重新定义虚拟机就可以了)
2,静态迁移的过程如下:
(1)确定虚拟机处于关闭状态,本文以hadoop3为例:
[root@KVM install]# virsh list --all Id Name State ---------------------------------------------------- 1 win7 running 18 hadoop4 running 20 hadoop2 running 21 hadoop1 running - hadoop3 shut off [root@KVM install]#
(2)准备迁移虚拟机,查看虚拟机的磁盘配置文件
[root@KVM install]# virsh domblklist hadoop3 Target Source ------------------------------------------------ hda /p_w_picpaths/test/hadoop3.qcow2 hdb /p_w_picpaths/test/hadoop3_add.qcow2 hdc - [root@KVM install]#
(3)导入虚拟机的配置文件
[root@KVM install]# virsh dumpxml hadoop3 > /tmp/hadoop3.xml [root@KVM install]# ll /tmp/hadoop3* -rw-r--r-- 1 root root 3016 Feb 6 12:43 /tmp/hadoop3.xml [root@KVM install]#
(4)拷贝配置文件到目标主机上
[root@KVM install]# scp /tmp/hadoop3.xml root@10.1.156.211:/etc/libvirt/qemu The authenticity of host '10.1.156.211 (10.1.156.211)' can't be established. RSA key fingerprint is 20:8e:24:a6:ef:b3:d6:71:72:bb:39:e7:88:f9:38:cd. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.1.156.211' (RSA) to the list of known hosts. root@10.1.156.211's password: [root@KVM install]#
(5)拷贝虚拟机的磁盘文件到目标主机上
[root@KVM install]# scp /tmp/hadoop3.xml root@10.1.156.211:/etc/libvirt/qemu The authenticity of host '10.1.156.211 (10.1.156.211)' can't be established. RSA key fingerprint is 20:8e:24:a6:ef:b3:d6:71:72:bb:39:e7:88:f9:38:cd. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.1.156.211' (RSA) to the list of known hosts. root@10.1.156.211's password: [root@KVM install]# virsh domblklist hadoop3 Target Source ------------------------------------------------ hda /p_w_picpaths/test/hadoop3.qcow2 hdb /p_w_picpaths/test/hadoop3_add.qcow2 hdc - [root@KVM install]# scp /p_w_picpaths/test/hadoop3.qcow2 /p_w_picpaths/test/hadoop3_add.qcow2 root@10.1.156.211:/data/test/ root@10.1.156.211's password: [root@KVM install]#
3,在目标主机上做如下操作:
(1)查看目标虚拟主机的环境
[root@KVM test]# virsh list --all Id Name State ----------------------------------------------------
(2)修改目标主机的配置文件。
[root@KVM test]#vi /etc/libvirt/qemu/hadoop3.xml
(3)定义注册虚拟主机
[root@KVM test]# virsh define /etc/libvirt/qemu/hadoop3.xml Domain hadoop3 defined from /etc/libvirt/qemu/hadoop3.xml
(4)启动并确认虚拟机
[root@KVM test]# virsh list --all Id Name State ---------------------------------------------------- - hadoop3 shut off [root@KVM test]# virsh start hadoop3 Domain hadoop3 started
至此,虚拟机的静态迁移成功