9780j 发表于 2016-2-15 14:51:51

kvm虚拟机静态迁移

1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移。分为以下情况:(1)虚拟主机各自使用本地存储存放虚拟机磁盘文件(本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式)(2)虚拟主机之间使用共享存储存放虚拟机磁盘文件(该方式只是在目标虚拟主机上重新定义虚拟机就可以了)2,静态迁移的过程如下: (1)确定虚拟机处于关闭状态,本文以hadoop3为例:
1
2
3
4
5
6
7
8
9
# virsh list --all
Id    Name                           State
----------------------------------------------------
1   win7                           running
18    hadoop4                        running
20    hadoop2                        running
21    hadoop1                        running
-   hadoop3                        shut off
#




(2)准备迁移虚拟机,查看虚拟机的磁盘配置文件
1
2
3
4
5
6
7
# virsh domblklist hadoop3
Target   Source
------------------------------------------------
hda      /images/test/hadoop3.qcow2
hdb      /images/test/hadoop3_add.qcow2
hdc      -
#




(3)导入虚拟机的配置文件

1
2
3
4
# virsh dumpxml hadoop3 > /tmp/hadoop3.xml
# ll /tmp/hadoop3*
-rw-r--r-- 1 root root 3016 Feb6 12:43 /tmp/hadoop3.xml
#




(4)拷贝配置文件到目标主机上


1
2
3
4
5
6
7
# 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:
#




(5)拷贝虚拟机的磁盘文件到目标主机上


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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:
# virsh domblklist hadoop3               
Target   Source
------------------------------------------------
hda      /images/test/hadoop3.qcow2
hdb      /images/test/hadoop3_add.qcow2
hdc      -
# scp /images/test/hadoop3.qcow2 /images/test/hadoop3_add.qcow2 root@10.1.156.211:/data/test/
root@10.1.156.211's password:
#




3,在目标主机上做如下操作:
(1)查看目标虚拟主机的环境

1
2
3
# virsh list --all
Id    Name                           State
----------------------------------------------------




(2)修改目标主机的配置文件。

1
#vi /etc/libvirt/qemu/hadoop3.xml






(3)定义注册虚拟主机

1
2
# virsh define /etc/libvirt/qemu/hadoop3.xml
Domain hadoop3 defined from /etc/libvirt/qemu/hadoop3.xml




(4)启动并确认虚拟机

1
2
3
4
5
6
# virsh list --all
Id    Name                           State
----------------------------------------------------
-   hadoop3                        shut off
# virsh start hadoop3
Domain hadoop3 started





至此,虚拟机的静态迁移成功

页: [1]
查看完整版本: kvm虚拟机静态迁移