|
+ o: r! ^7 ^! u8 u' X$ L
#头条创作挑战赛# 2 J. ]1 g0 M1 @+ |
7 h7 I1 C/ \9 i' j# v# l
一、Multipass是什么?' W# {0 F8 V) z9 O8 O+ { ? a
官网:https://multipass.run/ / k; K; h& J" E. {) ^; e- t
" j* q( }4 g! U* S4 y( J0 |0 d
一提到虚拟机大家一般都会想到VMvare和Virtual Box这两个的虚拟机软件,这两个软件一个比较麻烦的地方是安装完虚拟机以后还需要下载操作系统镜像。小编偶然间发现了Multipass。这款轻量级的虚拟机管理器,仅需一个命令就可以快速安装Ubuntu 环境。
* E1 x% i% u9 w" V7 l. G Multipass是一个轻量虚拟机管理器是由 Ubuntu 官方运营的公司 Canonical 推出的开源项目。运行环境支持 Linux,并且提供了一个命令行界面来启动和管理 Linux 实例。下载一个全新的镜像需要几秒钟的时间,并且在几分钟内就可以启动并运行 VM。
, ?6 N2 h* _/ O) P 功能特点 简单易用:Multipass 提供了一个简单而直观的命令行界面,使您可以轻松创建、启动、停止和删除虚拟机实例。快速部署:通过使用预先配置的基础映像,Multipass 可以在几秒钟内快速启动虚拟机。轻量级:Multipass 虚拟机非常轻量,占用的系统资源较少,这使得您可以同时运行多个虚拟机实例而不会拖慢您的计算机。与云平台集成:Multipass 支持与云平台(如AWS、Azure和GCP)集成,使您可以将虚拟机实例部署到云上。高度可定制:Multipass 允许您为虚拟机实例选择不同的操作系统和配置选项,以满足特定的需求。# k' B2 w8 R E# j9 i+ a/ M
9 G, m! B4 x- b8 i
Multipass支持跨平台,所以可以在Linux、 Windows 和 macOS上进行安装,本文采用Win10操作系统来进行Multipass安装等相关知识的介绍。 " p- k* d4 v% P4 w+ Z5 w4 W
本质上而言,Multipass用于管理各平台上的虚拟机引擎,例如: Hyper-V 和 VirtualBox(Windows)
6 J( u0 f+ ?! `/ p KVM(Linux)) A$ ^5 Z# D3 P+ v- m' A
HyperKit(macOS)所以使用前需要安装相应的虚拟机引擎,再通过Multipass进行管理。
) z% ~: C% a7 b( m* B* n% u! C 二、 安装虚拟机Virtual Box
: e) I6 f$ m3 Y: r% `/ Y0 {5 p- { 通过官网下载免费的Virtual Box并安装。 https://pan.quark.cn/s/4e34a2f09f56
# Z. W/ Y; g0 }/ g) h( B' n ) _4 E' J$ q" K/ U& M
- n/ @1 G! R+ W8 j. q. G; D 三、安装Multipass0 Z! i/ D1 t; b" o& h' ~
下载地址: https://pan.quark.cn/s/4fe07ab88e7e: G* j4 C. A% w' ]: r9 H
安装包非常小,仅有20多M。 ' K% ~) J$ y9 ?+ O5 C. p1 E
# j* _ E$ [: r" v1 y
双击安装,接着下一步即可。
6 k7 T. \0 c( d+ o, V+ s+ c
3 o: }8 C f7 A9 c* j
# U2 u, _0 N0 U, S* _% K8 h* \ 我安装过Virtual Box,所以选择了【Oracle VM Virtual Box】 ' p5 s) t, k1 Q$ _9 a
0 e! G7 X' C2 r3 B, k0 y 添加环境变量。 - e; N1 T* ~& H# ]$ }" R7 l5 i
3 L/ i8 H! \/ C/ p: i" j' A 选择安装路径。
0 H0 z. L7 f: F1 n1 {6 N + M; Y) a4 ?9 k# ?) _3 ]" P
# C# A8 H* w7 u: l; w 安装
/ {* I* D$ F }8 ]. Y
1 _( ~! `3 m! }; G% ^" q9 n
[+ k0 j" i2 b" M! C 安装完成之后就可以使用了。
: C( k' U9 b+ L/ t) H. ]7 U 四、使用Multipass9 A" p, W* m$ J" a5 I% e( e/ M
4.1 Multipass的使用帮助
$ B9 b- u9 y& o, B7 { 在命令行输入multipass,可以获得Multipass的使用帮助。 C:\Users\Administrator>multipass
; ?2 C, N, t V6 R% b5 R. F; g$ ?: a Usage: multipass [options] <command>
! n) z' v4 s+ L. U" q4 i Create, control and connect to Ubuntu instances.; d4 D. ~2 G0 L
6 h2 H. X+ O; u; _8 g3 v# r8 P4 g! ~9 u
This is a command line utility for multipass, a6 ?( p0 P% c; X' B
service that manages Ubuntu instances./ R4 u4 u: J" O
B4 C! f# \8 K7 E. g5 q
, h1 H8 h" S3 O: U Options:: \- j5 m" W: J7 g2 E6 @
-?, -h, --help Displays help on commandline options.
( _# \# E+ ]; R: \ --help-all Displays help including Qt specific options.& Z6 m: m$ ^ m
-v, --verbose Increase logging verbosity. Repeat the v in the short
8 z3 \5 r% J4 s% l# w option for more detail. Maximum verbosity is obtained with 40 R6 n- j0 E' X- O* w
(or more) vs, i.e. -vvvv.
! {/ e6 z, B7 _9 z P5 k/ G p0 V& a0 M& l7 f1 o
0 a% [' q9 q1 y4 |4 G) r Available commands:& k! w& P# |; o# i7 G6 W
alias Create an alias
5 r: u: I% r( ~# _, { aliases List available aliases
% c! F6 z7 z$ X% p$ H9 o authenticate Authenticate client
( m; w+ k a: I0 l delete Delete instances
( G( P+ A5 d4 T2 C: |3 p; F* D exec Run a command on an instance
5 q0 h$ S3 l, B find Display available images to create instances from
; D' M8 z7 V8 r% h5 F& w( e+ W. t get Get a configuration setting
/ y* T' w5 B( Q; s0 u( x) I help Display help about a command1 }; h; ^4 c! S. p$ P
info Display information about instances
; D4 H: l( _5 F launch Create and start an Ubuntu instance
U. N E, B6 S$ U; K+ j# Q& N list List all available instances" U, C2 G- b/ J8 m
mount Mount a local directory in the instance9 v2 b7 \: \. z! c7 U
networks List available network interfaces& [/ U* z: p1 ^/ v, t
purge Purge all deleted instances permanently
; m7 o1 m b% T$ y: p recover Recover deleted instances
0 R7 b2 e% G% G( s restart Restart instances
1 d# B$ K0 h/ s- h( r& l% r* i set Set a configuration setting0 p+ L3 Q- Q) j
shell Open a shell on a running instance4 [1 C9 M' f9 D
start Start instances J( Z3 z- F, H3 @
stop Stop running instances
# h, ]1 N" S9 q; E( G" J6 J- V suspend Suspend running instances
2 |7 A- b e6 P# J( F% C transfer Transfer files between the host and instances
, \1 h; N W' B. j) X' h) q% K5 T/ G umount Unmount a directory from an instance/ \& q+ v: Z: [* D* P3 X
unalias Remove an alias: @8 d7 t/ i }* O# R0 }
version Show version details$ F& r( e# N! e9 b @
查看安装的Multipass版本信息C:\Users\Administrator>multipass version( ~3 O' m! J# C7 U1 N' ?. V1 {6 Q7 H
multipass 1.9.1+win4 m4 B4 A. P+ D* e6 ?. K
multipassd 1.9.1+win, S7 B2 S3 b/ O4 Y0 J
4.2 创建实例
# r- f: b3 M9 P: ]" T2 E multipass launch命令用于创建实例。 5 O6 G, J9 o$ w
可以通过下面命令,创建实例。 multipass launch --name <实例名称>4 U# x/ f3 L' b/ o* }
multipass launch -n <实例名称>
0 v0 l4 W' T4 Y: C/ g9 r1 ` 如果不指定name参数,multipass会随机生成一个实例名。
( |: Y- Q$ O5 D# z2 r$ U 查看创建的实例。 C:\Users\Administrator>multipass list% c$ U9 \; _3 O/ c* M* g
No instances found. --》当前没有创建任何实例( O/ `! ]) z. d3 |
例: --下载镜像: ?& z. P' f: V
C:\Users\Administrator>multipass launch, z. ^8 G3 R: k$ y+ Q6 z; u7 M, U0 N. U
Retrieving image: 5%--创建实例acceptable-joey; @2 `5 A2 b* }8 m
C:\Users\Administrator>multipass launch: q/ Z8 y$ o; _& R' T
Starting acceptable-joey -
- V7 i$ g2 T& T: j' s) s5 [' c3 m ** launch第一次创建实例时会首先消耗几分钟下载镜像,之后launch会直接创建实例。 , z" J2 t8 J6 U- c* l
4.3 查看实例列表 C:\Users\Administrator>multipass list
8 |5 y4 f5 S9 h' ~% _- l Name State IPv4 Image
9 E7 m$ ]- ?" I, g+ }' W4 j acceptable-joey Running N/A Ubuntu 20.04 LTS
/ r! f" E. F0 `+ B' j: F 通过如下命令查看实例信息 multipass info <实例名称>例:C:\Users\Administrator>multipass info acceptable-joey
; y9 B: \7 Q: h, n/ T; G! e Name: acceptable-joey( M# J- Q) @1 M$ c K
State: Running% G' U; V: j! T+ F# e6 D& s) {( i3 f
IPv4: N/A
7 f S( ]6 a! D3 | Release: Ubuntu 20.04.4 LTS
9 ?4 B. h% v6 W. `# G: j- G2 [ Image hash: 75a04c7eed58 (Ubuntu 20.04 LTS)
. @& G6 w* q# V! C3 a% h9 \* y Load: 0.24 0.17 0.07; y3 K! }4 m9 U N/ n9 z& v2 ~* j
Disk usage: 1.4G out of 4.7G7 C$ K1 K" x' @8 \4 j6 U
Memory usage: 137.7M out of 976.9M
) {" i; L% ?/ d# {+ i* H+ \ Mounts: --
& e7 }& x5 m" v- S( E! x/ o1 m! e 创建命名的实例: C:\Users\Administrator>multipass launch -n test
0 v8 [' K" Y1 b; T H- R$ ? Launched: test7 g2 z" G/ _5 H
Z7 B( f* c9 C$ z$ {& {! ^* `
C:\Users\Administrator>multipass launch --name test25 H' } r& b, ]0 E
Launched: test2
4 p" o* m# W! z9 J
4 c" ^* m7 m5 o. E+ V& ?5 v( {) Y" x3 V7 k$ J- S/ h
C:\Users\Administrator>multipass list. q$ T6 S- g4 T1 [, N
Name State IPv4 Image' L& g/ d- N9 j( v! n0 _1 M/ i
acceptable-joey Running N/A Ubuntu 20.04 LTS
% k, L) B: L, B* n test Running N/A Ubuntu 20.04 LTS
' F/ h, w4 }5 L, B9 { test2 Running N/A Ubuntu 20.04 LTS删除实例multipass delete test2 --purge
; \0 n/ C4 O6 I4 e4 n C:\Users\Administrator>multipass list
+ \/ ` k0 q+ e* v, i- A8 L Name State IPv4 Image
o; E( h# ~' O0 {$ `2 x acceptable-joey Running N/A Ubuntu 20.04 LTS+ D$ }0 a6 i L# m0 y& O2 p
test Running N/A Ubuntu 20.04 LTS4.4 关闭和启动实例 C:\Users\Administrator>multipass stop acceptable-joey
# {4 D$ H" t6 X" ~' ~0 X5 k
1 z- L9 c& n* i. s5 Q
, W& m4 F7 t# P# l8 a) R0 d% { C:\Users\Administrator>multipass stop test) J& B6 }' T' z2 l# o
8 i2 ^' M# E G1 e2 Q
1 @' B, o3 k. g8 i6 ~# o7 S C:\Users\Administrator>multipass list: y! i* c% C$ [* c/ a
Name State IPv4 Image
# P+ u2 ^3 w) X acceptable-joey Stopped -- Ubuntu 20.04 LTS, T( w2 t! r5 A8 R" \, I/ W a
test Stopped -- Ubuntu 20.04 LTS
# ?1 j q1 t' O- ^& A7 x0 Q+ v
: F! w* A3 F. Q' V+ s0 o, y; j! B1 d# r
C:\Users\Administrator>multipass start test
. F5 ?/ F3 A) _, f6 H: o: Z+ m' w/ D3 d; p& E
2 ^& x6 ?$ s( C! H C:\Users\Administrator>multipass list
4 y" q( k/ |: b Name State IPv4 Image1 e' |4 e0 F, n+ K) C
acceptable-joey Stopped -- Ubuntu 20.04 LTS0 Y) g" M! h" \" m
test Running N/A Ubuntu 20.04 LTS
/ ~% D" G9 _1 ]2 l+ S 4.5 使用实例
( P6 ~2 s) Z3 g/ j 通过multipass shell 开始使用实例的命令行。 multipass shell <实例名称>例:C:\Users\Administrator>multipass shell test8 U9 \6 Q9 V! d4 Q) b# J( u* b
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-120-generic x86_64)
" P+ [7 A* I7 q3 R# {% v% W/ P5 \5 q
, z) e8 d8 E- d% X6 J9 T6 A# K; k+ i1 Z
* Documentation: https://help.ubuntu.com: T3 i: C3 Z6 G. u. v8 z
* Management: https://landscape.canonical.com" ~, x/ T7 i0 h7 g
* Support: https://ubuntu.com/advantage$ s% F, u2 c- I# x' f% }
: ^8 Z. S9 E' Y3 x1 o& W2 _% v
4 D& Z' u9 T, J0 o" ] System information as of Wed Jun 22 21:29:00 CST 2022
: Z/ s8 P$ K( M; Q4 @1 V( K" E
$ t5 U# D8 `6 m% t
4 ]' F' Q) ?8 d2 m$ l8 q4 P( F5 U1 C System load: 0.0 Processes: 102
, Q. E2 n: p: a4 ]: {$ i$ w Usage of /: 29.1% of 4.67GB Users logged in: 0
1 B8 Z* a8 X4 r- k6 o0 n# D% O Memory usage: 19% IPv4 address for enp0s3: 10.0.2.15
1 L+ k+ f# k0 C2 T! O/ ? Swap usage: 0%, n& ]& z7 ~- s2 w( a8 l; y
$ ?: C$ u) @' u2 i
' l- M2 i# ]+ P% h! h7 J
3 H n0 J3 X9 _' S7 c' N
' _' q- o7 q( B8 h+ S 1 update can be applied immediately.
5 ?+ ]( e. E' L5 s: f# b7 s To see these additional updates run: apt list --upgradable
) T" n4 A* u2 G2 ^% F, H$ V5 @- S3 U1 c2 [2 n9 J/ j7 E
7 H$ G; x, C$ y+ h$ N
8 k5 X6 e* J8 V& q$ K
, D \' L9 [* W; @/ ^* q2 V To run a command as administrator (user "root"), use "sudo <command>".
7 _% h( k& U/ C- q See "man sudo_root" for details.6 q! y* k% c$ b- n
( a. j3 {3 B) n, O* _! D% l" R% ?0 M2 i2 r6 H) |1 \+ Q
ubuntu@test:~$ pwd8 D' N0 j6 b: a
/home/ubuntu
3 j8 O3 k+ d7 ?. p% y ubuntu@test:~$ hostname
' G& ?5 L% I' h2 c- v. P test
$ Z# b: V: v4 J3 _4 C+ [9 [% F ubuntu@test:~$ id5 t6 {0 [( |+ e ~* A
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),117(netdev),118(lxd)
@) r) n3 }! M$ z9 D 这就是一台ubuntu的虚拟机,可以尽情使用了。是不是非常方便!
) B( ~7 e/ o5 e* L4 t- H7 O2 z6 U3 L4 F$ B$ O
7 h7 N, _7 E! ~) R9 ?/ @ |