KVM--静态迁移

静态迁移:也叫做常规迁移、离线迁移(Offline Migration)。就是在虚拟机关机或暂停的情况下从一台物理机迁移到另一台物理机。这种方式的迁移过程需要显式的停止虚拟机的运行。从用户角度看,有明确的一段停机时间,虚拟机上的服务不可用。这种迁移方式简单易行,适用于对服务可用性要求不严格的场合。

一、同一宿主机内迁移

[root@k-node2 ~]# virsh domblklist win7
目标     源
------------------------------------------------
vda        /var/lib/libvirt/images/win7.qcow2
vdb        /vm/test1.qcow2
vdc        /vm/test2.qcow2
hdb        /root/iso/virtio-win.iso

[root@k-node2 ~]# mv /var/lib/libvirt/images/win7.qcow2 /vm

[root@k-node2 ~]# ll /vm/win7.qcow2 
-rw------- 1 qemu qemu 10739318784 5月   6 13:57 /vm/win7.qcow2

[root@k-node2 ~]# virsh edit win7
修改前
<source file='/var/lib/libvirt/images/win7.qcow2'/>
修改后
<source file='/vm/win7.qcow2'/>

[root@k-node2 ~]# virsh start win7
域 win7 已开始

二、不同宿主机之间迁移--导入磁盘的方法

目标主机:

[root@master ~]# mkdir /vm

[root@master ~]# ll /tmp/win7.xml 
-rw-r--r--. 1 root root 4660 May 12 22:37 /tmp/win7.xml

[root@master ~]# virsh define /tmp/win7.xml 
Domain win7 defined from /tmp/win7.xml

[root@master ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos6.7                      shut off
 -     centos6.7-1                    shut off
 -     centos6.7-2                    shut off
 -     win7                           shut off

源主机:

[root@k-node2 ~]# rsync -avSHP /vm/win7.qcow2 [email protected]:/vm/
The authenticity of host '172.16.216.140 (172.16.216.140)' can't be established.
ECDSA key fingerprint is 39:5b:63:60:54:62:24:0c:c1:d7:fe:01:0a:ae:35:31.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.216.140' (ECDSA) to the list of known hosts.
[email protected]'s password: 
sending incremental file list
win7.qcow2
 10739318784 100%   37.73MB/s    0:04:31 (xfer#1, to-check=0/1)

sent 10740629812 bytes  received 31 bytes  38428013.75 bytes/sec
total size is 10739318784  speedup is 1.00

[root@k-node2 ~]# virsh dumpxml win7 > /tmp/win7.xml

[root@k-node2 ~]# rsync -avSHP /tmp/win7.xml [email protected]:/tmp
[email protected]'s password: 
sending incremental file list
win7.xml
        4660 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 4736 bytes  received 31 bytes  1059.33 bytes/sec
total size is 4660  speedup is 0.98

三、不同宿主机之间迁移--使用 virsh migrate命令

源主机

virsh # migrate --domain centos7.1 --desturi qemu+ssh://[email protected]/system --offline --persistent
[email protected]'s password: 

[root@k-node2 ~]# rsync -avSHP /vm/centos7-disk1.qcow2 [email protected]:/vm/
[email protected]'s password: 
sending incremental file list
centos7-disk1.qcow2
  1361444864 100%   31.07MB/s    0:00:41 (xfer#1, to-check=0/1)

sent 1361611141 bytes  received 31 bytes  28665498.36 bytes/sec
total size is 1361444864  speedup is 1.00

目标主机:

[root@master vm]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos6.7                      shut off
 -     centos6.7-1                    shut off
 -     centos6.7-2                    shut off
 -     centos7.1                      shut off


猜你喜欢

转载自blog.51cto.com/stuart/2118709