一、同一宿主机内迁移
[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 root@172.16.216.140:/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. root@172.16.216.140'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 root@172.16.216.140:/tmp root@172.16.216.140'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://root@172.16.216.140/system --offline --persistent root@172.16.216.140's password: [root@k-node2 ~]# rsync -avSHP /vm/centos7-disk1.qcow2 root@172.16.216.140:/vm/ root@172.16.216.140'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
转载于:https://blog.51cto.com/stuart/2118709