Windows-multipass

Windows

alias 创建别名
aliases 列出可用的别名
authenticate 认证客户端
delete 删除实例
exec 在实例上运行命令
find 显示可用于创建实例的图像
get 获取配置设置
help 显示关于命令的帮助
info 显示有关实例的信息
launch 创建并启动一个Ubuntu实例
list 列出所有可用的实例
mount 在实例中挂载本地目录
networks 网络列出可用的网络接口
purge 永久清除所有已删除的实例
recover 恢复删除的实例
restart 重启实例
set 设置配置设置

multipass set local.polaris02.disk=20g
multipass set local.polaris02.memory=8g
multipass set local.polaris02.cpus=4
multipass set local.driver=virtualbox
multipass set client.primary-name=<instance name>

shell 打开正在运行的实例上的shell
start 启动实例
stop 停止运行实例
suspend 挂起正在运行的实例
transfer 在主机和实例之间传输文件
umount 从实例中解除挂载目录
unalias 删除别名
version 显示版本详细信息

Multipass是一个灵活、强大的工具,可用于多种用途。最简单的形式是,它可以用来在任何主机上快速创建和销毁Ubuntu虚拟机(实例)。更全面地说,Multipass是笔记本电脑上的本地迷你云,允许测试和开发多实例或基于容器的云应用程序。

本教程将教你如何使用Multipass创建、定制和管理实例。您还将学习如何在两个常见的用例中应用Multipass。

Multipass默认使用Hyper-V作为其虚拟化提供者。如果您想使用VirtualBox,请启动命令提示符cmd.exe)或者PowerShell 如同Administrator`并运行:

C:\WINDOWS\system32> multipass set local.driver=virtualbox

如何创建实例

这个文档演示了用Multipass创建一个实例的各种方法。虽然每个方法都是包含命令的一行程序launch,每一个都展示了一个不同的选项,您可以使用它来获得您想要的实例。

内容:

创建实例

要创建具有Multipass的实例,请执行:

$ multipass launch
…
Launched: keen-yak

这已经启动了一个新的实例,它被随机命名为keen-yak。特别是,当我们运行multipass info时,我们发现这是一个Ubuntu LTS版本,即18.04,1GB RAM,1个CPU,5GB磁盘:

$ multipass info keen-yak
Name:           keen-yak
State:          RUNNING
IPv4:           10.140.94.253
Release:        Ubuntu 18.04.1 LTS
Image hash:     d53116c67a41 (Ubuntu 18.04 LTS)
Load:           0.00 0.12 0.18
Disk usage:     1.1G out of 4.7G
Memory usage:   71.6M out of 985.4M

创建具有特定环境的实例

要找出哪些图像可用,请运行:

$ multipass find
snapcraft:core18            18.04             20201111         Snapcraft builder for Core 18
snapcraft:core20            20.04             20210921         Snapcraft builder for Core 20
snapcraft:core22            22.04             20220426         Snapcraft builder for Core 22
snapcraft:devel                               20220525         Snapcraft builder for the devel series
core                        core16            20200818         Ubuntu Core 16
core18                                        20211124         Ubuntu Core 18
18.04                       bionic            20220523         Ubuntu 18.04 LTS
20.04                       focal,lts         20220505         Ubuntu 20.04 LTS
21.10                       impish            20220309         Ubuntu 21.10
22.04                       jammy             20220506         Ubuntu 22.04 LTS
daily:22.10                 devel,kinetic     20220522         Ubuntu 22.10
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

要启动具有特定映像的实例,请将映像名称或别名传递给multipass launch:

$ multipass launch kinetic
Launched: tenacious-mink

multipass info确认我们已经启动了所选图像的实例。

$ multipass info tenacious-mink
Name:           tenacious-mink
State:          Running
IPv4:           10.49.93.29
Release:        Ubuntu Kinetic Kudu (development branch)
Image hash:     5cb61a7d834d (Ubuntu 22.10)
Load:           0.10 0.06 0.02
Disk usage:     1.4G out of 4.7G
Memory usage:   161.8M out of 971.2M

使用自定义名称创建实例

要启动具有特定名称的实例,请在命令行中添加- name选项:

multipass launch kinetic --name helpful-duck
Launched: helpful-duck

使用自定义CPU号、磁盘和RAM创建一个实例

使用以下参数指定自定义数量的CPU、磁盘和RAM大小:

$ multipass launch --cpus 4 --disk 20G --mem 8G
Launched: giving-catfish

创建具有主要状态的实例

如果实例的名称是主要的,则该实例可以在创建时获得primary状态:

$ multipass launch kinetic --name primary
Launched: primary

创建具有多个网络接口的实例

Multipass可以通过- network选项启动带有附加网络接口的实例。该功能由networks命令补充,用于查找可桥接的主机网络。

只有对版本2网络配置具有cloud-init支持的映像才支持这一点,这反过来要求安装netplan。所以,从17.10和core 16以后,除了snapcraft:core16。然后只有在以下情况下:

​ 在Linux上,用LXD

​ 在Windows上,使用Hyper-V和VirtualBox

​ 在macOS上,使用VirtualBox驱动程序

可以多次给定- network选项,每次都请求一个额外的网络接口(除了默认的接口,该接口始终存在)。每次使用都需要一个参数来指定所需接口的属性:

  • name — 唯一必需的值,它标识实例设备要连接到的主机网络(有关可能的值,请参见网络)
  • mode —自动(默认)或手动;使用auto,实例将尝试自动网络配置
  • mac —用于设备的自定MAC地址

这些属性可以以< key>=,…的格式指定。但是只有< name >的一个更简单的表单可用于最常见的用例。这里有一个例子:

$ multipass launch --network en0 --network name=bridge0,mode=manual
Launched: upbeat-whipsnake

$ multipass exec upbeat-whipsnake -- ip -br address show scope global
enp0s3           UP             10.0.2.15/24
enp0s8           UP             192.168.1.146/24
enp0s9           DOWN

$ ping -c1 192.168.1.146  # elsewhere in the same network
PING 192.168.1.146 (192.168.1.146): 56 data bytes
64 bytes from 192.168.1.146: icmp_seq=0 ttl=64 time=0.378 ms
[...]

在上面的示例中,我们在实例中获得了以下接口:

  • enp0s3 —默认接口,实例可以使用该接口与外界联系,Multipass使用该接口与实例通信;
  • enp0s8 —连接到主机上的en0并自动配置的接口;
  • enp0s9 — 连接到主机上bridge0的接口,准备进行手动配置。

选择途径

额外接口配置有比默认度量(100)更高的度量(200)。因此,默认情况下,只有当它们是更好的匹配对于目标IP:

$ multipass exec upbeat-whipsnake -- ip route
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 100
default via 192.168.1.1 dev enp0s8 proto dhcp src 192.168.1.146 metric 200
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.0.2.2 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100
192.168.1.0/24 dev enp0s8 proto kernel scope link src 192.168.1.146
192.168.1.1 dev enp0s8 proto dhcp scope link src 192.168.1.146 metric 200

$ multipass exec upbeat-whipsnake -- ip route get 91.189.88.181
91.189.88.181 via 10.0.2.2 dev enp0s3 src 10.0.2.15 uid 1000
    cache

$ multipass exec upbeat-whipsnake -- ip route get 192.168.1.13
192.168.1.13 dev enp0s8 src 192.168.1.146 uid 1000
    cache

桥接

在Linux上,当尝试将实例网络连接到主机上的以太网设备时,Multipass将提供创建所需的桥:

$ multipass networks
Name             Type      Description
eth0             ethernet  Ethernet device
lxdbr0           bridge    Network bridge
mpbr0            bridge    Network bridge for Multipass
virbr0           bridge    Network bridge

$ multipass launch --network eth0
Multipass needs to create a bridge to connect to eth0.
This will temporarily disrupt connectivity on that interface.

Do you want to continue (yes/no)?

但是,Multipass需要NetworkManager来实现这一点。在没有安装NetworkManager的安装上(例如Ubuntu Server),用户仍然可以通过其他方式创建一个桥,并将其传递给Multipass。例如,这个配置片段通过网络计划实现了这一点:

network:
  bridges:
    mybridge:
      dhcp4: true
      interfaces:
        - eth0

它位于/etc/netplan/(例如/etc/netplan/50-custom.yaml)中的某个位置。成功尝试网络计划或应用网络计划后,Multipass将使用networks命令显示新桥,实例可以连接到该桥:

multipass launch --network mybridge

另一种选择是安装NetworkManager,但是需要停用其他网络处理程序,以避免冲突并使新的网桥永久存在

使用自定义DNS创建实例

在某些情况下,默认使用系统提供的DNS是不够的。在这种情况下,您可以在启动命令中使用- cloud-init选项,或者在实例启动后修改网络配置

-cloud-init方法

要在实例中使用自定义DNS,您可以使用以下cloud-init代码片段:

#cloud-config
bootcmd:
- printf "[Resolve]\nDNS=8.8.8.8" > /etc/systemd/resolved.conf
- [systemctl, restart, systemd-resolved]

用你喜欢的DNS服务器替换8.8.8.8。然后,您可以使用以下命令启动该实例:

$ multipass launch --cloud-init systemd-resolved.yaml

netplan.io方法

实例启动后,您可以修改/etc/net plan/50-cloud-init . YAML文件,添加nameservers条目:

network:
  ethernets:
    ens3:
      dhcp4: true
      match:
        macaddress: 52:54:00:fe:52:ee
     set-name: ens3
     nameservers:
       search: [mydomain]
       addresses: [8.8.8.8]

然后,您可以测试它:

$ sudo netplan try
Do you want to keep these settings?


Press ENTER before the timeout to accept the new configuration


Changes will revert in 120 seconds
...

如何修改实例

本文档进一步展示了在之外自定义实例的方法set命令,通过设置。

将实例的状态设置为primary

本节演示如何将实例的状态设置为主要。这很方便,因为它使这个实例成为几个命令的默认参数,比如shell、start、stop、restart和suspend,并且还自动在实例中挂载我们的$HOME目录。

要授予常规实例主要状态,请将其名称分配给客户机。primary-name:

$ multipass set client.primary-name=<instance name>

该设置允许在实例之间转移主要状态。主名称的配置可以独立于具有新旧名称的实例是否存在。如果他们这样做,他们失去并获得相应的主要地位。

这提供了一种选择(取消选择)现有实例作为主实例的方法。下面显示了一个示例:

# Assign the primary status to an instance called 'first':
$ multipass set client.primary-name=first
# Now this instance is picked up automatically by 'multipass start'
# The primary instance also automatically mounts the user's home directory into a directory called 'Home'
$ multipass start
Launched: first
Mounted '/home/ubuntu' into 'first:Home'
# Stop the primary instance
$ multipass stop
$ multipass launch --name second
Launched: second
# Change the primary instance to an existing instance
$ multipass set client.primary-name=second
# Now this instance is used by default by the commands
$ multipass suspend
# When listing all instances, the primary one is displayed first
$ multipass list
Name                    State             IPv4             Image
second                  Suspended         --               Ubuntu 18.04 LTS
first                   Stopped           --               Ubuntu 18.04 LTS

设置实例的CPU、RAM或磁盘(预览)

虽然实例属性可以在启动时确定,但有些属性可以在实例创建后更新。具体来说,实例的内存、磁盘空间和CPU数量是通过守护进程设置:local公开的。local.<instance-name>.(cpus|disk|memory).

只能更新已停止且未删除的实例的属性,但所有实例都可以提取其属性。因此,此时所有multipass管理的实例都可以使用设置键。然而,尝试更新正在运行、挂起或删除的实例会导致错误。

我们希望允许修改正在运行的实例,并在下次重启时应用更改,但这只能在以后实现。实时/热修改——在不重启的情况下更改正在运行的实例的属性——不在我们的计划之内(至少对于当前的属性来说是这样)。虚拟机管理程序的multipass支持很少支持它,并且增加的收益很少。

此外,使用时不支持修改实例设置超级工具包英特尔macOS上的驱动程序。这超级工具包驱动程序将很快被弃用,取而代之的是虚拟机。这虚拟机虚拟机英特尔macOS上的驱动程序支持实例修改。

如何使用实例

在实例中打开shell提示符

要在现有的loving-duck实例上打开shell提示符,请执行以下命令:

$ multipass shell loving-duck
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-109-generic x86_64)

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

  System information as of Tue May 31 14:26:40 -03 2022

  System load:  0.0               Processes:             113
  Usage of /:   28.8% of 4.67GB   Users logged in:       0
  Memory usage: 21%               IPv4 address for ens3: 10.49.93.241
  Swap usage:   0%


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@loving-duck:~$ 

如果loving-duck实例停止或暂停,它将自动启动。如果shell命令没有参数,将会打开主实例上的shell提示符(如果主实例不存在,则创建主实例)。

如上例所示,shell命令会显示一个Ubuntu提示符。可以在此外壳上执行命令。之后,可以通过logout exit或按Ctrl-D键来关闭会话。

在实例中执行命令

要在实例中执行单个命令,不需要打开shell。可以从主机直接调用该命令,调用

$ multipass exec loving-duck -- pwd
/home/ubuntu

在示例中,/home/ubuntu是在loving-duck实例上调用pwd命令的输出。

启动一个实例

已经创建并显示为停止或挂起的实例可以用

$ multipass start loving-duck

可以同时启动多个实例,在命令行中指定所有实例的名称

$ multipass start loving-duck devoted-lionfish sensible-shark

此外,可以使用- all参数同时启动所有现有实例:

$ multipass start --all

如果省略实例名称或- all参数,将启动主实例,并在需要时创建它。

停止实例

使用以下命令停止正在运行的、未挂起的实例:

$ multipass suspend loving-duck

可以一次暂停多个正在运行的实例,在命令行中指定它们的所有名称

$ multipass suspend loving-duck devoted-lionfish sensible-shark

所有正在运行的实例都会立即停止-所有参数:

$ multipass suspend --all

如果省略实例名称和- all参数,主实例将被停止(如果它存在并且正在运行而没有挂起)。

如何使用实例命令别名

本文档演示了如何创建、列出、执行和删除实例中运行的命令的别名。

创建别名

若要创建在给定实例上运行命令的别名,请使用命令别名。下面的代码使用这个命令创建一个别名lscc,它将在一个实例crazy-cat中运行命令ls:

$ multipass alias crazy-cat:ls lscc

运行这个命令后,别名lscc被定义为在实例crazy-cat上运行命令ls。如果省略别名lscc,别名默认为要运行的命令的名称(在本例中为ls)。

工作目录映射

默认情况下,从版本1.10.0开始,如果在实例上装载了执行别名的主机文件夹,实例上的工作目录将更改为装载的目录。当使用参数- no-map-working-directory定义别名时,可以避免这种行为。例如:

$ multipass alias crazy-cat:pwd pwdcc --no-map-working-directory

列出定义的别名

要查看到目前为止定义的别名列表,请使用aliases命令:

$ multipass aliases
Alias  Instance   Command  Working directory
lscc   crazy-cat  ls       map
pwdcc  crazy-cat  pwd      default

从Multipass 1.10.0开始出现的工作目录列告诉我们别名将在主机的哪个目录上执行。值default意味着别名将在实例默认工作目录中执行(通常是/home/ubuntu)。值映射意味着,如果用户调用别名的主机目录装载在实例上,别名将在实例上装载的目录上执行。在1.10.0之前的版本中,执行目录将始终是默认的;从Multipass 1.10.0开始,只有在创建别名时出现- no-map-working-directory参数,该值才是默认值。

执行别名

有两种方法可以执行别名。

multipass <alias>

$ multipass lscc

这将shells化为实例crazy-cat,执行ls并返回到主机命令行,就像它是一个exec命令一样。

也支持参数,前提是用下列字符分隔选项:

$ multipass lscc -- -l

<alias>

运行别名的第二种方式是一个两步过程:

将多遍别名脚本文件夹添加到系统路径

首先,Multipass别名脚本文件夹到系统路径。第一次创建别名时会显示这样做的说明,并且每个平台会有所不同。举个例子,

$ multipass alias crazy-cat:ls lscc
You'll need to add this to your shell configuration (.bashrc, .zshrc or so) for
aliases to work without prefixing with `multipass`:

PATH="$PATH:/home/user/snap/multipass/common/bin"
Linux

Expand to see the instructions for Linux

Windows

然而,对于Windows来说,这就有点复杂了。要使更改永久生效,请使用PowerShell存储旧的系统路径,向其中添加alias文件夹,然后存储新的路径。

$old_path = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$new_path = “$old_path;C:\Users\<user>\AppData\Local\Multipass\bin”
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $new_path

不要忘记重启你的终端。该文件夹现在被永久添加到您的路径中,Multipass现在可以执行别名,只需调用它们的名称。

执行别名

一旦您将alias文件夹添加到系统路径中,您就可以直接执行它(无需提及multipass ),如下所示:

$ lscc

此命令(假定路径已经添加到系统路径中)相当于多遍lscc。也支持参数,不需要–:

$ lscc -l

移除别名

最后,要删除别名lscc,发出:

$ multipass unalias lscc pwdcc

Multipass 1.10.0还引入了- all参数,旨在一次性删除所有已定义的别名。它的用法是:

$ multipass unalias --all

清除为其定义别名的实例时,别名也会被删除。这意味着multipass delete crazy-cat - purge也将删除别名lscc和pwdcc。

如何与实例共享数据

本文档演示了如何在您的主机和实例之间共享数据。有两种方法可以实现这一点,通过mount命令或通过transfer命令。

使用 mount

使用Multipass在主机和实例之间共享数据的推荐方法是mount命令:

$ multipass mount $HOME keen-yak
$ multipass info keen-yak
…
Mounts:         /home/michal => /home/michal

从这一点开始,/home/michal将在实例中可用。

您还可以指定实例内部的路径,以便在其中装载本地路径:

$ multipass mount $HOME keen-yak:/some/path

mount也可以指定为启动命令的一个选项:

multipass launch --mount /some/local/path:/some/instance/path

要卸载已装载的路径,请使用umount命令。您可以指定要卸载的路径,也可以不指定任何路径而卸载所有路径:

$ multipass umount keen-yak
$ multipass info keen-yak                
…
Mounts:         --

使用 transfer

您也可以使用transfer来复制文件。如果文件在实例中,请在其路径前加上<实例名>:。

$ multipass transfer keen-yak:/etc/crontab keen-yak:/etc/fstab /home/michal
$ ls -l /home/michal/crontab /home/michal/fstab
-rw-r--r-- 1 michal michal 722 Oct 18 12:13 /home/michal/crontab
-rw-r--r-- 1 michal michal  82 Oct 18 12:13 /home/michal/fstab
$ multipass transfer /home/michal/crontab /home/michal/fstab keen-yak:
$ multipass exec keen-yak -- ls -l crontab fstab
-rw-rw-r-- 1 ubuntu ubuntu 722 Oct 18 12:14 crontab
-rw-rw-r-- 1 ubuntu ubuntu  82 Oct 18 12:14 fstab

如何删除实例

本文档演示了如何临时或永久删除实例。

将实例移动到“回收站”

要将实例标记为已删除,请运行:

$ multipass delete keen-yak

现在,如果您列出实例,您会看到它实际上只是被标记为删除(或者换句话说,被移动到回收站):

$ multipass list
Name                    State             IPv4             Release
keen-yak                DELETED           --               Not Available

您可以使用- all选项将所有实例一次移动到回收站:

$ multipass delete --all

标记为已删除的实例稍后可以恢复:

$ multipass recover keen-yak
$ multipass list
Name                    State             IPv4             Release
keen-yak                STOPPED           --               Ubuntu 18.04 LTS

永久删除实例

如果您想永久删除“回收站”中的所有实例,您必须清除它们

$ multipass delete keen-yak
$ multipass purge
$ multipass list
No instances found.

purge命令不带参数。它将永久删除所有标记为已删除的实例。

为了在一个命令中只永久删除一个实例,可以使用:

$ multipass delete --purge keen-yak

在Multipass中使用Docker工作流运行容器

概观

多通团队最近宣布了Docker的新工作流程这使得它的用户可以在任何平台上使用现成的Docker。这个新的工作流程使得在macOS、Windows或Linux上本地开发和测试Docker容器变得更加容易。

在本教程中,我们将看到如何通过在Multipass的Docker容器中创建博客来开始Docker工作流。

我们会学到什么

  • 如何通过Multipass在macOS或Windows上使用Docker
  • 如何为docker命令到我们的主机命令行
  • 如何使用Portainer在multipass中启动Docker容器

我们需要什么

  • 任何有互联网连接的计算机

安装Multipass

时长:3分钟

我们将从在我们的机器上安装Multipass开始,如图所示这里。只需点击操作系统,并按照指示。

启动Docker虚拟机

时长:1分钟

现在已经安装了Multipass,我们可以非常简单地创建一个运行Docker的VM。打开终端,输入

multipass exec docker docker

为Docker命令设置别名

时长:1分钟

现在别名为码头工人命令到我们的主机命令行。这将让我们使用docker命令,就像Docker直接在我们的主机上运行一样。要为命令设置别名,请运行

multipass alias docker:docker

该命令将返回说明,显示如何将新别名添加到我们的路径中。只需复制并粘贴所示命令。它很可能是这样的形式:

PATH=“$PATH:/home//snap/multipass/common/bin”

们现在可以直接从命令行使用docker。要尝试一下,请运行

docker run hello-world

使用Portainer

时长:5分钟

我们现在将更进一步,使用Portainer。Docker工作流安装了Portainer,它提供了一个易于使用的图形界面来管理我们的Docker容器。要访问Portainer,我们首先需要它的IP地址。以下命令将显示与我们在前面的步骤中创建的Ddocker虚拟机关联的IP地址:

multipass list

应该列出两个IP地址,一个用于Docker实例,另一个用于Portainer。Portainer IP应该以10开头。

在web浏览器中,输入上一步中的Portainer IP地址,后跟Portainer端口9000,如下所示:":9000 "。在提示符下设置用户名和密码,然后选择用于管理的选项当地的Docker环境并单击连接

单击新创建的“本地”环境来管理本地虚拟机上的Docker实例。

启动容器

在本教程中,我们将使用Portainer中的Ghost模板创建一个博客。如果你正在寻找更多的想法,Portainer有许多其他的应用程序模板。如果需要更多选择,可以从Portainer的Docker hub或命令行启动容器。

在Portainer中,点击左侧工具栏中的应用模板,向下滚动到Ghost模板。

现在,我们可以配置和部署模板了。输入名称,然后单击部署。桥接网络是默认的正确选项。

在容器页面上,我们现在应该看到两个容器正在运行。一个包含Ghost,另一个包含Portainer本身。

我们现在可以访问我们的Ghost博客,方法是转到容器页面中显示的已发布端口,即<虚拟机IP地址>:< Ghost端口>

这就是了,我们的博客运行在Multipass中的Docker容器中!

接下来,尝试Portainer的其他应用程序模板(步骤5),或查看Docker Hub以获得更多容器。如果您想尝试容器编排,Microk8s或Multipass的Minikube工作流是很好的起点。

如何设置驱动程序

本文档演示了如何选择、设置和管理多通道背后的驱动程序。Multipass已经有了合理的默认值,所以这是一个可选步骤。

内容:

Windows:使用VirtualBox

将多通道驱动程序切换到VirtualBox

然后,您可以告诉Multipass使用它(也具有管理员权限):

multipass set local.driver=virtualbox

从那时起,所有使用multipass launch启动的实例都将在后台使用VirtualBox。

使用VirtualBox查看Multipass实例

Multipass作为系统帐户运行,因此要在VirtualBox中或通过VBoxManage命令查看实例,您必须通过PsExec -s以该用户身份运行这些实例。下载并解压缩Downloads文件夹中的

& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s -i $env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe

要在命令行中列出实例,请执行以下操作:

& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe list vms
"primary" {05a04fa0-8caf-4c35-9d21-ceddfe031e6f}

您仍然可以使用multipass客户端和系统菜单图标,并且您在VirtualBox中对实例配置所做的任何更改都将是持久的。但是,它们可能不会在multipass info之类的Multipass命令中表示。

使用VirtualBox为多通道实例设置端口转发

要在您的主机上公开实例内部运行的服务,您可以使用VirtualBox的端口转发功能,例如:PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe controlvm "primary" natpf1 "myservice,tcp,,8080,,8081"

如何设置驱动程序

本文档演示了如何选择、设置和管理多通道背后的驱动程序。Multipass已经有了合理的默认值,所以这是一个可选步骤。

Windows:使用VirtualBox

默认情况下,Windows上的Multipass使用hyperv驱动程序。但是,如果您愿意(或者必须),您可以将Multipass使用的hypervisor更改为VirtualBox。

安装VirtualBox

为此,安装VirtualBox,如果你还没有。你可能会发现你需要以管理员身份运行VirtualBox安装程序

将multipass驱动程序切换到VirtualBox

然后,您可以告诉Multipass使用它(也具有管理员权限):

multipass set local.driver=virtualbox

从这时时起,所有使用multipass launch启动的实例都将在后台使用VirtualBox。

使用VirtualBox查看multipass实例

Multipass作为系统帐户运行,因此要在VirtualBox中或通过VBoxManage命令查看实例,您必须通过PsExec -s以该用户身份运行这些实例。下载并解压缩Downloads文件夹中的PSTools.zip,并在管理PowerShell中运行:

 & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s -i $env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe

要在命令行中列出实例,请执行以下操作:

& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe list vms
"primary" {05a04fa0-8caf-4c35-9d21-ceddfe031e6f}

您仍然可以使用multipass客户端和系统菜单图标,并且您在VirtualBox中对实例配置所做的任何更改都将是持久的。但是,它们可能不会在multipass info之类的Multipass命令中表示。

使用VirtualBox为多通道实例设置端口转发

要在您的主机上公开实例内部运行的服务,您可以使用VirtualBox的端口转发功能,例如:

& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe controlvm "primary" natpf1 "myservice,tcp,,8080,,8081"

然后,您可以打开http://localhost:8081/,在端口8080上的实例内部运行的服务将被公开。

切换回默认驱动程序

如果您想切换回默认驱动程序:

multipass set local.driver=hyperv

使用VirtualBox创建的实例不会被转移,但是您可以随时返回它们。

如何使用Multipass服务验证客户端

Multipass要求客户端在允许命令完成之前通过服务的身份验证。

内容:

设置密码短语

管理员需要设置密码,以便客户端通过Multipass服务进行身份验证。设置密码短语的客户端需要已经过身份验证。有两种方法可以设置密码。

要使用无回声交互式条目设置密码,其中键入的密码隐藏在视图之外:

$ multipass set local.passphrase
Please enter passphrase:
Please re-enter passphrase:
$ multipass set local.passphrase=foo

认证客户端

未被授权连接到multipass服务的客户端在运行Multipass命令时将会失败。发生这种情况时,将显示一个错误。例如:

multipass list
list failed: The client is not authenticated with the Multipass service.
Please use 'multipass authenticate' before proceeding.

此时,客户端需要提供之前设置的密码。这可以通过两种方式实现。

要使用无回声交互式条目进行身份验证,其中键入的密码隐藏在视野之外:

multipass authenticate
Please enter passphrase:

要在密码可见的单一命令中进行身份验证,请执行以下操作:

multipass authenticate foo

如果客户端无法授权并且无法设置密码

有可能另一个有特权连接到Multipass套接字的客户机将首先连接,使得似乎不可能设置local.passphrase并授权该客户机使用该服务。人们会看到如下内容:

$ multipass list
list failed: The client is not authenticated with the Multipass service.
Please use 'multipass authenticate' before proceeding.
$ multipass authenticate
Please enter passphrase: 
authenticate failed: Passphrase is not set. Please `multipass set local.passphrase` with a trusted client.
$ multipass set local.passphrase
Please enter passphrase: 
Please re-enter passphrase: 
set failed: The client is not authenticated with the Multipass service.
Please use 'multipass authenticate' before proceeding.

然后似乎不可能授权客户端连接到服务。使用sudo时,这甚至可能不起作用。

以下解决方法应该有助于摆脱这种情况:

$ cat ~/snap/multipass/current/data/multipass-client-certificate/multipass_cert.pem | sudo tee -a /var/snap/multipass/common/data/multipassd/authenticated-certs/multipass_client_certs.pem > /dev/null
$ snap restart multipass

此时,您的客户机应该通过了Multipass服务的身份验证。

如何远程使用multipass

本文档将演示如何远程使用Multipass。例如,如果您想在更强大的机器上运行虚拟机,这可能会很有用。

内容:

向您的网络公开multipass

若要向您的网络公开 Multipass,请传递---address启动守护程序时:

$ multipassd --help
# ...
  --address <server_name:port>                      specifies which address to
                                                    use for the multipassd
                                                    service; a socket can be
                                                    specified using
                                                    unix:<socket_file>

客户端接受覆盖默认值的MULTIPASS_SERVER_ADDRESS环境变量:

https://github.com/canonical/multipass/blob/a1ea65fb63184fc778e277d3c9e2920ef2a9fb3d/src/client/common/client_common.cpp#L171-L173
$ MULTIPASS_SERVER_ADDRESS=<hostname>:51001 multipass find
Image                       Aliases           Version          Description
...
21.10                       impish            20220118         Ubuntu 21.10

更改守护程序设置

Windows操作系统

在Windows上,您需要编辑/重新创建服务定义,这是很重要的(如果您这样做了,记得传递/svc作为multipassd.exe二进制,我们目前使用LocalService帐户)…

作为一次性的事情,您可以使用开始参数中的字段服务停止服务后的面板:

停止服务后,您可以一次性使用服务面板中的启动参数字段:

让我们知道这是如何为您工作的,以及您接下来想看到什么!

如何提高multipass装载性能

默认情况下,Multipass使用SSHFS在实例上装载主机文件夹。虽然它在性能、安全性和功能之间提供了很好的折衷,但也可以使用其他方法来手动完成此任务。

我们对许多挂载方法进行了全面的测试。这里,我们简要地展示了如何在每个系统上创建共享,以及如何使用我们发现的最高效的方法在多通道实例中挂载它们。

内容:

与SMB共享文件夹

在Windows中

首先,为了提高速度,我们可以选择在Windows内置的SMB服务器上启用RDMA。在控制面板中,我们可以找到“打开或关闭Windows功能”图标。在该窗口中,我们需要启用SMB Direct。Windows可能需要重新启动。

然后,为了共享一个文件夹,我们可以使用PowerShell。发出命令

New-SmbShare -Name "share_name" -Path "C:\my_path"

将创建一个名为\\hostname\share_name在主机中。命令新-SmbShare有多个选项来控制访问和加密,但这些不是本文档的主题。

在实例上装载与SMB共享的文件夹

一旦主机操作系统共享了该文件夹,我们需要将它装载到实例上。为此,该包CIFS-工具需要,可以与一起安装

$ sudo apt update && sudo apt install -y cifs-utils

最后,挂载是通过命令行完成的

$ sudo mount -t cifs //hostname/my_path_or_share_name mount_folder/ -o user=my_name,uid=1000

在哪里my_nam用户是否共享主机上的文件夹。终端会询问密码,输入密码后,我们就完成了。

或者,我们可以在/etc/fstab让操作系统在启动时自动挂载文件夹,或者至少不需要指定挂载名称和选项。这一行应该是:

//hostname/my_path_or_share_name mount_folder/ cifs user=my_name,uid=1000 0 0

该文件中的条目用空格或制表符分隔。第一个是共享名或路径,第二个是挂载文件夹的目录,第三个是挂载类型,第四个是以逗号分隔的选项列表(添加noauto以避免在引导时挂载),最后两个选项最好保持为零。

以防noauto选项中指定了,则应该使用

$ sudo mount mount_folder/

虚拟文件系统装载

如果在Linux上使用LXD后端,我们可以从高性能的文件系统装载中获益,代价是不能在实例运行时装载它。使用命令将文件夹装载到实例上

$  lxc --project multipass config device add lxdinstance mount_lxd disk source=/my_path path=//mount_folder

在哪里lxdinstance是实例的名称,mount_lxd是装载的任意设备名称,source指定要共享的路径,并path指定安装源的目录。只需这个命令,LXD就能搞定一切:不需要在实例上运行命令。

virtio-fs也可以在qemu和libvirt后端获得,尽管需要额外的安装费用。

NFS山

Linux和MacOS在系统上提供了NFS服务器。

与NFS共享一个文件夹

在MacOS中

MacOS中包含的NFS服务器由控制nfsd命令和文件/etc/export。我们需要将想要共享的文件夹添加到这个文件中,其中有一行类似于

/my_path -mapall=host_user -network 192.168.0.0 -mask=255.255.0.0

在哪里-network-mask控制可以访问共享的网络。然后,我们用命令启动服务器

$ sudo nfsd start

(或者restart如果服务器已经在运行)。

在Linux中

在Ubuntu(或任何其他基于Debian的发行版)中,包nfs内核服务器包含使用内核中包含的NFS服务器的文件。我们可以用命令安装它

$ sudo apt update && sudo apt install -y nfs-kernel-server

要共享一个文件夹,我们使用以下命令:

$ sudo exportfs *:/my_path

在哪里*表示“导出到任何主机”;我们可以在那里指定主机名或IP地址。

在实例上装载与NFS共享的文件夹

我们首先需要在实例中安装NFS客户端,命令如下

$ sudo apt update && sudo apt install -y nfs-common

然后,我们可以用

$ sudo mount -t nfs HOST_IP:/my_path /mount_folder -o user=host_user,uid=instance_uid,gid=instance_gid

如何用Packer构建多通道图像

Packer是一个实用程序,允许您(重新)构建在各种环境中运行的映像。如果满足一些要求,Multipass也可以运行这些映像(也就是说,映像必须在使用的虚拟机管理程序上引导,并且[cloud-init需要可用)。

内容:

基础知识

最简单的方法是从现有的[ Ubuntu Cloud Image,然后是基础项目设置(您可以单击文件名来查看它们的内容,meta-data故意为空):


├── cloud-data
│   ├── meta-data
│   └── user-data
└── template.json

1 directory, 3 files

您将需要安装QEMU(例如sudo apt install qemu)从那里您可以运行:


$ packer build template.json
$ multipass launch file://$PWD/output-qemu/packer-qemu --disk 5G
…
Launched: tolerant-hammerhead
$ multipass shell tolerant-hammerhead
…
ubuntu@tolerant-hammerhead ~:$ 

自定义图像

现在上面的内容对您起作用了,用multipass delete --purge tolerant-hammerhead并编辑中的以下部分模板. json文件:

        {
            "type": "shell",
            "inline": ["echo Your steps go here."]
        },

您在这里所做的任何事情都会反映在生成的图像中。你可以安装软件包,配置服务,任何你能在运行系统上做的事情。你需要sudo(无密码)对于任何需要管理员权限的情况,或者您可以将它添加到该置备程序中,以便在有权限的情况下运行整个脚本:

     "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'",

为了使映像对其他人有用,您需要“一般化”映像,以便它可以在另一台机器上正常工作,可能是在另一个网络上,甚至是在不同的管理程序下。这就是provisioners列表中没有 template.json

解释流程

简而言之,Packer使用下载的映像启动一个虚拟机,并在正在运行的系统上运行所有置备程序步骤。

云初始化

默认情况下,Ubuntu云映像被设置为只允许通过SSH使用基于密钥的认证进行登录。Packer的qemu builder只支持密码认证,所以我们使用cloud-init为packer用户提供一个简单的密码,只在映像构建过程中使用。这是通过JSON模板中的以下部分实现的:

           "http_directory": "cloud-data",
            "qemuargs": [
                ["-smbios", "type=1,serial=ds=nocloud-net;instance-id=packer;seedfrom=http://{{ .HTTPIP }}:{{ .HTTPPort }}/"]
            ],

这将指导Packer通过HTTP提供云数据目录,并指导cloud-init通过NoCloud数据源使用它。参考cloud-init的文档来理解用户数据条目的含义。

清除

为了让Multipass能够使用这个映像,cloud-init需要执行另一组指令,因此必须重置它。需要删除packer用户,并且需要在映像中恢复一些其他更改(比如SSH密码验证)。这发生在模板的最后一个置备程序中,这应该是不言自明的。

您的更改可能也需要一些清理,您可以挂载qemu映像并使用Meld工具来比较这两棵树,以查看所有的更改是否确实是有意的。

后续步骤

请查阅Packer的文档,了解QEMU构建器、其他供应器及其配置,以及其他可能会派上用场的东西。或者,您可以用其他cloud-init指令扩展用户数据来提供您的映像。

图形桌面可以以多种方式查看。在本文档中,我们描述了两种方式:RDP(远程显示协议)和普通X11转发。其他方法包括VNC和通过X11转发运行Mir shell(如上所述这里).

如何设置图形界面

内容:**

使用RDP

Multipass使用的图像没有安装图形桌面。出于这个原因,必须安装一个桌面环境(我们使用ubuntu-desktop,但是也有很多其他的选项,就像现有的ubuntu版本一样),以及RDP服务器(这里我们将使用xrdp,但是也有其他选项,比如freerdp)。为此,我们必须首先登录到正在运行的Multipass实例:

$ multipass shell headbanging-squid

一旦进入实例,

$ sudo apt update
$ sudo apt install ubuntu-desktop xrdp

然后,我们需要一个有密码的用户来登录。一种可能是将密码设置为默认值ubuntu用户。

$ sudo passwd ubuntu

我们将被要求输入并再次输入密码。我们已经完成了服务器端的工作。

然后,我们用logout命令并在主机中找出要连接的IP地址:

$ multipass list
Name                    State             IPv4             Image
headbanging-squid       Running           10.49.93.209     Ubuntu 22.04 LTS

因此,我们将使用IP地址10.49.93.209连接到实例上的RDP服务器。

如果实例的IP地址没有显示在multipass列表的输出中,可以使用命令ip addr直接从实例中获取。

在Linux上

在Linux上,有诸如Remmina之类的应用程序来可视化桌面(确保包remmina-plugin-rdp与一起安装在您的主机中remmina).

要直接启动客户端,请运行以下命令:

$ remmina -c rdp://10.49.93.209

系统将要求输入用户名(ubuntu)和上面设置的密码,然后就会显示实例上的Ubuntu桌面。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zy20tLle-1662634797760)(https://ubuntucommunity.s3.dualstack.us-east-2.amazonaws.com/optimized/2X/8/83c7e6d7282fe35622df122ea0ed05788f461bcb_2_690x567.png)]

在macOS上

要在MacOS上连接,我们可以使用Mac App Store中的“微软远程桌面”应用程序。

在Windows上

在Windows上,我们可以通过“远程桌面连接”应用程序连接到RDP服务器。在这里,我们输入虚拟机的IP地址,将会话设置为XOrg,并输入我们在前面的步骤中创建的用户名和密码。我们完成了…一个图形化的桌面!

使用X11转发

可能的情况是,我们只希望Multipass启动一个应用程序,并且只看到那个窗口,而不需要整个桌面。事实证明,这种设置比RDP方法简单,因为我们不需要Multipass实例来部署完整的桌面。相反,我们可以使用X11将实例中的应用程序与主机的图形功能连接起来。

在Linux上

默认情况下,Linux和MacOS运行X和实例,因此主机中不需要额外的软件。通过在X转发中使用身份验证,我们有可能比在Windows上更安全一点。然而,我们将通过ssh转发,以避免与扩展验证的东西发生冲突。不幸的是,multipass shell不允许用户向ssh传递额外的参数,所以我们不能通过multipass使用这个shell。我们将允许主机中的用户通过复制文件/中的公钥,通过ssh登录到Multipass实例。ssh/id_rsa.pub添加到文件/中的实例授权密钥列表中。ssh/authorized _ key。我们可以用下面的命令做到这一点(用您的实例名替换示例实例名):

$ multipass exec rocking-squirrel -- bash -c "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/authorized_keys"

如果文件~/。ssh/id_rsa.pub不存在,这意味着必须创建ssh密钥。使用ssh-keygen创建它们并重试复制。然后,使用multipass info rocking-squirrel检查实例的IP地址。最后,我们可以使用X转发登录实例

# replace `xx.xx.xx.xx` with the IP address obtained above
$ ssh -X ubuntu@xx.xx.xx.xx

并测试运行在该实例上的某个程序的设置:

$ sudo apt install x11-apps
$ xlogo &

xlogo on Linux

必须显示一个包含X标志的小窗口。搞定了。

在macOS上

MacOS的程序应该和Linux差不多,但是我手头没有测试它的Mac。欢迎投稿:slight_smile:

在Windows上

Windows对X一无所知,因此我们需要安装一个X服务器。这里我们将使用VcXsrv。其他选择包括Xming(然而,最新版本是付费的,但旧版本仍然可以从他们的SourceForge网站)或在中安装X服务器Cygwin

因此,第一步是安装VcXsrv,并通过新创建的开始菜单项“XLaunch”运行X服务器。将显示一些选项。第一屏要选择“多窗口”,设置显示数量;将它保留在-1是一个安全的选择。“下一步”按钮将我们带到“客户端启动”窗口,在这里我们应该选择“不启动客户端”。“下一步”将向我们显示“额外设置”,在那里我们应该激活选项“禁用访问控制”。按“下一步”会给我们保存设置的选项,最后我们可以启动X服务器。一个图标将出现在dock中:我们已经完成了X服务器。

要配置客户机(即Multipass实例),我们需要主机IP地址,可以使用控制台命令ipconfig获得该地址。然后启动实例,并将DISPLAY环境变量设置为主机IP:

# replace `xx.xx.xx.xx` with the IP address obtained above
$ export DISPLAY=xx.xx.xx.xx:0.0

我们完成了,我们可以使用xlogo就像在窗户区一样。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UxetAEbb-1662634797762)(https://ubuntucommunity.s3.dualstack.us-east-2.amazonaws.com/optimized/2X/8/82019ef0e41c2d9dafeab82e94346cbea89e33ae_2_690x388.jpeg)]

如何使用不同于系统图标的终端

如果需要,您可以更改多通道系统菜单图标所使用的终端应用程序。

目前仅适用于macOS

为此,您需要告诉macOS使用哪个终端来.command文件类型。本文介绍了实现这一目标的两种方法。

内容:

使用duti

duti是一个小助手应用程序,可以修改默认的应用程序首选项。它也可以available from brew.。

使用mdls找出您的首选终端的捆绑标识符:

$ mdls /Applications/iTerm.app/ | grep BundleIdentifier
kMDItemCFBundleIdentifier              = "com.googlecode.iterm2"

并使其成为脚本文件的默认设置duti

$ duti -s com.googlecode.iTerm2 com.apple.terminal.shell-script shell

使用Finder

创建一个扩展名为. command的空文件,并在Finder中找到它。选择文件并按下⌘I.,你会看到一个信息面板,如下所示:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-v5KzbsRZ-1662634797763)(https://ubuntucommunity.s3.dualstack.us-east-2.amazonaws.com/original/2X/1/1ce425a98480deb53e0cc44416df10bbb52150c2.png)]

展开“打开方式:”部分,选择您喜欢的终端应用程序,然后单击“Change All…”。

如何访问日志

当出现问题时,日志是我们的第一选择。Multipass由一个守护进程(服务)以及命令行和GUI客户端组成,每个客户端都报告自己的健康状况。multipass命令接受- verbose选项(简称为-v),该选项可以重复使用,从默认(错误)级别到警告、信息、调试直至跟踪。

我们使用底层平台的日志记录工具来确保您无论身在何处都能获得熟悉的行为。

内容:

Linux操作系统

在Linux上,systemd-journald与现代Linux系统上事实上的标准相集成。

要访问守护程序(及其子进程)日志:

$ journalctl --unit 'snap.multipass*'

macOS

在macOS上,日志文件存储在/Library/Logs/Multipass中,其中multipassd.log包含守护进程消息。您还可以在这里看到实例日志——文件名模式是< instance>-hyperkit.log。

Windows操作系统

在Windows上,使用事件系统,并且事件查看器允许您访问它们。我们的日志目前在“Windows Logs/Application”下,您可以通过“Multipass”事件源进行过滤。然后,您可以将选定的事件导出到文件中。

如何排除网络故障

本文档演示了如何对macOS和Windows上的各种已知多通道网络问题进行故障诊断。

内容:

macOS网络故障排除

体系结构

MacOS上使用的驱动程序(HyperKit和QEMU)采用了macOS的Hypervisor.framework。

在创建实例时,主机上的Hypervisor.framework使用macOS的“互联网共享”机制来

  1. 创建一个虚拟交换机,并将每个实例连接到它(子网192.168.64。*)
  2. 在位于192.168.64.1的交换机上提供DHCP和DNS解析(通过主机上运行的bootpd & mDNSResponder服务);这是由一个自动生成的文件/etc/bootpd.plist配置的——但是编辑它是没有意义的,因为MacOS会根据需要重新生成它。

请注意,根据“System Preferences”->“Sharing”,“Internet Sharing”服务可能会被禁用。这没问题—在后台,它仍将被启用以支持实例。

已知会干扰Multipass的工具

  • VPN软件在管理路由方面可能很激进,可能会通过VPN接口路由192.168.64子网,而不是保持其在本地可用。
    • 可能的元凶:OpenVPN、F5、Dell SonicWall、Cisco AnyConnect、Citrix/Netscaler Gateway、Jupiter Junos Pulse / Pulse Secure
    • Tunnelblick不会引起问题
  • 它绑定到本地主机的Cisco伞式漫游客户端:53与互联网共享冲突,破坏实例的DNS(参考: Umbrella Roaming Client OS X and Internet Sharing)
  • dnscrypt-proxy/dnscrypt-wrapper/cloud flared-proxy
    默认配置绑定到本地主机端口53,与互联网共享冲突。
  • 另一个dnsmasq进程绑定到本地主机端口53
  • 自定义DHCP服务器绑定到端口67?(“sudo lsof -iUDP:67 -n -P” should show launchd & bootpd only)
  • MacOS update可以对防火墙进行更改,并使实例处于未知状态(请参阅 below).

[问题类https://multipass.run/docs/troubleshoot-networking#heading–arp-problems)

一般网络问题
Unable to determine IP address

通常意味着某些网络配置不兼容,或者受到防火墙或VPN的干扰。

故障排除(要扩展的部分)
  1. Firewall

    1. 是否启用了防火墙?
    2. 如果是这样,它不能“阻止所有传入的连接”
      • 阻止所有传入的连接会阻止DHCP服务器在本地运行,从而为实例提供一个IP。
      • 然而,阻止传入的到“multipassd”的连接是可以的。
  2. VPN

  3. 小告密者-默认是好的,它应该允许mDNSResponder和bootpd访问BPF,如果你在下载图像时遇到问题和/或在尝试多通道启动时看到未知错误-vvv,小告密者可能会干扰multipassd的网络访问(参考。#1169)

  4. 互联网共享——通常不会冲突

  5. bootpd DHCP服务器是否处于活动状态?(

    sudo lsof -iUDP:67 -n -P
    

    应该提到

    bootpd
    

    )

    • bootpd DHCP服务器是否处于活动状态?(sudo lsof -iUDP:67 -n -P应该提到bootpd)通过运行sudo launch CTL load-w/System/Library/launch daemons/bootps . plist来启动它
网络路由问题

可以试试

sudo route -nv add -net 192.168.64.0/24 -interface bridge100

如果你得到一个“文件存在”的错误,也许删除并重试?

sudo route -nv delete -net 192.168.64.0/24
sudo route -nv add -net 192.168.64.0/24 -interface bridge100

可能 -static 路线有帮助?

如果使用“Cisco any connect”-尝试使用“open connect”(brew install open connect),因为它对路由的干扰较少(但您公司的系统管理员/政策可能不允许/授权这样做)。

您的VPN软件是否提供了“Split connection”选项——VPN系统管理员可以在其中指定一系列IP地址通过虚拟专用网路由。

  • Cisco does
  • Pulse Secure / Jupiter Junos Pulse do
VPN冲突的潜在解决方法(参考:#495)

在/etc/pf.conf中的nat …行(如果有,否则在末尾)之后,添加这一行:

nat on utun1 from bridge100:network to any -> (utun1)

并用$ sudo pfctl -f /etc/pf.conf重新加载PF。

可能的其他选项-配置Multipass以使用不同的子网?

编辑/Library/Preferences/system configuration/com . apple . vmnet . plist,将“Shared_Net_Address”值更改为192.168.64.1 -以外的值。

  • 如果您编辑plist文件并保持在192.168范围内,则有效,因为这是多通道硬编码的

请注意:
如果您更改子网并启动实例,它将从新子网获得一个IP。但是,如果您尝试将它改回来,该更改将在下一次实例启动时恢复。dhcp服务器似乎读取了/var/db/dhcpd_leases,由此决定子网,并更新Shared_Net_Address以进行匹配。因此,真正恢复此更改的唯一方法是编辑/删除/var/db/dhcpd_leases

DNS问题

你能ping通IP地址吗?

$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
^C
--- 1.1.1.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2030ms

注意macOS的防火墙可以屏蔽ping使用的ICMP数据包,这会干扰这个测试。确保您在“System Preferences”->“Security & Privacy”->“Firewall”中禁用了“Stealth Mode”,这只是为了测试。

Security & Privacy

如果你再试一次:

multipass@x:~$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=53 time=7.02 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=53 time=5.91 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=53 time=5.12 ms
^C
--- 1.1.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2143ms
rtt min/avg/max/mdev = 5.124/6.020/7.022/0.781 m

这意味着实例确实可以连接到internet,但是DNS解析被破坏。现在使用dig工具测试DNS解析可能会显示它已损坏:

multipass@x:~$ dig google.ie
; <<>> DiG 9.10.3-P4-Ubuntu <<>> google.ie
;; global options: +cmd
;; connection timed out; no servers could be reache

但是如果它显示了这个,它就都工作了:

multipass@x:~$ dig google.ie
; <<>> DiG 9.10.3-P4-Ubuntu <<>> google.ie
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48163
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.ie.   		 IN    A

;; ANSWER SECTION:
google.ie.   	 15    IN    A    74.125.193.94

;; Query time: 0 msec
;; SERVER: 192.168.64.1#53(192.168.64.1)
;; WHEN: Thu Aug 01 15:17:04 IST 2019
;; MSG SIZE  rcvd: 54

要进一步测试,请尝试提供一个显式DNS服务器

multipass@x:~$ dig @1.1.1.1 google.ie
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @1.1.1.1 google.ie
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11472
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1452
;; QUESTION SECTION:
;google.ie.   		 IN    A

;; ANSWER SECTION:
google.ie.   	 39    IN    A    74.125.193.94

;; Query time: 6 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Thu Aug 01 15:16:27 IST 2019
;; MSG SIZE  rcvd: 54

这意味着问题出在macOS的“互联网共享”功能上——由于某种原因,它的内置DNS服务器坏了。

内置的DNS服务器应该是“mDNSResponder ”,它在端口53上绑定到本地主机。

如果使用Little Snitch或另一个基于进程的防火墙,请确保mDNSResponder可以建立传出连接。MacOS的内置防火墙应该不会干扰它。

使用以下命令检查绑定到主机端口的内容

$ sudo lsof -iTCP:53 -iUDP:53 -n -P
COMMAND   PID       	USER   FD   TYPE         	DEVICE SIZE/OFF NODE NAME
mDNSRespo 191 _mdnsresponder   17u  IPv4 0xa89d451b9ea11d87  	0t0  UDP *:53
mDNSRespo 191 _mdnsresponder   25u  IPv6 0xa89d451b9ea1203f  	0t0  UDP *:53
mDNSRespo 191 _mdnsresponder   50u  IPv4 0xa89d451b9ea8b8cf  	0t0  TCP *:53 (LISTEN)
mDNSRespo 191 _mdnsresponder   55u  IPv6 0xa89d451b9e2e200f  	0t0  TCP *:53 (LISTEN)

上面的输出显示了实例运行时的正确状态。如果没有实例正在运行(并且在“System Preferences”中禁用了Internet Sharin),该命令应该不会返回任何内容。

该输出中出现的任何其他命令都意味着某个进程与Internet共享冲突,因此会破坏实例中的DNS。

可能的变通办法
  1. 将实例内部的DNS配置为使用外部工作的DNS服务器。可以通过手动将这一行附加到/etc/resolv.conf来实现:

    nameserver 1.1.1.1
    

    “1.1.1.1”是CloudFlare提供的免费DNS服务,不过你也可以使用自己的。

  2. 使用自定义cloud-init以设置/etc/resolv.conf给你第一次开机。

ARP问题

macOS bridge by Multipass过滤数据包,以便只允许最初分配给虚拟机的IP地址通过。如果您向虚拟机添加一个额外的地址(例如IP别名),ARP广播将通过,但ARP响应将被过滤掉。

这意味着依赖额外IP地址的应用程序,如金属lb下面的microk8s,不会起作用。

MacOS更新导致的问题

将MacOS升级到12.4时(升级到其他版本时也可能发生这种情况),MacOS会对防火墙进行更改。如果实例在更新前没有停止,那么与实例的连接可能会被MacOS防火墙阻止。我们不知道防火墙到底有什么变化,看起来是苹果的bootpd停止回复DHCP请求。有一些程序可以盲目地帮助克服这个问题(见这里有关该问题的讨论和一些替代解决方案)。您可以首先尝试:

  • 重新启动计算机。
  • 禁用然后重新启用互联网共享和/或防火墙
  • 允许驱动程序(HyperKit或QEMU)和multipass允许防火墙中的传入连接。

Windows网络故障排除

体系结构

Multipass使用Windows上的本机“Hyper-V”虚拟机管理程序,以及为其创建的“默认交换机”。反过来,它使用“互联网共享”功能,为实例提供DHCP (IP地址)和DNS(域名解析)。

已知问题

默认开关出错

不幸的是,默认开关是众所周知的古怪,Windows更新经常把它放在一个奇怪的状态。这可能会导致新实例无法启动,现有实例启动超时。

在重新启动后,这种中断状态仍然存在。有帮助的一种方法是从默认交换机中移除网络共享并重新启动:

PS> Get-HNSNetwork | ? Name -Like "Default Switch" | Remove-HNSNetwork
PS> Restart-Computer

Hyper-V将在下次启动时重新创建它。

过时的Internet连接共享租约

实例超时的另一个原因可能是特定实例名称的“stale”IP地址存储在Internet Connection Sharing主机文件。

使用管理员权限,编辑C:\ WINDOWS \ System32 \ drivers \ etc \ hosts . ics,并查找任何包含您的实例名称的条目。如果有一个以上的条目,请删除除列出的第一个之外的所有条目。请保存文件,然后重试。

防病毒/安全软件阻止实例

防病毒和网络安全软件不一定能够感知虚拟化。如果您的连接有问题,暂时禁用该软件进行测试可能会产生积极的结果。这种软件的例子是赛门铁克,ESET,卡巴斯基和恶意软件字节。

参考

技术信息-规范、API、架构。

Multipass通道CLI命令

`multipass alias’命令

[从版本1.8.0开始]

alias命令使Multipass创建一个持久别名,以便在给定实例上运行命令。其语法如下:

multipass alias instance:command [name]

如果name则别名默认为command

[从版本1.10.0开始]

运行这个之后,一个新的别名被定义为运行command在给定的实例上。默认情况下,从Multipass 1.10.0开始,如果在实例上装载了执行别名的主机文件夹,实例上的工作目录将更改为装载的目录。使用参数定义别名时,可以避免这种行为--no-map-working-directory

multipass aliases 命令

aliases命令显示为所有实例定义的别名。它的基本用法是调用带有多路别名的命令。

$ multipass aliases
Alias  Instance         Command  Working directory
lsrm   rewarded-merlin  ls       default
topfp  flying-pig       top      map

从Multipass 1.10.0开始出现的工作目录列告诉我们别名将在主机的哪个目录上执行。值default意味着别名将在实例默认工作目录中执行(通常是/home/ubuntu)。值映射意味着,如果用户调用别名的主机目录装载在实例上,别名将在实例上装载的目录上执行。在1.10.0之前的版本中,执行目录将始终是默认的;从Multipass 1.10.0开始,只有在创建别名时出现- no-map-working-directory参数,该值才是默认值。

该命令可以与- format或-f一起使用,以指定所需的输出格式(csv、json、table或yaml)。

multipass authenticate 命令

multipass authenticate命令允许客户端使用multipass服务进行身份验证。一旦通过身份验证,客户端就可以发出list、launch等命令。

$ multipass authenticate --help
Usage: multipass authenticate [options] [<passphrase>]
Authenticate with the Multipass service.
A system administrator should provide you with a passphrase
to allow use of the Multipass service.

Options:
  -h, --help     Display this help
  -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.

Arguments:
  passphrase     Passphrase to register with the Multipass service. If omitted,
                 a prompt will be displayed for entering the passphrase.

为了帮助减少身份验证的输入量,还可以使用multipass auth作为别名:

$ multipass auth foo

如果authenticate命令行中没有给出密码,将会显示一个提示,要求输入密码:

$ multipass authenticate
Please enter passphrase:

它是如何工作的

Linux和macoOS

Linux和macOS主机目前使用Unix域套接字进行客户端和守护程序通信。第一次使用时,这个套接字只允许客户端通过属于该套接字所属的特定组的用户进行连接。例如,该组可以是sudo、admin或wheel,用户需要属于该组,否则连接时权限将被拒绝。

在第一个客户机与属于套接字管理组的用户连接之后,客户机的OpenSSL证书将被守护进程接受,然后套接字将对所有用户开放以供连接。尝试连接到Multipass服务的任何其他用户都需要使用之前设置的local.passphrase向该服务进行身份验证

Windows

Windows主机使用TCP套接字在端口50051上侦听客户端连接。这个套接字对所有人开放,因为TCP套接字没有文件所有权的概念。这并不十分安全,因为任何多路客户端都可以连接到该服务并发出任何命令。

为了缩小这个差距,现在需要使用Multipass服务对客户端进行身份验证。为了减轻必须对客户端进行身份验证的负担,安装了更新版本的Multipass的用户将自动使用该服务对其客户端进行身份验证。连接到该服务的任何其他用户都必须使用之前设置的local.passphrase进行身份验证

multipass delete 命令

multipass delete命令将从使用中删除实例。这不会破坏实例,并且可以通过多遍恢复命令再次使用。但是,使用-p/ - purge选项将销毁实例,并且无法恢复

  • all选项将删除所有实例。使用此选项时要小心。

已删除但未销毁的实例可以使用多次清除命令永久删除。

$ multipass delete --help
Usage: multipass delete [options] <name> [<name> ...]
Delete instances, to be purged with the "purge" command,
or recovered with the "recover" command.

Options:
  -h, --help     Display this help
  -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.
  --all          Delete all instances
  -p, --purge    Purge instances immediately

Arguments:
  name           Names of instances to delete
$ multipass delete calm-squirrel

$ multipass delete --purge legal-takin

multipass exec 命令

multipass exec命令执行实例内部的给定命令。第一个参数是要在其上运行命令的实例,-可以选择将multipass选项与其余选项分开-命令本身要运行:

$ multipass exec primary -- uname -r
4.15.0-48-generic

您可以通过管道将标准输入和输出发送到命令或从命令接收

$ multipass exec primary -- lsb_release -a | grep ^Codename:
No LSB modules are available.
Codename:       bionic

如果要将选项传递给正在运行的命令,分隔符是必需的。必须先指定exec命令本身的选项

从Multipass 1 . 10 . 0版开始,可以指定命令必须在哪个实例目录下执行。为此,有三种选择。第一个是- working-directory

,它告诉Multipass命令必须在文件夹< dir >中执行。举个例子,

$ multipass exec arriving-pipefish --working-directory /home -- ls -a
.  ..  ubuntu

ls -la命令显示了/home目录的内容,因为它是从那里执行的。

指定工作目录的第二个选项是首先查看挂载的文件夹。如果我们从装载在实例上的目录中执行主机上的别名,则命令将从那里在实例上执行。如果实例上没有装载工作目录,将在实例上的默认目录下执行该命令。这是版本1.10.0和更高版本中的默认行为,无需指定任何参数即可进行映射。

第三种选择是直接执行实例中默认目录下的命令(通常是/home/ubuntu。强制这种行为的参数是- no-map-working-directory。必须注意,在1.10.0之前的版本中,这是默认设置。

multipass find 命令

不带任何参数的multipass find命令将列出可用于在您的系统上通过multipass launch启动实例的别名以及相关的版本信息,例如:

$ multipass find
multipass launch …   Starts an instance of           Image version
------------------------------------------------------------------
[...]
18.04                Ubuntu 18.04 LTS                20181003
   (or: b, bionic, default, lts)
daily:18.10          Ubuntu 18.10                    20181011
   (or: c, cosmic, devel)

完整的多遍帮助查找输出解释了可用的选项:

$ multipass help find
Usage: multipass find [options] [<remote:>][<string>]
Lists available images matching <string> for creating instances from.
With no search string, lists all aliases for supported Ubuntu releases.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more
                 detail

Arguments:
  string         An optional value to search for in [<remote:>]<string> format,
                 where <remote> can be either ‘release’ or ‘daily’. If <remote>
                 is omitted, it will search ‘release‘ first, and if no matches
                 are found, it will then search ‘daily‘. <string> can be a
                 partial image hash or an Ubuntu release version, codename or
                 alias.

您可以传递[:]形式的参数,将输出限制为该远程:

$ multipass find daily:
multipass launch …   Starts an instance of           Image version
------------------------------------------------------------------
[...]
daily:18.04          Ubuntu 18.04 LTS                20181011
   (or: b, bionic, default, lts)
daily:18.10          Ubuntu 18.10                    20181011
   (or: c, cosmic, devel)

支持的值有:

  • release,意思是Ubuntu云映像的发布版本,
  • 以及daily,开发和支持版本的日常构建。

您也可以要求一个特定的别名:

$ multipass find default
multipass launch …   Starts an instance of           Image version
------------------------------------------------------------------
default              Ubuntu 18.04 LTS                20181003

< alias >值的一组示例:

  • default -multipass上的默认版本,
  • lts-最新的长期支持版本,
  • devel -最新的开发系列版本(仅在每日:),
  • Ubuntu系列的代码名,
  • < c> -代码名的第一个字母,
  • < XX。YY> -一个系列的版本号。

这不是一个详尽的列表,可能会引入新的列表,并且您的系统可能不支持所有的列表。

multipass get` 命令

multipass get命令检索由“key”参数指定的单个设置的值。该键在分层设置树中采用点分隔路径的形式:

$ multipass get client.gui.autostart
true

参考资料中记录了可用的设置。

$ multipass help get
Usage: multipass get [options] <key>
Get the configuration setting corresponding to the given key.

Keys:
  client.gui.autostart
  client.gui.hotkey
  client.primary-name
  local.bridged-network
  local.driver
  local.privileged-mounts

Options:
  -h, --help     Display this help
  -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.
  --raw          Output in raw format. For now, this affects only the
                 representation of empty values (i.e. "" instead of "<empty>").

Arguments:
  key            Path to the setting whose configured value should be obtained.

multipass get 命令 (preview)

multipass get命令提供了一种获取multipass设置的方法。例如:

$ multipass get local.driver
qemu

参考资料中记录了可用的设置。

当不带参数使用时,它将所有可用设置显示为< key>=对的列表:

$ multipass get
client.gui.autostart=true
client.gui.hotkey=Ctrl+Alt+U
client.primary-name=primary

使用- keys选项,它仅列出设置键:

$ multipass get --keys
client.gui.autostart
client.gui.hotkey
client.primary-name

在所有情况下,get只返回执行时可用的设置。

也可以给这个命令指定位置参数,限制要检索的设置。这种参数可以采用普通键(例如client.primary-name)或键通配符(例如local)的形式。*).

multipass get根据给定的位置参数过滤设置,仅返回满足这些参数的可用设置的子集:

$ multipass get client.gui.*
client.gui.autostart=true
client.gui.hotkey=Ctrl+Alt+U
$ multipass get client.gui.* local.driver
client.gui.autostart=true
client.gui.hotkey=Ctrl+Alt+U
local.driver=qemu

当只有一个设置满足输入参数时,它的键被省略,只打印它的值,除非还提供了- keys(在这种情况下,仍然只打印键):

 multipass get client.gui.autostart
true

如果没有与参数匹配的设置,multipass将抱怨它无法识别设置key(s)。

使用- raw选项,以原始格式打印值。目前,这只影响空值的表示:

$ multipass get --raw client.primary-name

$ multipass get client.primary-name
<empty>

使用multipass道帮助获取快速参考:

$ multipass help get
Usage: multipass get [options] [<arg> ...]
Get the configuration setting(s) corresponding to the given key(s), or all settings if no key is specified.

Some common settings keys are:
  - client.gui.autostart
  - local.driver
  - local.privileged-mounts

Use `multipass get --keys` to obtain the full list of available settings at any given time.

Options:
  -h, --help     Display this help
  -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.
  --raw          Output in raw format. For now, this affects only the
                 representation of empty values (i.e. "" instead of "<empty>").
  --keys         List available settings keys. This outputs the whole list of
                 currently available settings keys, or a matching subset when
                 <arg>... is(are) provided

Arguments:
  arg            Setting(s) key(s), i.e. path(s) to the setting(s) whose
                 configured value(s) should be obtained.

multipass help 命令

不带参数的multipass help命令将列出所有可用的命令,并附有简要说明。它接受一个< command >参数来获取有关该命令的详细帮助。

$ multipass help
Usage: multipass [options] <command>
Create, control and connect to Ubuntu instances.

This is a command line utility for multipass, a
service that manages Ubuntu instances.

Options:
  -h, --help     Display this help
  -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.

Available commands:
  alias         Create an alias
  aliases       List available aliases
  authenticate  Authenticate client
  delete        Delete instances
  exec          Run a command on an instance
  find          Display available images to create instances from
  get           Get a configuration setting
  help          Display help about a command
  info          Display information about instances
  launch        Create and start an Ubuntu instance
  list          List all available instances
  mount         Mount a local directory in the instance
  networks      List available network interfaces
  purge         Purge all deleted instances permanently
  recover       Recover deleted instances
  restart       Restart instances
  set           Set a configuration setting
  shell         Open a shell on a running instance
  start         Start instances
  stop          Stop running instances
  suspend       Suspend running instances
  transfer      Transfer files between the host and instances
  umount        Unmount a directory from an instance
  unalias       Remove an alias
  version       Show version details

使用- help选项会产生相同的结果。

–verbose传递给任何命令都会增加其输出详细程度,您可以重复它(最多三次)以获得更多输出。默认情况下,将只显示错误,并添加-v警告,-vv启用信息性消息,-vvv将打印出调试信息。

有关其他命令的信息,请参见我们的命令行参考。

multipass info` 命令

multipass info命令显示作为参数给定的实例的属性,如果给定了- all,则显示所有创建的实例的属性:

$ multipass info calm-squirrel
Name:           calm-squirrel
State:          RUNNING
IPv4:           10.218.69.109
Release:        Ubuntu 16.04.6 LTS
Image hash:     485bf889ca70 (Ubuntu 16.04 LTS)
Load:           0.00 0.03 0.02
Disk usage:     849.4M out of 4.8G
Memory usage:   41.9M out of 992.0M

完整的多通道帮助信息输出解释了可用的选项:

$ multipass help info         
Usage: multipass info [options] [<name> ...]
Display information about instances

Options:
  -h, --help         Display this help
  -v, --verbose      Increase logging verbosity, repeat up to three times for
                     more detail
  --all              Display info for all instances
  --format <format>  Output info in the requested format.
                     Valid formats are: table (default), json, csv and yaml

Arguments:
  name               Names of instances to display information about

与list命令类似,唯一的选项是- format,它允许您选择数据的显示方式——人类可读的表格或JSON、CSV和YAML之一,例如:

$ multipass info --format yaml calm-squirrel
errors:
  - ~
calm-squirrel:
  - state: RUNNING
    image_hash: 485bf889ca70f877511705b9b82b1ab7866718128c3312549e0b6ce11bb14b20
    image_release: 16.04 LTS
    release: Ubuntu 16.04.6 LTS
    load:
      - 0
      - 0.01
      - 0
    disks:
      - sda1:
          used: 905637888
          total: 5136297984
    memory:
      usage: 31199232
      total: 1040195584
    ipv4:
      - 10.218.69.109
    mounts: ~

multipass launch 命令

不带任何参数的multipass launch命令将使用随机生成的名称,基于默认映像创建并启动一个新实例:

$ multipass launch
…
Launched: relishing-lionfish

然后,您可以通过实例的名称进入该实例

$ multipass shell relishing-lionfish
…
multipass@relishing-lionfish:~$ 

完整的多通道帮助启动输出解释了可用选项:

$  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> | <url>           Path or URL 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.
  --mount <local-path>:<instance-path>  Mount a local directory inside the
                                        instance. If <instance-path> is omitted,
                                        the mount point will be the same as the
                                        absolute path of <local-path>
  --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.

唯一可选的位置参数是启动实例的图像。有关可用图像的信息,请参见多通道查找文档。还可以提供映像的完整URL(对于运行multipassd的主机上可用的映像,使用file://)。

您可以通过传递- cpu、- disk、- mem选项中的任何一个来更改实例可用的资源,分别允许更多的cpu核心、磁盘空间或RAM。

如果希望实例有自己选择的名称,请使用- name。它必须是唯一的,两个实例不能共享同一个名称。

通过向- cloud-init传递文件名或URL,您可以向cloud-init提供“用户数据”,以便在第一次引导时定制实例。有关示例,请参见他们的文档。

这–network选项允许使用附加网络接口启动实例。[从版本1.6.0开始]

Passing - bridged和- network bridged是- network 的快捷方式,其中< name >是通过multipass set local . bridged-interface配置的。[从版本1.7.0开始]

–mount选项允许在实例启动后通过调用mount命令在实例中挂载多个文件夹。可以使用不同的挂载路径多次指定它。[从版本1.10.0开始]

如果您需要更改Multipass等待机器启动和初始化的时间,请使用- timeout。[从版本1.7.0开始]

multipass list 命令

multipass list命令列出所有创建的实例及其一些属性

$ multipass list
Name                    State             IPv4             Release
primary                 SUSPENDED         --               Ubuntu 18.04 LTS
calm-squirrel           RUNNING           10.218.69.109    Ubuntu 16.04 LTS

完整的多遍帮助列表输出解释了可用选项:

$ multipass help list
Usage: multipass list [options]
List all instances which have been created.

Options:
  -h, --help         Display this help
  -v, --verbose      Increase logging verbosity, repeat up to three times for
                     more detail
  --format <format>  Output list in the requested format.
                     Valid formats are: table (default), json, csv and yaml

该命令特有的唯一选项是- format,它允许您选择数据的显示方式——人类可读的表格或JSON、CSV和YAML之一,例如:

$ multipass list --format yaml
primary:
  - state: SUSPENDED
    ipv4:
      - ""
    release: 18.04 LTS
calm-squirrel:
  - state: RUNNING
    ipv4:
      - 10.218.69.109
    release: 16.04 LTS

multipass mount 命令

$ multipass help mount
Usage: multipass mount [options] <source> <target> [<target> ...]
Mount a local directory inside the instance. If the instance is
not currently running, the directory will be mounted
automatically on next boot.

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.
  -g, --gid-map <host>:<instance>  A mapping of group IDs for use in the mount.
                                   File and folder ownership will be mapped from
                                   <host> to <instance> inside the instance. Can
                                   be used multiple times.
  -u, --uid-map <host>:<instance>  A mapping of user IDs for use in the mount.
                                   File and folder ownership will be mapped from
                                   <host> to <instance> inside the instance. Can
                                   be used multiple times.

Arguments:
  source                           Path of the local directory to mount
  target                           Target mount points, in <name>[:<path>]
                                   format, where <name> is an instance name, and
                                   optional <path> is the mount point. If
                                   omitted, the mount point will be the same as
                                   the source's absolute path

multipass networks 命令

multipass networks命令列出了multipass可以将实例连接到的网络接口。结果取决于使用的平台和驱动程序。此时,网络只能在以下情况下找到接口:

下面是一个安装了Hyper-V的Windows上的示例:

PS> multipass networks
Name            Type    Description
Default Switch  switch  Virtual Switch with internal networking
ExternalSwitch  switch  Virtual Switch with external networking via "Red Hat VirtIO Ethernet Adapter"
InternalSwitch  switch  Virtual Switch with internal networking
PrivSwitch      switch  Private virtual switch

像list一样,networks支持- format选项。另一个例子,现在有了macOS上的VirtualBox:

$ multipass networks --format yaml
bridge0:
  - type: bridge
    description: Network bridge with en1, en2
bridge2:
  - type: bridge
    description: Empty network bridge
en0:
  - type: wifi
    description: Wi-Fi (Wireless)
en1:
  - type: thunderbolt
    description: Thunderbolt 1
en2:
  - type: thunderbolt
    description: Thunderbolt 2

有关如何使用这些界面的说明,请参见启动和附加网络界面。

multipass帮助网络解释了可用的选项:

$ multipass help networks
Usage: multipass networks [options]
List host network devices (physical interfaces, virtual switches, bridges)
available to integrate with using the `--network` switch to the `launch`
command.

Options:
  -h, --help         Display this help
  -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.
  --format <format>  Output list in the requested format.
                     Valid formats are: table (default), json, csv and yaml

multipass purge 命令

multipass purge命令将永久删除使用multipass delete命令删除的所有实例。这将破坏实例的所有痕迹,并且无法撤消。

$ multipass purge --help
Usage: multipass purge [options]
Purge all deleted instances permanently, including all their data.

Options:
  -h, --help     Display this help
  -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.
multipass purge
$

multipass recover 命令

multipass recover命令将恢复以前通过multipass delete删除的实例。要做到这一点,不能使用多遍清除或多遍删除-清除来清除实例。该命令的效果就像从未执行过多次删除一样

$ multipass recover --help
Usage: multipass recover [options] <name> [<name> ...]
Recover deleted instances so they can be used again.

Options:
  -h, --help     Display this help
  -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.
  --all          Recover all deleted instances

Arguments:
  name           Names of instances to recover
$ multipass recover gentle-weevil
multipass recover --all
$

multipass set` 命令

multipass set命令采用< key>=形式的参数来配置单个设置。“kkey”部分是一个点分隔的路径,用于标识分层设置树中的设置。“值”部分应该设置为:

$ multipass set client.gui.autostart=false

要了解任何时候的配置值,请参见get。参考资料中记录了可用的设置。

multipass help set输出解释了可用的选项:

$ multipass help set
Usage: multipass set [options] <key>=<value>
Set, to the given value, the configuration setting corresponding to the given key.

Keys:
  client.gui.autostart
  client.gui.hotkey
  client.primary-name
  local.bridged-network
  local.driver
  local.passphrase
  local.privileged-mounts

Options:
  -h, --help     Display this help
  -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.

Arguments:
  keyval         A key-value pair. The key specifies a path to the setting to
                 configure. The value is its intended value.

multipass shell 命令

multipass shell命令将在实例上打开一个shell提示符。如果没有任何参数,它将打开主实例的shell提示符。您也可以传递现有实例的名称。如果实例没有运行,它将自动启动。对于主实例的情况,如果它还不存在,它将被创建。

对于主实例:

$ multipass shell
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-72-generic x86_64)

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

  System information as of Thu Dec 19 16:11:12 EST 2019

  System load:  0.0               Processes:           87
  Usage of /:   24.0% of 4.67GB   Users logged in:     0
  Memory usage: 13%               IP address for ens4: 10.3.19.167
  Swap usage:   0%


11 packages can be updated.
3 updates are security updates.


Last login: Thu Dec 19 16:03:37 2019 from 10.3.19.1
ubuntu@primary:~$

对于名为bionic的实例:

$ multipass shell bionic
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-72-generic x86_64)

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

  System information as of Thu Dec 19 16:11:12 EST 2019

  System load:  0.0               Processes:           87
  Usage of /:   24.0% of 4.67GB   Users logged in:     0
  Memory usage: 13%               IP address for ens4: 10.3.19.167
  Swap usage:   0%


11 packages can be updated.
3 updates are security updates.


Last login: Thu Dec 19 16:03:37 2019 from 10.3.19.1
ubuntu@bionic:~$

multipass shell --help输出解释了可用的选项:

$ multipass shell --help
Usage: multipass shell [options] [<name>]
Open a shell prompt on the instance.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more
                 detail

Arguments:
  name           Name of the instance to open a shell on. If omitted, 'primary'
                 (the configured primary instance name) will be assumed. If the
                 instance is not running, an attempt is made to start it (see
                 `start` for more info).

multipass start 命令

不带任何参数的multipass start命令将启动主实例(如果它还不存在,则首先创建它)。您还可以传递一个或多个实例名或- all选项来同时启动多个实例:

$ multipass start
Configuring primary \
Launching primary |
…
$ multipass shell
multipass@primary:~$

完整的multipass help start启动输出解释了可用选项:

$ multipass help start
Usage: multipass start [options] [<name> ...]
Start the named instances. Exits with return code 0
when the instances start, or with an error code if
any fail to start.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more
                 detail
  --all          Start all instances

Arguments:
  name           Names of instances to start. If omitted, and without the --all
                 option, 'primary' (the configured primary instance name) will
                 be assumed. If 'primary' does not exist but is included in a
                 successful start command (either implicitly or explicitly), it
                 is launched automatically (see `launch` for more info).

multipass stop 命令

不带任何参数的多遍stop命令将停止主实例。您还可以传递一个或多个实例名或- all选项来同时停止多个实例:

sage: multipass stop [options] [<name> ...]
Stop the named instances, if running. Exits with
return code 0 if successful.

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.
  --all              Stop all instances
  -t, --time <time>  Time from now, in minutes, to delay shutdown of the
                     instance
  -c, --cancel       Cancel a pending delayed shutdown

Arguments:
  name               Names of instances to stop. If omitted, and without the
                     --all option, 'primary' will be assumed.

multipass suspend 命令

$ multipass help suspend
Usage: multipass suspend [options] [<name> ...]
Suspend the named instances, if running. Exits with
return code 0 if successful.

Options:
  -h, --help     Display this help
  -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.
  --all          Suspend all instances

Arguments:
  name           Names of instances to suspend. If omitted, and without the
                 --all option, 'primary' will be assumed.```

multipass transfer 命令

multipass transfer命令在主机和实例之间复制文件,而无需在实例上装载文件夹。

例如,要将本地文件local_file.txt复制到实例good-prawn的默认主文件夹,我们应该发出:

$ multipass transfer local_file.txt good-prawn:.

相反,要将文件instance_file.txt从ample-pigeon实例的默认主文件夹复制到当前工作文件夹,我们应该运行:

 multipass transfer ample-pigeon:remote_file.txt .

源文件可以是主机标准输入,在这种情况下,流将被写入实例上的目标文件。同样,目标可以是主机的标准输出,而源可以是实例上的文件。在这两种情况下,标准输入和输出是用-指定的。

完整的multipass help transfer输出解释了可用的选项:

$ multipass help transfer
Usage: multipass transfer [options] <source> [<source> ...] <destination>
Copy files between the host and instances.

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.

Arguments:
  source         One or more paths to transfer, prefixed with <name:> for paths
                 inside the instance, or '-' for stdin
  destination    The destination path, prefixed with <name:> for a path inside
                 the instance, or '-' for stdout

multipass umount 命令

$ multipass help umount
Usage: multipass umount [options] <mount> [<mount> ...]
Unmount a directory from an 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.

Arguments:
  mount          Mount points, in <name>[:<path>] format, where <name> are
                 instance names, and optional <path> are mount points. If
                 omitted, all mounts will be removed from the named instances.

multipass unalias 命令

multipass unalias命令删除以前用alias添加的别名。删除别名是通过以下方式完成的:

$ multipass unalias name

这将删除给定的别名,如果未定义别名,将出错。请注意,如果某个实例被删除并清除,则没有必要为该实例上定义的别名运行unalias,因为它们会被自动删除。Multipass 1.10.0引入了使用一个命令删除多个别名的功能:

$ multipass unalias name1 name2 name3

和参数- all,删除所有已定义的别名:

$ multipass unalias --all
multipass help unalias` explains the available options:

```plain
$ multipass help unalias
Usage: multipass unalias [options] <name> [<name> ...]
Remove aliases

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.
  --all          Remove all aliases

Arguments:
  name           Names of aliases to remove

multipass version 命令

不带参数的multipass version命令将显示multipass的客户端和守护程序版本。

$ multipass version
multipass  1.0.0
multipassd 1.0.0

如果有可用的Multipass更新,则除了上述输出(示例而非实际输出)之外,还会将其打印出来:

$ multipass version
multipass  1.0.0
multipassd 1.0.0

########################################################################################
Multipass 1.0.1 release
Bugfix release to address a crash

Go here for more information: https://github.com/canonical/multipass/releases/tag/v1.0.1
########################################################################################

使用- help选项打印出version命令的用法信息:

$ multipass version --help
Usage: multipass version [options]
Display version information about the multipass command
and daemon.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more
                 detail

Arguments:
source One or more paths to transfer, prefixed with name: for paths
inside the instance, or ‘-’ for stdin
destination The destination path, prefixed with name: for a path inside
the instance, or ‘-’ for stdout


# `multipass umount` 命令

```nohighlight
$ multipass help umount
Usage: multipass umount [options] <mount> [<mount> ...]
Unmount a directory from an 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.

Arguments:
  mount          Mount points, in <name>[:<path>] format, where <name> are
                 instance names, and optional <path> are mount points. If
                 omitted, all mounts will be removed from the named instances.

multipass unalias 命令

multipass unalias命令删除以前用alias添加的别名。删除别名是通过以下方式完成的:

$ multipass unalias name

这将删除给定的别名,如果未定义别名,将出错。请注意,如果某个实例被删除并清除,则没有必要为该实例上定义的别名运行unalias,因为它们会被自动删除。Multipass 1.10.0引入了使用一个命令删除多个别名的功能:

$ multipass unalias name1 name2 name3

和参数- all,删除所有已定义的别名:

$ multipass unalias --all
multipass help unalias` explains the available options:

```plain
$ multipass help unalias
Usage: multipass unalias [options] <name> [<name> ...]
Remove aliases

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.
  --all          Remove all aliases

Arguments:
  name           Names of aliases to remove

multipass version 命令

不带参数的multipass version命令将显示multipass的客户端和守护程序版本。

$ multipass version
multipass  1.0.0
multipassd 1.0.0

如果有可用的Multipass更新,则除了上述输出(示例而非实际输出)之外,还会将其打印出来:

$ multipass version
multipass  1.0.0
multipassd 1.0.0

########################################################################################
Multipass 1.0.1 release
Bugfix release to address a crash

Go here for more information: https://github.com/canonical/multipass/releases/tag/v1.0.1
########################################################################################

使用- help选项打印出version命令的用法信息:

$ multipass version --help
Usage: multipass version [options]
Display version information about the multipass command
and daemon.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more
                 detail
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用基于URL regexp的数据自动登录到基本身份验证。 此扩展名使您可以注册与正则表达式关联的凭据。当您浏览需要HTTP基本身份验证的网站时,其URL将与正则表达式匹配,并且如果找到匹配项,则将自动发送凭据 MultiPass地址栏图标上的绿色徽标表示您已正确通过身份验证,红色徽标表示凭据已被拒绝,最后黄色徽标表示此域存在多个匹配项。如果您要报告问题,请使用Github问题跟踪器:https://github.com/krtek4/MultiPass/issues Changelog 0.8.0-22/11/2018-删除Google Analytics 0.8.1-22/11 / 2018-避免在有问题的正则表达式0.8.2上破坏整个扩展名-2018年11月22日-删除onAuthRequired hack,因为FF在一年的大部分时间里都支持它0.8.3-01/12/2018-波兰语翻译0.7.0- 27/02/2017-防止XSS,添加选项以禁用Analytics 0.7.1-27/03/2017-更好地检测存储名称空间0.7.2-09/06/2017-避免在正则表达式太长时弄乱布局0.7 .3-2009年9月6日-在规则0.7.3中添加优先级字段-2017年6月13日-添加缺少的翻译版本0.6.0-2016年6月11日-正则表达式测试器,Firefox支持0.6.1-08/11 / 2016-Opera支持0.6.2-13/11/2016-德语和荷兰语翻译,修复了突出显示0.6.3的问题-2016/11/18-删除了jQuery依赖项0.6.4-18/11/2016-改进了测试器,修复版本,改进分析功能0.6.5-14/02/2017-禁用Fire中的跟踪狐狸,减少分析次数0.5.3-2016年6月11日-法语翻译0.5.2-2016年5月11日-恢复分析0.5.1-2016年10月30日-解决了新添加的凭据不存在的问题在重新启动之前可用0.5.0-2016年10月29日-改进翻译机制0.4.3-24/09/2015-修复了添加凭据时的问题0.4.2-22/09/2015-重置按钮0.4.1-22 / 09/2015-允许条目版本0.4.0-2014年11月11日-样式,突出显示与弹出窗口中当前URL匹配的正则表达式0.3.2-2014年6月8日-修复了分析0.3.1-2014年6月8日-修复了徽章问题0.3.0-2014年4月8日-避免错误循环,显示徽章,JSON凭证导入0.2.0-2014年4月8日-新选项面板0.1.2-2014年4月8日-添加Google Analytics(分析) 0.1.1-30/07/2014-从Chrome BasicAuth重命名为MultiPass 0.1.0-2014/07/28-初始版本 支持语言:Deutsch,English,Fran&ccedil;ais,Nederlands,italiano,polski

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值