xen虚拟机迁移和扩容

    首先安装好系统centos系统,宿主机只安装base的基本包,然后用yum安装常见的xen,kernel-xen软件。

2.xen软件安装好之后检查一下/etc/grub.conf文件设置启动选项为后缀为xen 的内核,最后reboot重新启动。

3.系统启动好之后查看宿主机信息

[root@localhost ~]# xm li //xm  list显示domain 0的信息。
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      282     1 r-----    804.7

4.ifconfig -a查看桥和虚拟网卡

xen的网络桥接模式的工作流程,现翻译在下面以备后面之需。

When xend is started, with the default configuration (in /etc/xen/xend-config.sxp), it'll execute /etc/xen/scripts/network-bridge to re-configure your networking.

当xend这个进程被开启之后,进程会根据默认的配置文件/etc/xen/xend-config.sxp里的内容,让/etc/xen/scripts/network-bridge这个脚本发挥工作,重新来配置你的网络。

It'll rename the physical eth0 interface to peth0, change it's MAC address to FE:FF:FF:FF:FF:FF, and then create a virtual ethernet interface called eth0, configure it with the real MAC address, and bridge both of those interfaces to xenbr0 bridge.

它会将你的eth0重命名为peth0,把eth0的MAC值改为FE:FF:FF:FF:FF:FF。然后再重新创建一个虚拟的网络接口,将它命名为eth0,配置它让它有物理上的MAC地址,然后把peth0跟eth0这两个接口跟xenbr0做一个桥接。

This way the virtual eth0 interface should have a real MAC, and it can be used for dom0 management, and at the same time allow other VMs/domUs to share the physical ethernet interface by using xenbr0 bridge.

所以说,按这种方式虚拟出来的eth0这个接口会有物理上的MAC值,在domain0中发挥上网的功用,同时它也允许domainU通过xenbr0这个桥接接口跟domain0合用物理网络接口。

[root@localhost ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.000000000000       yes
xenbr0          8000.feffffffffff       no              vif3.0
                                                        vif0.0
                                                        peth0

[root@localhost ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:15:56:F2 
          inet addr:192.168.40.232  Bcast:192.168.40.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45498 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13674 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:19669317 (18.7 MiB)  TX bytes:1924647 (1.8 MiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:100 (100.0 b)  TX bytes:100 (100.0 b)

peth0     Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:324838 errors:2 dropped:2 overruns:0 frame:0
          TX packets:118994 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:402460402 (383.8 MiB)  TX bytes:9313197 (8.8 MiB)
          Interrupt:18 Base address:0x2000

veth1     Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          BROADCAST MULTICAST  MTU:1500  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)

veth2     Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          BROADCAST MULTICAST  MTU:1500  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)

veth3     Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          BROADCAST MULTICAST  MTU:1500  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)

vif0.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:13719 errors:0 dropped:0 overruns:0 frame:0
          TX packets:45546 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1931157 (1.8 MiB)  TX bytes:19672872 (18.7 MiB)

vif0.1    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          BROADCAST MULTICAST  MTU:1500  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)

vif0.2    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          BROADCAST MULTICAST  MTU:1500  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)

vif0.3    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          BROADCAST MULTICAST  MTU:1500  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)

vif3.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:314 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1649 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:23922 (23.3 KiB)  TX bytes:434040 (423.8 KiB)

virbr0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:3137 (3.0 KiB)

xenbr0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:26586 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:6736372 (6.4 MiB)  TX bytes:0 (0.0 b)

5.安装客户端系统centos首先创建8g空间的img映像文件

[root@localhost ~]# mkdir  -p  /data/xen/ //创建目录/data和xen目录

[root@localhost ~]# dd if=/dev/zero of=/data/xen/xen.img bs=1 count=1 seek=8G
1+0 records in
1+0 records out
1 byte (1 B) copied, 0.000111 seconds, 9.0 kB/s

6.安装客户端系统centos

用virt-install --prompt交互模式来创建客户机的或者用命令行virt-install -n xentest -r 300 --vcpus=1 --nographic -f /data/xen/xen.img  -l http://mirrors.163.com/centos/5.8/os/i386/

7.客户机centos安装好之后启动xentest虚拟机

[root@localhost ~]# xm li//查看xentest虚拟机状态
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      282     1 r-----    804.7
xentest                                    3      300     1 -b----     29.4

 [root@localhost ~]# xm create xentest //启动xentest虚拟机后面也可以加参数-c xentest 启动grub界面
Using config file "/etc/xen/xentest".
Using <class 'grub.GrubConf.GrubConfigFile'> to parse /grub/menu.lst
Started domain xentest

 8.连接虚拟机xentest

[root@localhost ~]# xm console(con) xentest//进入虚拟机界面,如果想切换用ctrl+]就可以切换了。

[root@localhost ~]# fdisk -l//启动好虚拟机可以看一下空间为8G磁盘为/dev/xvda1。

Disk /dev/xvda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14          89      610470   82  Linux swap / Solaris
/dev/xvda3              90         522     3478072+  83  Linux

9.查看宿主机的/etc/xen配置文件

[root@localhost ~]# cat /etc/xen/xentest //查看xentest虚拟机配置文件。
name = "xentest"
uuid = "f16d705e-203b-c694-d17b-9501bc528535"
maxmem = 300
memory = 300
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/data/xen/xen.img,xvda,w" ]//磁盘
vif = [ "mac=00:16:3e:2e:09:66,bridge=xenbr0,script=vif-bridge" ] 桥的指定,如果要自己定义桥可以用brctl命令创建,具体用法可以看说明。

[root@localhost ~]# ls /etc/xen/查看主要配置文件
auto       xend-config.sxp//是xend的主要配置文件      xentest     xmexample.hvm
qemu-ifup  xend-pci-permissive.sxp  xmexample1  xmexample.vti
scripts//    xenscripts是xen的脚本存放目录,里面也存放了xen的网络初始化脚本。
d-pci-quirks.sxp      xmexample2
 

 10.扩大或缩小xvda,xentest虚拟机磁盘xen.img的空间大小。

[root@localhost ~]# xm shutdown xentest//首先停用xentest虚拟机

[root@localhost ~]#  dd if=/dev/zero of=/data/xen/xen.img bs=1 count=1 seek=4G
1+0 records in
1+0 records out
1 byte (1 B) copied, 0.000111 seconds, 9.0 kB/s 

或者在虚拟机配置文件/etc/xen/xentest添加镜像文件,意思就是在添加一个硬盘,添加好之后fdisk和mkfs和fstab就可以使用了。

[ "tap:aio:/data/xen/xen.img,xvda,w","tap:aio:/data/xen/xen1.img,xvdb,w" ] 
 

[root@localhost ~]#  xm create xentest//启动xentest虚拟机。

[root@localhost ~]#  xm console  -c xentest //连接虚拟机xentest

[root@localhost ~]# fdisk -l//查看磁盘分区变成4G

Disk /dev/xvda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14          89      610470   82  Linux swap / Solaris
/dev/xvda3              90         522     3478072+  83  Linux

 11.迁移的问题

直接把xen.img文件拷贝到别处机器,首先安装好xen环境直接xm create xentest即可。

 12.查看支持半虚拟化还是全虚拟化

你可能感兴趣的:(扩容,迁移,xen)