静态迁移就是拷贝虚拟机(关机状态)的虚拟磁盘文件与配置文件到目标虚拟服务器上实现的迁移。
1、确保被迁移虚机处于关机状态并检查虚机磁盘列表
[root@sun ~]# virsh list --all Id Name State ---------------------------------------------------- 2 mercury running 3 venus running 4 aptcacher running - pluto shut off [root@sun ~]# virsh domblklist pluto Target Source ------------------------------------------------ hda /var/lib/libvirt/images/pluto.qcow2 hdb -
2、备份导出虚机配置文件:virsh dumpxml vhostname > vhostname.xml
[root@sun ~]# virsh dumpxml pluto > pluto.xml [root@sun ~]# ll | grep pluto -rw-r--r-- 1 root root 3393 Oct 30 21:22 pluto.xml
3、将备份导出的虚机配置文件和虚机磁盘镜像拷贝至目标服务器相关位置
[root@sun ~]# scp pluto.xml root@172.16.2.100:/etc/libvirt/qemu/ The authenticity of host '172.16.2.100 (172.16.2.100)' can't be established. ECDSA key fingerprint is e7:cb:b7:7c:26:36:de:61:50:3d:dd:b1:8b:ad:9e:4b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.16.2.100' (ECDSA) to the list of known hosts. root@172.16.2.100's password: pluto.xml 100% 3397 3.3KB/s 00:00
[root@sun ~]# scp /var/lib/libvirt/images/pluto.qcow2 root@172.16.2.100:/date/images root@172.16.2.100's password: pluto.qcow2 100% 23GB 108.7MB/s 03:40
4、在目标服务器上查看相关文件均已被拷贝过来
[root@boron3 ~]# ll /etc/libvirt/qemu total 16 drwxr-xr-x 2 root root 27 Oct 30 15:06 autostart -rw------- 1 root root 4643 Oct 30 16:26 centos7.0.xml drwx------ 3 root root 42 Oct 29 16:35 networks -rw-r--r-- 1 root root 3393 Oct 31 09:27 pluto.xml [root@boron3 ~]# ll /date/images/ -h total 25G -rw------- 1 qemu qemu 21G Oct 31 09:30 centos7.0.qcow2 -rw-r--r-- 1 root root 24G Oct 31 09:06 pluto.qcow2
5、编辑修改虚机配置文件检查虚机磁盘文件存放位置
[root@boron3 ~]# vim /etc/libvirt/qemu/pluto.xml
6、定义注册虚拟主机:virsh define /etc/libvirt/qemu/pluto.xml
[root@boron3 ~]# virsh define /etc/libvirt/qemu/pluto.xml Domain pluto defined from /etc/libvirt/qemu/pluto.xml [root@boron3 ~]# virsh list --all Id Name State ---------------------------------------------------- 1 centos7.0 running - pluto shut off
7、开启虚机,检查各方面无误后表示迁移成功:virsh start pluto
[root@boron3 ~]# virsh start pluto Domain pluto started [root@boron3 ~]# virsh list Id Name State ---------------------------------------------------- 1 pluto running 2 centos7.0 running