这里提到的静态迁移同是基于KVM虚拟主机之间的迁移,非异构虚拟化平台的静态迁移。
1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移。
(1)虚拟主机各自使用本地存储存放虚拟机磁盘文件
本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式,
(2)虚拟主机之间使用共享存储存放虚拟机磁盘文件
该方式只是在目标虚拟主机上重新定义虚拟机就可以了。
2.静态迁移过程如下
(1)确定虚拟机关闭状态
1
2
3
4
5
6
7
8
9
|
[root@node1 ~] # 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
[root@node1 ~] #
|
(2)准备迁移CentOS6.5-02虚拟机,查看该虚拟机配置的磁盘文件
1
2
3
4
5
6
7
|
[root@node1 ~] # virsh domblklist CentOS6.5-02
Target Source ------------------------------------------------ vda /data/kvm/CentOS6 .5-02.img
hdc - [root@node1 ~] #
|
(3)导入虚拟机配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@node1 ~] # virsh dumpxml CentOS6.5-02 > /root/CentOS6.5-02.xml
[root@node1 ~] # 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 [root@node1 ~] #
|
(4)拷贝配置文件到目标虚拟主机上。
1
2
3
4
5
|
[root@node1 ~] # scp CentOS6.5-02.xml 10.10.172.192:/etc/libvirt/qemu/
root@10.10.172.192's password: CentOS6.5-02.xml 100% 2781 2.7KB /s 00:00
[root@node1 ~] #
[root@node1 ~] #
|
(5)查看虚拟机磁盘文件并拷贝到目标虚拟主机。
1
2
3
4
5
6
7
8
9
10
|
[root@node1 ~] # cd /data/kvm/
[root@node1 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 [root@node1 kvm] #
|
拷贝虚拟磁盘文件
1
2
3
4
5
|
[root@node1 kvm] # scp CentOS6.5-02.img 10.10.172.192:/data/kvm/
root@10.10.172.192's password: CentOS6.5-02.img 100% 7168MB 140.6MB /s 00:51
[root@node1 kvm] #
[root@node1 kvm] #
|
3.目标虚拟主机上
上面已经将虚拟机磁盘文件与配置文件都已经复制到目标虚拟主机上了。下面开始配置与启动。
(1)查看目标虚拟主机环境。
1
2
3
4
5
6
7
8
9
10
11
|
[root@node2 ~] # virsh list --all
Id Name State
---------------------------------------------------- [root@node2 ~] #
[root@node2 ~] # 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 [root@node2 ~] #
[root@node2 ~] #
|
查看虚拟机磁盘文件,目录结构与源虚拟主机一致。
1
2
3
4
5
6
|
[root@node2 ~] # cd /data/kvm/
[root@node2 kvm] # ll
total 7340036 -rwxr-xr-x. 1 root root 7516192768 Nov 27 08:13 CentOS6.5-02.img [root@node2 kvm] #
[root@node2 kvm] #
|
(2)定义注册虚拟主机
1
2
3
4
5
6
7
|
[root@node2 ~] #
[root@node2 ~] #
[root@node2 ~] # virsh define /etc/libvirt/qemu/CentOS6.5-02.xml
Domain CentOS6.5-02 defined from /etc/libvirt/qemu/CentOS6 .5-02.xml
[root@node2 ~] #
[root@node2 ~] #
|
(3)启动虚拟主机并确认
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
[root@node2 ~] # virsh list --all
Id Name State
---------------------------------------------------- - CentOS6.5-02 shut off
[root@node2 ~] #
[root@node2 ~] # virsh start CentOS6.5-02
Domain CentOS6.5-02 started [root@node2 ~] #
[root@node2 ~] # 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 [root@CentOS6 ~] #
[root@CentOS6 ~] # 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)
[root@CentOS6 ~] #
|
至此虚拟机静态迁移完成。
本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/2044771,如需转载请自行联系原作者