这里提到的静态迁移同是基于KVM虚拟主机之间的迁移,非异构虚拟化平台的静态迁移。
1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移。
(1)虚拟主机各自使用本地存储存放虚拟机磁盘文件
本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式,
(2)虚拟主机之间使用共享存储存放虚拟机磁盘文件
该方式只是在目标虚拟主机上重新定义虚拟机就可以了。
2.静态迁移过程如下
(1)确定虚拟机关闭状态
[[email protected] ~]# virsh list --all Id Name State ---------------------------------------------------- - CentOS6.5-01 shut off - CentOS6.5-02 shut off - CentOS6.5-03 shut off - Ser08R2-01 shut off [[email protected] ~]#
(2)准备迁移CentOS6.5-02虚拟机,查看该虚拟机配置的磁盘文件
[[email protected] ~]# virsh domblklist CentOS6.5-02 Target Source ------------------------------------------------ vda /data/kvm/CentOS6.5-02.img hdc - [[email protected] ~]#
(3)导入虚拟机配置文件
[[email protected] ~]# virsh dumpxml CentOS6.5-02 > /root/CentOS6.5-02.xml [[email protected] ~]# ll total 100 -rw-------. 1 root root 1536 Nov 15 2016 anaconda-ks.cfg -rw-r--r-- 1 root root 2781 Nov 27 15:45 CentOS6.5-02.xml drwxr-xr-x. 2 root root 4096 Nov 15 2016 Desktop drwxr-xr-x. 2 root root 4096 Nov 15 2016 Documents drwxr-xr-x. 2 root root 4096 Nov 15 2016 Downloads -rw-r--r--. 1 root root 43152 Nov 15 2016 install.log -rw-r--r--. 1 root root 9360 Nov 15 2016 install.log.syslog drwxr-xr-x. 2 root root 4096 Nov 15 2016 Music -rw-r--r-- 1 root root 0 Nov 27 15:30 node1.txt drwxr-xr-x. 2 root root 4096 Nov 15 2016 Pictures drwxr-xr-x. 2 root root 4096 Nov 15 2016 Public drwxr-xr-x. 2 root root 4096 Nov 15 2016 Templates drwxr-xr-x. 2 root root 4096 Nov 15 2016 Videos [[email protected] ~]#
(4)拷贝配置文件到目标虚拟主机上。
[[email protected] ~]# scp CentOS6.5-02.xml 10.10.172.192:/etc/libvirt/qemu/ [email protected]'s password: CentOS6.5-02.xml 100% 2781 2.7KB/s 00:00 [[email protected] ~]# [[email protected] ~]#
(5)查看虚拟机磁盘文件并拷贝到目标虚拟主机。
[[email protected] ~]# cd /data/kvm/ [[email protected] kvm]# ll total 20806040 -rw-r--r-- 1 root root 393216 Nov 22 17:06 CentOS6.5-01_add.qcow2 -rwxr-xr-x 1 root root 7516192768 Nov 22 15:08 CentOS6.5-01.img -rw-r--r-- 1 root root 2318139904 Nov 27 15:40 CentOS6.5-01.qcow2 -rwxr-xr-x 1 root root 7516192768 Nov 22 13:52 CentOS6.5-02.img -rwxr-xr-x 1 root root 7516192768 Nov 22 14:39 CentOS6.5-03.img -rwxr-xr-x 1 root root 10737418240 Nov 22 14:40 Ser08R2-01.img [[email protected] kvm]#
拷贝虚拟磁盘文件
[[email protected] kvm]# scp CentOS6.5-02.img 10.10.172.192:/data/kvm/ [email protected]'s password: CentOS6.5-02.img 100% 7168MB 140.6MB/s 00:51 [[email protected] kvm]# [[email protected] kvm]#
3.目标虚拟主机上
上面已经将虚拟机磁盘文件与配置文件都已经复制到目标虚拟主机上了。下面开始配置与启动。
(1)查看目标虚拟主机环境。
[[email protected] ~]# virsh list --all Id Name State ---------------------------------------------------- [[email protected] ~]# [[email protected] ~]# ll /etc/libvirt/qemu total 8 -rw-r--r--. 1 root root 2781 Nov 27 08:06 CentOS6.5-02.xml drwx------. 3 root root 4096 Nov 27 07:57 networks [[email protected] ~]# [[email protected] ~]#
查看虚拟机磁盘文件,目录结构与源虚拟主机一致。
[[email protected] ~]# cd /data/kvm/ [[email protected] kvm]# ll total 7340036 -rwxr-xr-x. 1 root root 7516192768 Nov 27 08:13 CentOS6.5-02.img [[email protected] kvm]# [[email protected] kvm]#
(2)定义注册虚拟主机
[[email protected] ~]# [[email protected] ~]# [[email protected] ~]# virsh define /etc/libvirt/qemu/CentOS6.5-02.xml Domain CentOS6.5-02 defined from /etc/libvirt/qemu/CentOS6.5-02.xml [[email protected] ~]# [[email protected] ~]#
(3)启动虚拟主机并确认
[[email protected] ~]# virsh list --all Id Name State ---------------------------------------------------- - CentOS6.5-02 shut off [[email protected] ~]# [[email protected] ~]# virsh start CentOS6.5-02 Domain CentOS6.5-02 started [[email protected] ~]# [[email protected] ~]# virsh console CentOS6.5-02 Connected to domain CentOS6.5-02 Escape character is ^] CentOS release 6.5 (Final) Kernel 2.6.32-431.el6.x86_64 on an x86_64 CentOS6.5-02 login: root Password: Last login: Wed Nov 22 05:41:25 on ttyS0 [[email protected] ~]# [[email protected] ~]# ifconfig -a eth0 Link encap:Ethernet HWaddr 52:54:00:77:D9:F4 inet addr:10.10.172.243 Bcast:10.10.172.255 Mask:255.255.255.0 inet6 addr: fe80::5054:ff:fe77:d9f4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:242 errors:0 dropped:0 overruns:0 frame:0 TX packets:9 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:22894 (22.3 KiB) TX bytes:566 (566.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [[email protected] ~]#
至此虚拟机静态迁移完成。
时间: 2024-10-07 06:00:09