Multipass,一款开源的轻量级的虚拟机!

       Multipass 是一个轻量级的虚拟机管理器,由 Ubuntu 运营公司 Canonical 所推出的开源项目。运行环境支持 LinuxWindowsmacOS。在不同的操作系统上,使用的是不同的虚拟化技术。在 Linux 上使用的是 KVMWindow 上使用 Hyper-VmacOS 中使用 HyperKit 以最小开销运行VM,同时它还可以在 Windows 和 macOS 上使用 VirtualBox,支持在个人电脑上通过简单的命令行快速创建Docker、Minikube及其他基于Ubuntu的轻量级云服务器,非常适合开发和测试人员使用,可以抛弃收费的VMware了。

     注意:如果是想用Hyper-V,则操作系统版本需要是Windows 10专业版、企业版、教育版本的1803及以上版本,若使用VirtualBox,则Windows 10家庭版和其他版本都是支持的,Win11更没问题。

       本文介绍的是在Windows+Virtualbox下安装使用,其他请参考官方文档

Multipass官网:Multipass orchestrates virtual Ubuntu instanceshttps://multipass.run/VirtualBox官网:Oracle VM VirtualBoxhttps://www.virtualbox.org/

1、下载与安装

  从上面两个官方下载Multipass 和VirtualBox,使用管理员权限进行安装。

 

 

如下安装界面勾选VirtualBox选项

如下界面选择添加到系统环境变量

安装成功后, 打开CMD或Power Shell终端执行以下命令可以查看当前软件版本:

multipass version

 推荐个跨平台支持的终端工具WindTermicon-default.png?t=M4ADhttps://github.com/kingToolbox/WindTerm

 

 

 查看帮助

multipass help

 

使用下面命令查看Ubuntu系统镜像类别

C:\# multipass find
Image                       Aliases           Version          Description
core                        core16            20200818         Ubuntu Core 16
core18                                        20211124         Ubuntu Core 18
18.04                       bionic            20220523         Ubuntu 18.04 LTS
20.04                       focal,lts         20220530         Ubuntu 20.04 LTS
21.10                       impish            20220604         Ubuntu 21.10
22.04                       jammy             20220604         Ubuntu 22.04 LTS
appliance:adguard-home                        20200812         Ubuntu AdGuard Home Appliance
appliance:mosquitto                           20200812         Ubuntu Mosquitto Appliance
appliance:nextcloud                           20200812         Ubuntu Nextcloud Appliance
appliance:openhab                             20200812         Ubuntu openHAB Home Appliance
appliance:plexmediaserver                     20200812         Ubuntu Plex Media Server Appliance
anbox-cloud-appliance                         latest           Anbox Cloud Appliance
charm-dev                                     latest           A development and testing environment for charmers
docker                                        latest           A Docker environment with Portainer and related tools
minikube                                      latest           minikube is local Kubernetes

2、配置与使用

2.1 设置虚拟化提供方式

 由于Multipass 默认使用 Hyper-V 作为它的虚拟化提供程序。

C:\# multipass get local.driver
virtualbox

前面在安装的时候如果不是选择的VirtualBox,则需管理员身份启动命令窗口或者PowerShell,然后输入以下命令进行切换

C:\# multipass set local.driver=virtualbox

C:\# 

2.2 网络设备查看

通过以下命令查看当前电脑的网络设置,复制如下所示的Name值备用

C:\# multipass networks
Name  Type  Description
WLAN  wifi  Intel(R) Wi-Fi 6 AX201 160MHz

2.3 创建虚拟机

通过下面命令,可以查看创建虚拟机的相关参数,Image通过multipass find查看-

C:\# multipass help launch
Usage: multipass launch [options] [[<remote:>]<image> | <url>]
Create and start a new instance.

Options:
  -?, -h, --help       Displays help on commandline options.
  --help-all           Displays help including Qt specific options.
  -v, --verbose        Increase logging verbosity. Repeat the 'v' in the short
                       option for more detail. Maximum verbosity is obtained
                       with 4 (or more) v's, i.e. -vvvv.
  -c, --cpus <cpus>    Number of CPUs to allocate.
                       Minimum: 1, default: 1.
  -d, --disk <disk>    Disk space to allocate. Positive integers, in bytes, or
                       with K, M, G suffix.
                       Minimum: 512M, default: 5G.
  -m, --mem <mem>      Amount of memory to allocate. Positive integers, in
                       bytes, or with K, M, G suffix.
                       Minimum: 128M, default: 1G.
  -n, --name <name>    Name for the instance. If it is 'primary' (the
                       configured primary instance name), the user's home
                       directory is mounted inside the newly launched instance,
                       in 'Home'.
  --cloud-init <file>  Path to a user-data cloud-init configuration, or '-' for
                       stdin
  --network <spec>     Add a network interface to the instance, where <spec> is
                       in the "key=value,key=value" format, with the following
                       keys available:
                        name: the network to connect to (required), use the
                       networks command for a list of possible values, or use
                       'bridged' to use the interface configured via `multipass
                       set local.bridged-network`.
                        mode: auto|manual (default: auto)
                        mac: hardware address (default: random).
                       You can also use a shortcut of "<name>" to mean
                       "name=<name>".
  --bridged            Adds one `--network bridged` network.
  --timeout <timeout>  Maximum time, in seconds, to wait for the command to
                       complete. Note that some background operations may
                       continue beyond that. By default, instance startup and
                       initialization is limited to 5 minutes each.

Arguments:
  image                Optional image to launch. If omitted, then the default
                       Ubuntu LTS will be used.
                       <remote> can be either ‘release’ or ‘daily‘. If <remote>
                       is omitted, ‘release’ will be used.
                       <image> can be a partial image hash or an Ubuntu release
                       version, codename or alias.
                       <url> is a custom image URL that is in http://, https://,
                       or file:// format.

执行以下命令,创建一个20.04LTS版本的虚拟机名称为demo1的,接入的网络设置为WLAN,

C:\# multipass launch 20.04 -n demo1 --network WLAN
Launched: demo1

若想创建一个docker的,则把20.04改成docker即可。

待安装成功后用下面命令查看刚创建的虚拟机信息,如果不使用--network参数,则IP地址为空,这样就无法访问该虚拟机里的服务

C:\# multipass info demo1
Name:           demo1
State:          Running
IPv4:           192.168.1.105
Release:        Ubuntu 20.04.4 LTS
Image hash:     103ae8982d79 (Ubuntu 20.04 LTS)
Load:           0.26 0.09 0.03
Disk usage:     1.4G out of 4.7G
Memory usage:   138.7M out of 976.9M
Mounts:         --

C:\# 

进入虚拟机

C:\# multipass shell demo1
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-113-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Jun  9 01:05:08 CST 2022

  System load:  0.0               Processes:               102
  Usage of /:   28.9% of 4.67GB   Users logged in:         0
  Memory usage: 19%               IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%                IPv4 address for enp0s8: 192.168.1.105


1 update can be applied immediately.
To see these additional updates run: apt list --upgradable


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@demo1:~$ 

2.4 虚拟机设置

进入虚拟机后,调整ssh配置,以便允许通过ssh客户端访问

ubuntu@demo1:~$ sudo vi /etc/ssh/sshd_config
将
#PermitRootLogin prohibit-password
修改为
PermitRootLogin yes


将
PasswordAuthentication no
修改为
PasswordAuthentication yes

重启SSH服务

ubuntu@demo1:~$ sudo systemctl restart ssh

设置ubuntu账号登陆密码

ubuntu@demo1:~$ sudo passwd ubuntu
New password: 
Retype new password: 
passwd: password updated successfully
ubuntu@demo1:~$ 

在WindTerm下新建ssh连接,输入主机IP,点击连接后输入登录账号和密码,进入虚拟机内

 2.5 虚拟机启动与停止

C:\# multipass list
Name                    State             IPv4             Image
demo1                   Running           192.168.1.105    Ubuntu 20.04 LTS

C:\# multipass stop demo1

C:\# multipass list
Name                    State             IPv4             Image
demo1                   Stopped           --               Ubuntu 20.04 LTS

C:\# multipass start demo1

C:\# multipass list
Name                    State             IPv4             Image
demo1                   Running           192.168.1.105    Ubuntu 20.04 LTS

总结

Multipass 使用起来很方便,几分钟的时间就可以快速创建个虚拟机,比用VMWare、VirtualBox创建虚拟机要快捷的多。

注意:Multipass 是由 Ubuntu 背后的 Canonical 公司开发的,因此 Multipass 所使用的镜像也都是 Ubuntu 镜像。

 

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值