admin 发表于 2023-3-13 15:07:45

xen 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 box-001 /tmp/box-001.img/etc/xen/box
Saving to /tmp/box-001.img new xl format (info 0x1/0x0/888)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536100%
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                                     01024   1   r—–      88.0
恢复:
# xl restore /etc/xen/box /tmp/box-001.img
Loading new save file /tmp/box-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/65536100%
验证:
# xl list
Name                                        ID   Mem VCPUs    State    Time(s)
Domain-0                                     01024   1   r—–      90.7
box-001                                  9   256   2   -b—-       0.0
(2)暂停与继续:
pause:# xl pause box-001
unpause:# xl unpausebox-001
(3)关机与重启:
shutdown:要虚拟机支持关机命令
reboot:重启
(4)保存与恢复:
保存:
# xl save box-002 /tmp/box-002.img/etc/xen/box
busybox-002 is an invalid domain identifier (rc=-6)
# xl save box-001 /tmp/box-001.img/etc/xen/box
Saving to /tmp/box-001.img new xl format (info 0x1/0x0/888)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536100%
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                                     01024   1   r—–      88.0

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

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

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

# xl vcpu-list
Name                              IDVCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                           0   0    0   r–      94.40 / all
box-001                        9   0    3   -b-       0.43 / all
box-001                        9   1    1   -b-       0.4all / all

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

# xl domidbox-001
9

# xl domname 9
box-001

# xl dmesgbox-001
启动时信息

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

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

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

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

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

验证:
# ifconfig -a
vif9.0    Link encap:EthernetHWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST MULTICASTMTU:1500Metric: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:EthernetHWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric: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:EthernetHWaddr 00:0C:29:13:E0:CF
inet addr:10.0.0.208Bcast:10.0.0.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe13:e0cf/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric: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-listbox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   000:16:3e:75:d5:57   0   4   14   769/768         /local/domain/0/backend/vif/9/0
1   000:16:3e:1f:06:07   1   4      81280/1281      /local/domain/0/backend/vif/9/1

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

验证:
# xl network-listbox-001
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   000: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/box1.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/box1.img
# du -sh /srv/xen/box1.img
524K    /srv/xen/box1.img

#####插入虚拟机
# xl block-attach box-001 ‘/srv/xen/box1.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 box-001
VdevBEhandle 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 box-001 51728
验证:
# xl block-list box-001
VdevBEhandle state evt-ch ring-ref BE-path
51712 0   1      -1    -1   -1       /local/domain/0/backend/qdisk/1/51712

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

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

进入控制台
# xl console box-001

退出控制台:
ctrl + ]


admin 发表于 2023-3-13 15:12:54

# xl destroy 2
libxl.c:764:libxl_domain_destroy: xs_rm failed for /xapi/2: No such file or
directory
# xl rename 2 a
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     01024   2      r--    251.9
a                                          2   0   1      --d52657.4
Mini-OS                                    4    32   1      r--      0.0
# xl destroy 2
libxl.c:764:libxl_domain_destroy: xs_rm failed for /xapi/2: No such file or
directory
# xl destroy a
a is an invalid domain identifier (rc=-1)
#
页: [1]
查看完整版本: xen xl 工具使用