xen(三)xl 工具使用

使用xl
这里是Xen手册页的xl文档:xl(1)。
我们将创建一个CentOS-6和一个CentOS-7 HVM。
首先,我们需要虚拟机的配置文件。 在xen包中有一个名为/etc/xen/xlexample.hvm的示例HVM配置文件。 您可以查看该文件并在此HVM文档中查看:xl.cfg(5)
文档:http://xenbits.xen.org/docs/4.6-testing/man/xl.1.html
这里是我们的配置文件..我在/ etc / xen / config.d中创建了一个保存配置文件的目录。
(1)保存与恢复:
保存:
# xl save busybox-001 /tmp/busybox-001.img  /etc/xen/busybox
Saving to /tmp/busybox-001.img new xl format (info 0x1/0x0/888)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%
libxl: info: libxl.c:1717:devices_destroy_cb: forked pid 5981 for destroy of domain 8

# xl list
Name                                        ID   Mem VCPUs    State    Time(s)
Domain-0                                     0  1024     1     r—–      88.0
恢复:
# xl restore /etc/xen/busybox /tmp/busybox-001.img
Loading new save file /tmp/busybox-001.img (new xl fmt info 0x1/0x0/888)
Savefile contains xl domain config in JSON format
Parsing config from /etc/xen/busybox
xc: Reloading memory pages: 65536/65536  100%
验证:
# xl list
Name                                        ID   Mem VCPUs    State    Time(s)
Domain-0                                     0  1024     1     r—–      90.7
busybox-001                                  9   256     2     -b—-       0.0
(2)暂停与继续:
pause:# xl pause busybox-001
unpause:# xl unpause busybox-001
(3)关机与重启:
shutdown:要虚拟机支持关机命令
reboot:重启
(4)保存与恢复:
保存:
# xl save busybox-002 /tmp/busybox-002.img  /etc/xen/busybox
busybox-002 is an invalid domain identifier (rc=-6)
[root@xen net]# xl save busybox-001 /tmp/busybox-001.img  /etc/xen/busybox
Saving to /tmp/busybox-001.img new xl format (info 0x1/0x0/888)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%
libxl: info: libxl.c:1717:devices_destroy_cb: forked pid 5981 for destroy of domain 8

验证:
# xl list
Name                                        ID   Mem VCPUs    State    Time(s)
Domain-0                                     0  1024     1     r—–      88.0

恢复:
# xl restore /etc/xen/busybox /tmp/busybox-001.img
Loading new save file /tmp/busybox-001.img (new xl fmt info 0x1/0x0/888)
Savefile contains xl domain config in JSON format
Parsing config from /etc/xen/busybox
xc: Reloading memory pages: 65536/65536  100%

验证:
# xl list
Name                                        ID   Mem VCPUs    State    Time(s)
Domain-0                                     0  1024     1     r—–      90.7
busybox-001                                  9   256     2     -b—-       0.0
(5)关于cpu:
# xl vcpu-list
Name                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                             0     0    0   r–      92.8  0 / all
busybox-001                          9     0    3   -b-       0.3  all / all
busybox-001                          9     1    1   -b-       0.2  all / all

让vcpu 0只能运行于物理cpu3上
# xl vcpu-pin busybox-001 0 3

# xl vcpu-list
Name                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                             0     0    0   r–      94.4  0 / all
busybox-001                          9     0    3   -b-       0.4  3 / all
busybox-001                          9     1    1   -b-       0.4  all / all

只让busybox-001只运行一颗cpu
# xl vcpu-set busybox-001 1
# xl vcpu-list
Name                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                             0     0    0   r–      95.2  0 / all
busybox-001                          9     0    3   -b-       0.6  3 / all
busybox-001                          9     1    –   –p       0.5  all / all
(6)xl获取信息
# xl info
当前hypervisor信息

# xl domid busybox-001
9

# xl domname 9
busybox-001

# xl dmesg busybox-001
启动时信息

# xl top busybox-001
查看domain资源排序命令

(7)关于网卡
# network-attach
添加块儿网卡

# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0

添加网卡:
# xl network-attach busybox-001 bridge=xenbr0

验证:
# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
1   0  00:16:3e:1f:06:07     1     4      8  1280/1281        /local/domain/0/backend/vif/9/1

验证:
# ifconfig -a
vif9.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:128 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b)  TX bytes:85791 (83.7 KiB)

vif9.1    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
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:32
RX bytes:0 (0.0 b)  TX bytes:6287 (6.1 KiB)

xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:13:E0:CF
inet addr:10.0.0.208  Bcast:10.0.0.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe13:e0cf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:12309 errors:0 dropped:0 overruns:0 frame:0
TX packets:5822 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2376281 (2.2 MiB)  TX bytes:1105969 (1.0 MiB)

查看虚拟机网卡:
# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
1   0  00:16:3e:1f:06:07     1     4      8  1280/1281        /local/domain/0/backend/vif/9/1

拆除一块儿网卡
# xl network-detach busybox-001 1

验证:
# xl network-list busybox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
(8)磁盘管理:
######创建一个磁盘映像文件
# qemu-img create -f qcow2 -o ? /srv/xen/busybox1.img
Supported options:
size             Virtual disk size
backing_file     File name of a base image
backing_fmt      Image format of the base image
encryption       Encrypt the image
cluster_size     qcow2 cluster size
preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
size     虚拟磁盘空间大小
backing_file  指明后端文件名称
backing_fmt   指明后端文件格式
encryption   加密虚拟磁盘映像文件
cluster_size  簇大小
preallocation   off,metadata(只创建元数据),full全部分配空间

###热插拔进入虚拟机

/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn’t contain a valid partition table

# qemu-img create -f qcow2 -o size=2G,preallocation=metadata /srv/xen/busybox1.img
# du -sh /srv/xen/busybox1.img
524K    /srv/xen/busybox1.img

#####插入虚拟机
# xl block-attach busybox-001 ‘/srv/xen/busybox1.img,qcow2,xvdb,w’

验证:
/ # fdisk -l

Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvda doesn’t contain a valid partition table

Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvdb doesn’t contain a valid partition table
验证:
# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   1      4     13     8        /local/domain/0/backend/qdisk/1/51712
51728 0   1      4     14     57       /local/domain/0/backend/qdisk/1/51728

#####卸载磁盘
# xl block-detach busybox-001 51728
验证:
# xl block-list busybox-001
Vdev  BE  handle state evt-ch ring-ref BE-path
51712 0   1      -1    -1     -1       /local/domain/0/backend/qdisk/1/51712

###查看虚拟机up时间
# xl uptime busybox-001
Name                                ID Uptime
busybox-001                          1  0:13:05
(9)创建虚拟机
干跑:
# xl -v create /etc/xen/busybox -n

直接连入控制台
# xl -v create /etc/xen/busybox -c

进入控制台
# xl console busybox-001

退出控制台:
ctrl + ]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值