找回密码
 注册
查看: 555|回复: 1

xen xl 工具使用

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2023-3-13 15:07:45 | 显示全部楼层 |阅读模式
这里是Xen手册页的xl文档:xl(1)。
/ i$ J3 J  T4 W3 c' q0 Q# W5 O我们将创建一个CentOS-6和一个CentOS-7 HVM。
. n2 B- \2 R$ ~9 _首先,我们需要虚拟机的配置文件。 在xen包中有一个名为/etc/xen/xlexample.hvm的示例HVM配置文件。 您可以查看该文件并在此HVM文档中查看:xl.cfg(5)
  ^, J% _- M$ z' h5 y文档:http://xenbits.xen.org/docs/4.6-testing/man/xl.1.html+ r) h7 C* }/ ~& F" a3 ?0 Y# Q& K- N
这里是我们的配置文件..我在/ etc / xen / config.d中创建了一个保存配置文件的目录。
( w; _) c# z3 ]+ r(1)保存与恢复:
- v. E% u' s- O( U4 N保存:9 Z" y. ~; ]7 }1 n7 g& }
# xl save box-001 /tmp/box-001.img  /etc/xen/box
, Y1 J# U9 }) u0 s& b: DSaving to /tmp/box-001.img new xl format (info 0x1/0x0/888)
! k0 d( D$ I2 o. Uxc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%
# [* L# [: K; O7 f( elibxl: info: libxl.c:1717:devices_destroy_cb: forked pid 5981 for destroy of domain 8
$ |) Z  H% E" |$ o" o
2 p: X1 M8 a" s* M# k- E/ e3 P# xl list
7 U# L5 b" K  H' Z, M! p5 B" PName                                        ID   Mem VCPUs    State    Time(s)
$ V9 z3 {; ?  jDomain-0                                     0  1024     1     r—–      88.0
. [: L: B" z0 u/ U1 m! W* A: L恢复:+ [, A* J2 O6 K
# xl restore /etc/xen/box /tmp/box-001.img
: v; P7 Z( s5 Z3 F( L9 ]Loading new save file /tmp/box-001.img (new xl fmt info 0x1/0x0/888)+ h2 k& G, A/ g$ q& l" e
Savefile contains xl domain config in JSON format
% M# W, _, J, J: C) Y, C& `* U( qParsing config from /etc/xen/busybox1 }! K  i/ x, `6 a* }9 }& n! `
xc: Reloading memory pages: 65536/65536  100%4 A' A2 \* ^3 u. B2 y: i
验证:3 M7 K, o* q: x) e4 r
# xl list% U% r6 g. D. a$ }
Name                                        ID   Mem VCPUs    State    Time(s)7 l  {# k1 u. m3 D0 X, s: a
Domain-0                                     0  1024     1     r—–      90.7
1 d) K9 J7 c6 W8 ]; M2 V. bbox-001                                  9   256     2     -b—-       0.03 R) d( v- h3 E- B1 U
(2)暂停与继续:
4 }+ h+ y, P! F) |pause:# xl pause box-001% e% Y$ N( A1 O6 f
unpause:# xl unpause  box-001# X! O1 s7 K5 q& Y( d0 U
(3)关机与重启:
( V% U! S' _, k& Lshutdown:要虚拟机支持关机命令& z/ G* m+ T' x+ w
reboot:重启' ?! N' ?( N* Q: W! R
(4)保存与恢复:
5 M2 p" G$ Z' w& f( f+ l( i保存:1 X/ s! f  r3 K8 n$ p: I
# xl save box-002 /tmp/box-002.img  /etc/xen/box
0 x. r/ h! u! e8 {* Z5 qbusybox-002 is an invalid domain identifier (rc=-6)# g' I3 i) z' ?1 f4 N3 N4 c* @
[root@xen net]# xl save box-001 /tmp/box-001.img  /etc/xen/box6 R5 A9 H! a$ |* {% Y
Saving to /tmp/box-001.img new xl format (info 0x1/0x0/888)
. q; a" h  `% S; L0 dxc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536  100%' P4 F+ w! w4 x/ E" v) }0 _7 X( K2 f
libxl: info: libxl.c:1717:devices_destroy_cb: forked pid 5981 for destroy of domain 8
* |2 b7 z8 ^( S7 ?( z: B+ V/ v. R7 q, l& D, v5 T' s' Y' X- X; y) D1 p( M
验证:
4 M; D7 ^, B. H8 o& `! w* t# xl list2 p1 J: e9 r9 O0 m" O
Name                                        ID   Mem VCPUs    State    Time(s)& M' g( C+ X5 [0 ^5 B5 k6 a
Domain-0                                     0  1024     1     r—–      88.0
) T+ f) Y. A6 `1 M
+ ?0 E) N, B7 o4 {1 y1 B! @恢复:6 H8 f4 T; D% b. C1 ?
# xl restore /etc/xen/box /tmp/box-001.img1 Q. W$ o3 @; G$ E! P5 l% Z
Loading new save file /tmp/box-001.img (new xl fmt info 0x1/0x0/888)# M; {9 e) X7 N4 l% P
Savefile contains xl domain config in JSON format
) ]- c/ W3 b0 t+ s+ ZParsing config from /etc/xen/box
% P+ N. U* k, T" sxc: Reloading memory pages: 65536/65536  100%! }( x" o8 ]9 ]( }; y; X0 r
  X  p4 }# D& k) r
验证:4 x/ m( ?4 v) J4 [. ?+ z
# xl list8 @; ^. V$ S) e+ G
Name                                        ID   Mem VCPUs    State    Time(s)# T* e  j$ ?, V+ [# r/ R$ H
Domain-0                                     0  1024     1     r—–      90.7( W8 J1 `4 l0 U: d' H
busybox-001                                  9   256     2     -b—-       0.0' {1 D; O2 Z4 F& y. j/ F2 J
(5)关于cpu:
# Q3 z/ A- l( p# xl vcpu-list
/ w1 Z2 d8 `! g' l0 ]7 yName                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
9 b# ^) C/ J! t/ T  C9 F( i5 _Domain-0                             0     0    0   r–      92.8  0 / all$ q& m& @& d- N6 b
box-001                          9     0    3   -b-       0.3  all / all3 t2 W$ Z3 w$ z4 Q3 g; Y, J
box-001                          9     1    1   -b-       0.2  all / all
, _$ ~' L" i) l7 |# ^) V* [& g- L; G% q7 I+ A  w9 d
让vcpu 0只能运行于物理cpu3上. U4 u5 \: Y" ]/ z  s/ c
# xl vcpu-pin box-001 0 37 g' ]# V% N; M

9 m) O  n7 K% ~" Z- O  F# xl vcpu-list
6 u4 S( O& U3 @* B5 vName                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
2 p! j. I' o  O) GDomain-0                             0     0    0   r–      94.4  0 / all
& H' D2 z9 P/ f7 x$ |( Nbox-001                          9     0    3   -b-       0.4  3 / all9 s* U+ m6 F& f$ v+ p1 j5 I" i! J
box-001                          9     1    1   -b-       0.4  all / all" m0 C# j3 z0 L8 n+ O* U

% ^0 z3 O2 u4 T/ _  W只让busybox-001只运行一颗cpu7 w. }9 z& y# V/ ^+ v  o
# xl vcpu-set box-001 1
" ]4 u9 f$ L& l5 P- v1 x( W# xl vcpu-list
% e( X: A  v# w5 v% e/ \* oName                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
: T0 l2 s9 G/ D+ YDomain-0                             0     0    0   r–      95.2  0 / all7 F8 H( l, S0 @; I7 v0 l. d
box-001                          9     0    3   -b-       0.6  3 / all
  N, l/ [- s8 S8 j$ h2 {box-001                          9     1    –   –p       0.5  all / all
5 B& p5 ]) Z* ?1 @! M* D  Y(6)xl获取信息8 @! N# w/ g0 n0 [
# xl info9 X/ R( m( j, f/ }& {
当前hypervisor信息
2 V1 C. l1 z6 i6 i! s  o
5 P' K% a& s1 y3 w& F/ x$ E# xl domid  box-001) q; h5 M: H3 T1 |& M" n/ F: e
94 O5 S) A6 n+ j; I
# s; p- W! h1 Z% H
# xl domname 9
1 ^! K) L/ Y6 J0 @* ?, | box-0016 V" `- F# j4 c: x
/ Z* y2 J3 e9 K' |& X/ q1 `
# xl dmesg  box-0017 F0 X1 K1 Q# s% x
启动时信息: `8 X# B  o1 O8 F5 U+ [

+ e0 C8 \8 h0 m% E+ a# xl top  box-001
; c/ S6 E' s$ m0 e* X$ S查看domain资源排序命令
' n  S" U9 D* c4 |  E7 y; t
" h7 g3 [5 }9 C4 {# [(7)关于网卡! L0 }9 g1 K' S2 f9 E- Z& J
# network-attach+ o4 K0 e, q& g1 e* z
添加块儿网卡9 `6 h7 g& M- o9 j. [" s6 y2 Y
4 K5 ~; }! @% d) V9 b# A
# xl network-list box-001
. z3 S) \+ b1 {, c8 LIdx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path7 C6 V5 Y% V5 j
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
4 f! i. ?1 `; l" g4 P2 x, u! a5 m/ ^3 _6 o
添加网卡:& {8 I) f, m, E4 z
# xl network-attach  box-001 bridge=xenbr0/ e" x8 C/ m3 s, P# |

# Z( z2 K, d7 m4 w6 h  W验证:! e5 e! X7 ?8 w, Y. l! z
# xl network-list  box-001
: \8 g! u) @4 f- {4 u) KIdx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
7 Z5 D" H( e" j3 F* V9 O# E2 `. q0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
) i. ?! i' F$ W1   0  00:16:3e:1f:06:07     1     4      8  1280/1281        /local/domain/0/backend/vif/9/1* f( G! R/ w/ Q) ]6 s( T7 I

* P! z$ j. l7 {) Y% x- j4 _6 z' k+ e7 g验证:
: h3 H2 T; O+ `' A0 l# ifconfig -a6 K6 A3 @/ D* ~$ L+ }; R
vif9.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF  Q5 _" V3 a$ z/ \) z. g
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link1 X# ?8 J& L0 Z. ^+ z6 `0 n
UP BROADCAST MULTICAST  MTU:1500  Metric:1
) e- u9 U1 `' o3 f& _# IRX packets:0 errors:0 dropped:0 overruns:0 frame:0
6 j7 X2 z& A5 _! q" S* zTX packets:128 errors:0 dropped:0 overruns:0 carrier:0! Q; |0 s3 u: i  Q1 {& N6 r
collisions:0 txqueuelen:32, L( Q; N/ m" b) i6 @
RX bytes:0 (0.0 b)  TX bytes:85791 (83.7 KiB)
% p3 r. E5 s: M6 @& P( f8 l6 y
9 ]% K1 J+ Y% A2 m' t- f4 a; Xvif9.1    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF) a5 C9 K6 K! L$ [
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
9 N* I7 M' l6 V, V1 R1 X& ]$ _; `UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
/ ]; J, m+ }+ FRX packets:0 errors:0 dropped:0 overruns:0 frame:0
6 T- Q8 H" F/ Z& Z3 y) H  qTX packets:14 errors:0 dropped:0 overruns:0 carrier:0
- C9 z4 U; r: V. @' Q$ [) Acollisions:0 txqueuelen:32; E; m" N2 W, u- {0 I$ H
RX bytes:0 (0.0 b)  TX bytes:6287 (6.1 KiB)  n% G  E2 r/ g  a; A% u8 S) ?: g
( K9 `" R# |8 X
xenbr0    Link encap:Ethernet  HWaddr 00:0C:29:13:E0:CF6 B" E: k( }9 Y8 h7 S* |
inet addr:10.0.0.208  Bcast:10.0.0.255  Mask:255.255.255.08 t7 V- E% F2 j
inet6 addr: fe80::20c:29ff:fe13:e0cf/64 Scope:Link: M( a! w  D+ q6 ?8 e
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
2 }0 V' i0 C) m" T4 ^% N. DRX packets:12309 errors:0 dropped:0 overruns:0 frame:01 K" |0 X0 ~' X- w& o
TX packets:5822 errors:0 dropped:0 overruns:0 carrier:0
; h$ S- A0 @; ]! w0 ?$ Zcollisions:0 txqueuelen:10009 h6 V- o1 @' r% s6 M0 g- ]
RX bytes:2376281 (2.2 MiB)  TX bytes:1105969 (1.0 MiB)1 n- q% Q% V' c( \( u

3 Q! |  d3 L! {查看虚拟机网卡:
" F: n/ R) V2 q* T9 |$ Z' b$ E# xl network-list  box-001
+ a- w1 x( I. z; _' V4 w# S/ G3 |Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
( ~( t  ^5 E8 O" u2 \  C- @- s9 J0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
4 m# H) U% w* t, ?0 N! V& K1   0  00:16:3e:1f:06:07     1     4      8  1280/1281        /local/domain/0/backend/vif/9/1
, v7 A9 z% c: R0 o) l: v$ [- N' t/ @6 V  @  z$ E  N2 w" A
拆除一块儿网卡
" `3 I$ W' y: D/ N3 D4 X4 d) M# xl network-detach  box-001 10 S1 }2 `$ {$ V. K0 g2 {/ `: O

& e0 a# j6 b; k9 Y验证:
7 Z0 Q# h* O) B6 {5 l7 n# xl network-list  box-001* N+ y7 W4 B: J, m4 C/ M' P& r
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path* T" Y' Y- d; _# w# t7 A) T
0   0  00:16:3e:75:d5:57     0     4     14   769/768         /local/domain/0/backend/vif/9/0
+ D3 S6 b- f( U$ W3 @(8)磁盘管理:6 K% A" B9 M: s8 G! m* r2 P4 i
######创建一个磁盘映像文件; P, L9 h! e( M/ e7 `, \& m$ s2 V
# qemu-img create -f qcow2 -o ? /srv/xen/box1.img9 A/ P* `0 \7 o9 x5 K6 `# J9 W
Supported options:0 X! Z% ~8 D9 z$ ]. ?( V$ H
size             Virtual disk size+ b3 Z7 @( G( J' V( }# R$ q
backing_file     File name of a base image8 n# W* {8 _/ x2 L# y! N; j
backing_fmt      Image format of the base image5 c- N$ Z2 t( v1 \
encryption       Encrypt the image& [1 ~9 G" n, z! n& j
cluster_size     qcow2 cluster size$ W- o! E* V- q! R# _
preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)0 n! f( @& S* y& ^
size     虚拟磁盘空间大小! t5 A" i6 _- I9 l! u
backing_file  指明后端文件名称
4 p, R% y& |5 D* ?3 Rbacking_fmt   指明后端文件格式
; x+ S. B( P9 I+ {encryption   加密虚拟磁盘映像文件+ e0 O0 M) v6 b. |; D) d
cluster_size  簇大小9 |6 F# g& l+ ^- L8 X
preallocation   off,metadata(只创建元数据),full全部分配空间
0 E+ ]& G5 O# b9 g9 P
  ]; r( H' Z4 U; y) N###热插拔进入虚拟机* {/ H# S+ {! ?1 f
, R" Q* g; n+ \) [, W" `
/ # fdisk -l
& H6 P# Q( J9 ~, `$ c3 ^& w( Z, \# J) W0 c. j: L
Disk /dev/xvda: 2147 MB, 2147483648 bytes0 R5 ?1 q3 c9 W4 k# x8 C' Q
255 heads, 63 sectors/track, 261 cylinders
6 v0 _* t9 s% fUnits = cylinders of 16065 * 512 = 8225280 bytes
3 p+ L3 _: [! H  y" ~1 j; I; `( k" h) v5 Q, A# p& Z" q. B, b9 W
Disk /dev/xvda doesn’t contain a valid partition table
7 k# ?0 Z- m/ F! H6 p
+ ^% V9 O& \5 L" T1 V9 g# qemu-img create -f qcow2 -o size=2G,preallocation=metadata /srv/xen/box1.img7 [* ~/ _0 W) D
# du -sh /srv/xen/box1.img' `* O& u# ^- Y8 k- @' @0 {
524K    /srv/xen/box1.img
4 }. D1 S  ^" @% ?, H3 A* M  ?( _1 T; q& W7 {/ e) l, K3 K
#####插入虚拟机
( _; [& A, x! O. l/ y9 o# xl block-attach box-001 ‘/srv/xen/box1.img,qcow2,xvdb,w’
1 B: \) }2 o. h5 G9 H7 H+ Y
( D6 p, ~* {- k9 Z' ]验证:
9 N" A1 `+ X% P/ # fdisk -l
% N, S/ M. k* _" e$ S9 [( B
  p: @. u( S$ U) d* g- CDisk /dev/xvda: 2147 MB, 2147483648 bytes
) G5 N/ j0 [( h3 G4 T( ]" b255 heads, 63 sectors/track, 261 cylinders" |$ R" H$ p- z3 s
Units = cylinders of 16065 * 512 = 8225280 bytes
+ }1 {. N0 Y1 C) @! Y( C. |8 {- R+ ]" g# ^& U
Disk /dev/xvda doesn’t contain a valid partition table: [& Q& `3 @4 N) F. ]

& h! U- e* t7 cDisk /dev/xvdb: 2147 MB, 2147483648 bytes5 Y4 q2 f3 B1 o4 B7 P
255 heads, 63 sectors/track, 261 cylinders/ o' d1 j! i' ?1 F& M
Units = cylinders of 16065 * 512 = 8225280 bytes! {4 i% ~- `: ]. x( O( b# o
2 Y9 p: I& w. F: N' l
Disk /dev/xvdb doesn’t contain a valid partition table
; F* |% P, W, u, @4 W验证:
( s; j, @1 ]3 u# t; O8 ~- G# xl block-list box-001
! E- L3 R) s8 ]5 p5 h$ sVdev  BE  handle state evt-ch ring-ref BE-path; ?7 s9 ~, M& `- ?1 @
51712 0   1      4     13     8        /local/domain/0/backend/qdisk/1/51712. d0 E$ p+ o3 H
51728 0   1      4     14     57       /local/domain/0/backend/qdisk/1/517285 ^8 C5 a+ a; A& u, Q6 y) q9 ~
! g% o* l( u; S. ~4 h  {
#####卸载磁盘
' ^0 q/ q. w7 D- A! W7 Q5 Z0 ^# xl block-detach box-001 51728
- F/ p5 M2 h) ?: j5 T* U5 C验证:
: _$ o/ R4 ~3 D  R8 {1 ^# xl block-list box-001& {/ C  j: L' ]- z$ x9 R
Vdev  BE  handle state evt-ch ring-ref BE-path: d3 z: s4 p. c  H2 ?4 j; S
51712 0   1      -1    -1     -1       /local/domain/0/backend/qdisk/1/51712
: W% |' M" l8 G! H
) U/ M% c, D6 O9 }: R' w2 o$ K1 L7 u###查看虚拟机up时间9 ?( B2 o# z/ P% u3 `
# xl uptime box-001
6 M: T4 I+ m7 j$ z) ~. I! g; d5 CName                                ID Uptime2 R5 c5 O+ e" e: K
busybox-001                          1  0:13:058 r2 w  l8 {  n) W0 ]
(9)创建虚拟机. M5 E& h$ F% {# Z' B7 O' t
干跑:
5 Q$ q9 ]0 B3 d) Q. A# xl -v create /etc/xen/box -n
( v. K2 ^, S% p2 ?$ E
  U! H2 r$ ]4 E' M- H! s直接连入控制台
! o8 {. @* P$ y) n+ Z! [- A# xl -v create /etc/xen/box -c' U6 B& `7 H# J

' c* K( u1 x3 U& Q4 D1 A) }进入控制台
: \# S" u% n' D8 \( Z( F# xl console box-001
7 ?' {. k7 k* s' I& U6 V. n
# a+ o, Z" t4 d( f退出控制台:5 Z; P& D7 _  P% f6 i& H5 q9 n
ctrl + ]
; G* G( s$ ?: n9 r9 ~2 F# J4 i
' G+ k5 o* \( i+ F: A! K8 h! b: l' U- M

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-3-13 15:12:54 | 显示全部楼层
[root@centos libxl]# xl destroy 2
% M* q7 ?# @) t8 t7 X[0] libxl.c:764:libxl_domain_destroy: xs_rm failed for /xapi/2: No such file or
$ G5 {3 E) d0 \; t0 @directory
, g% Z! b0 x* W[root@centos libxl]# xl rename 2 a! p% P" _1 X) N0 {+ d
[root@centos libxl]# xl list8 @& s+ b& x6 B: n; w9 `, ?7 P9 b
Name                                        ID   Mem VCPUs      State   Time(s)1 A0 q. K  A1 {8 B
Domain-0                                     0  1024     2        r--    251.98 M0 |+ z) y8 b
a                                            2     0     1        --d  52657.45 p8 F& T& L2 T1 K
Mini-OS                                      4    32     1        r--      0.0
+ u0 E8 p/ t0 ?5 ~) t[root@centos libxl]# xl destroy 2
( u) m# i- F3 D$ B4 d  c[0] libxl.c:764:libxl_domain_destroy: xs_rm failed for /xapi/2: No such file or ! \2 \! Y) _0 U6 n& y
directory/ r/ t9 A. s& E4 i& a3 g% ^& r
[root@centos libxl]# xl destroy a: g/ _" m5 ?5 e) x: C( c, F2 M
a is an invalid domain identifier (rc=-1)+ I. V5 m6 |9 M3 f  n8 a
[root@centos libxl]#
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:22 , Processed in 0.018068 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表