使用 Azure CLI 查找 Azure 市场映像信息

注意

本文引用了 CentOS,这是一个接近生命周期结束 (EOL) 状态的 Linux 发行版。 请相应地考虑你的使用和规划。 有关详细信息,请参阅 CentOS 生命周期结束指南

适用于:✔️ Linux VM ✔️ Windows VM ✔️ 灵活规模集

本主题介绍如何使用 Azure CLI 在 Azure 市场中查找 VM 映像。 使用 CLI、资源管理器模板或其他工具以编程方式创建 VM 时,使用此信息指定市场映像。

还可以使用 Azure 市场Azure PowerShell 浏览可用的映像和产品/服务。

请确保已安装最新版的 Azure CLI 且已登录到 Azure 帐户 (az login)。

注意

在可以在由世纪互联运营的 Microsoft Azure 中使用 Azure CLI 之前,请先运行 az cloud set -n AzureChinaCloud 来更改云环境。 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloud

术语

Azure 中的市场映像具有以下属性:

  • 发布者:创建映像的组织。 示例:Canonical、SUSE
  • 产品/服务:发布者创建的一组相关映像的名称。 示例:0001-com-ubuntu-server-jammy、sles-15-sp3。
  • SKU:产品/服务的实例,例如分发的主要版本。 示例:22_04-lts-gen2、8-lvm-gen2、gen2。
  • 版本:映像 SKU 的版本号。

可以单独传递这些值,或将这些值作为映像 URN 传递,并将它们用冒号 (:) 隔开。 例如:发布者:产品/服务:SKU:版本 。 可将 URN 中的版本号替换为 latest,以使用最新版本的映像。

如果映像发布服务器提供附加许可和购买条款,则必须先接受这些条款才能使用映像。 有关详细信息,请参阅查看购买计划信息

可以运行 az vm image list --all 查看所有可用的映像,但生成整个列表可能需要几分钟时间。 一种更快的方式是使用 az vm image list(无需使用 --all 选项)来查看 Azure 市场中的常用 VM 映像列表。 例如,运行以下命令以表格形式显示缓存的常用映像列表:

az vm image list --output table

输出包括映像 URN。 还可以使用 UrnAlias,这是为 UbuntuLTS 等常用映像创建的简化版本。

Offer                         Publisher               Sku                                 Urn                                     UrnAlias                 Version
----------------------------  ----------------------  ----------------------------------  ------------------------------------------------------------------------------  -----------------------  ---------
CentOS                        OpenLogic               7.5                                 OpenLogic:CentOS:7.5:latest
                                     CentOS                   latest
debian-10                     Debian                  10                                  Debian:debian-10:10:latest
                                     Debian                   latest
opensuse-leap-15-3            SUSE                    gen2                                SUSE:opensuse-leap-15-3:gen2:latest                                             openSUSE-Leap            latest
sles-15-sp3                   SUSE                    gen2                                SUSE:sles-15-sp3:gen2:latest                                     SLES                     latest
UbuntuServer                  Canonical               18.04-LTS                           Canonical:UbuntuServer:18.04-LTS:latest                                         UbuntuLTS                latest
WindowsServer                 MicrosoftWindowsServer  2022-Datacenter                     MicrosoftWindowsServer:WindowsServer:2022-Datacenter:latest                     Win2022Datacenter        latest
WindowsServer                 MicrosoftWindowsServer  2022-datacenter-azure-edition-core  MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition-core:latest  Win2022AzureEditionCore  latest
WindowsServer                 MicrosoftWindowsServer  2019-Datacenter                     MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest                     Win2019Datacenter        latest
WindowsServer                 MicrosoftWindowsServer  2016-Datacenter                     MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest                     Win2016Datacenter        latest
WindowsServer                 MicrosoftWindowsServer  2012-R2-Datacenter                  MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest                  Win2012R2Datacenter      latest
WindowsServer                 MicrosoftWindowsServer  2012-Datacenter                     MicrosoftWindowsServer:WindowsServer:2012-Datacenter:latest                     Win2012Datacenter        latest
WindowsServer                 MicrosoftWindowsServer  2008-R2-SP1                         MicrosoftWindowsServer:WindowsServer:2008-R2-SP1:latest                         Win2008R2SP1             latest

查找特定映像

可以按 --publisher 或其他参数筛选映像列表以限制结果。

例如,以下命令显示所有 Debian 产品/服务:

az vm image list  -l chinaeast2 --offer Debian --all --output table

可以通过添加 --architecture 参数将结果限制为单个体系结构。 例如,如果要显示 Canonical 中提供的所有 Arm64 映像,请执行以下操作:

az vm image list -l chinaeast2 --architecture Arm64 --publisher Canonical --all --output table

查看所有可用映像

在某个位置查找映像的另一种方法是,运行序列中的 az vm image list-publishersaz vm image list-offersaz vm image list-skus 命令。 可以使用这些命令确定以下值:

  1. 列出某个位置的映像发布服务器。 在本例中,我们探讨的是中国北部区域。

    az vm image list-publishers --location chinanorth --output table
    
  2. 对于给定的发布者,列出其产品。 在本例中,我们将 Canonical 添加为发布服务器。

    az vm image list-offers --location chinanorth --publisher Canonical --output table
    
  3. 对于给定的产品,列出其 SKU。 在本例中,我们将 UbuntuServer 添加为产品/服务。

    az vm image list-skus --location chinanorth --publisher Canonical --offer UbuntuServer --output table
    

注意

Canonical 更改了他们用于最新版本的套餐名称。 在 Ubuntu 20.04 之前,套餐名称为 UbuntuServer。 对于 Ubuntu 20.04,套餐名称为 0001-com-ubuntu-server-focal,对于 Ubuntu 22.04,其名称为 0001-com-ubuntu-server-jammy

  1. 对于给定的发布服务器、产品/服务和 SKU,显示所有版本的映像。 在本例中,我们将 18.04-LTS 添加为 SKU。

    az vm image list \
        --location chinanorth \
        --publisher Canonical \
        --offer UbuntuServer \
        --sku 18.04-LTS \
        --all --output table
    

使用 az vm create 命令创建 VM 时,可将 URN 列的此值与 --image 参数一起传递。 还可以将 URN 中的版本号替换为“latest”以使用最新版本的映像。

如果使用资源管理器模板部署 VM,请在 imageReference 属性中单独设置映像参数。

查看购买计划信息

Azure 市场中的某些 VM 映像具有附加许可条款和购买条款,你必须接受这些条款,然后才能以编程方式部署这些映像。

若要从此类映像部署 VM,需要在首次使用时接受映像的条款,每个订阅接受一次。 还需要指定采购计划参数,以便从该映像部署 VM

若要查看映像的购买计划信息,请使用映像的 URN 运行 az vm image show 命令。 如果输出中的 plan 属性不是 null,则映像有条款,在以编程方式部署前需要接受该条款。

例如,Canonical Ubuntu Server 18.04 LTS 映像没有、额外条款,因为 plan 信息为 null

az vm image show --location chinanorth --urn Canonical:UbuntuServer:18.04-LTS:latest

输出:

{
  "dataDiskImages": [],
  "id": "/Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Providers/Microsoft.Compute/Locations/chinanorth/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/18.04-LTS/Versions/18.04.201901220",
  "location": "chinanorth",
  "name": "18.04.201901220",
  "osDiskImage": {
    "operatingSystem": "Linux"
  },
  "plan": null,
  "tags": null
}

后续步骤

若要使用映像信息快速创建虚拟机,请参阅使用 Azure CLI 创建和管理 Linux VM