1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移。分为以下情况:
(1)虚拟主机各自使用本地存储存放虚拟机磁盘文件(本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式)
(2)虚拟主机之间使用共享存储存放虚拟机磁盘文件(该方式只是在目标虚拟主机上重新定义虚拟机就可以了)
2,静态迁移的过程如下:
(1)确定虚拟机处于关闭状态,本文以hadoop3为例:
[[email protected] install]# virsh list --all Id Name State ---------------------------------------------------- 1 win7 running 18 hadoop4 running 20 hadoop2 running 21 hadoop1 running - hadoop3 shut off [[email protected] install]#
(2)准备迁移虚拟机,查看虚拟机的磁盘配置文件
[[email protected] install]# virsh domblklist hadoop3 Target Source ------------------------------------------------ hda /images/test/hadoop3.qcow2 hdb /images/test/hadoop3_add.qcow2 hdc - [[email protected] install]#
(3)导入虚拟机的配置文件
[[email protected] install]# virsh dumpxml hadoop3 > /tmp/hadoop3.xml [[email protected] install]# ll /tmp/hadoop3* -rw-r--r-- 1 root root 3016 Feb 6 12:43 /tmp/hadoop3.xml [[email protected] install]#
(4)拷贝配置文件到目标主机上
[[email protected] install]# scp /tmp/hadoop3.xml [email protected]:/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. [email protected]‘s password: [[email protected] install]#
(5)拷贝虚拟机的磁盘文件到目标主机上
[[email protected] install]# scp /tmp/hadoop3.xml [email protected]:/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. [email protected]‘s password: [[email protected] install]# virsh domblklist hadoop3 Target Source ------------------------------------------------ hda /images/test/hadoop3.qcow2 hdb /images/test/hadoop3_add.qcow2 hdc - [[email protected] install]# scp /images/test/hadoop3.qcow2 /images/test/hadoop3_add.qcow2 [email protected]:/data/test/ [email protected]‘s password: [[email protected] install]#
3,在目标主机上做如下操作:
(1)查看目标虚拟主机的环境
[[email protected] test]# virsh list --all Id Name State ----------------------------------------------------
(2)修改目标主机的配置文件。
[[email protected] test]#vi /etc/libvirt/qemu/hadoop3.xml
(3)定义注册虚拟主机
[[email protected] test]# virsh define /etc/libvirt/qemu/hadoop3.xml Domain hadoop3 defined from /etc/libvirt/qemu/hadoop3.xml
(4)启动并确认虚拟机
[[email protected] test]# virsh list --all Id Name State ---------------------------------------------------- - hadoop3 shut off [[email protected] test]# virsh start hadoop3 Domain hadoop3 started
至此,虚拟机的静态迁移成功
时间: 2024-10-22 00:58:09