你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

从通用化映像创建规模集

Azure Compute Gallery 中存储的通用映像版本创建规模集。 若要使用专用映像版本创建规模集,请参阅从专用映像创建规模集实例

重要

从 2023 年 11 月开始,使用 PowerShell 和 Azure CLI 创建的 VM 规模集将默认为灵活业务流程模式(如果未指定业务流程模式)。 若要详细了解此更改以及你应采取哪些操作,请访问针对 VMSS PowerShell/CLI 客户的中断性变更 - Microsoft 社区中心

在此示例中,请根据需要替换资源名称。

使用 az sig image-definition list 列出库中的映像定义,以查看定义的名称和 ID。

resourceGroup=myGalleryRG
gallery=myGallery
az sig image-definition list \
   --resource-group $resourceGroup \
   --gallery-name $gallery \
   --query "[].[name, id]" \
   --output tsv

使用 az vmss create 创建规模集。

使用 --image 的映像定义 ID 从可用的最新映像版本创建规模集实例。 还可以通过提供 --image 的映像版本 ID 从特定版本创建规模集实例。 请注意,使用特定映像版本意味着:如果该特定映像版本由于已删除或已从区域中删除而无法使用,则自动化可能会失败。 建议使用映像定义 ID 来创建新的 VM(除非需要特定的映像版本)。

在此示例中,我们将从 myImageDefinition 映像的最新版本创建实例。

az group create --name myResourceGroup --location eastus
az vmss create \
   --resource-group myResourceGroup \
   --name myScaleSet \
   --image "/subscriptions/<Subscription ID>/resourceGroups/myGalleryRG/providers/Microsoft.Compute/galleries/myGallery/images/myImageDefinition" 
   --admin-username azureuser \
   --generate-ssh-keys

创建和配置所有的规模集资源和 VM 需要几分钟时间。

重要

Azure Compute Gallery - 社区库目前为预览版,并受 Azure Compute Gallery 预览版条款 - 社区库的约束。

Microsoft 不为社区库中的映像提供支持。

可以从社区库中的映像创建规模集,但如果以后删除该映像,则无法纵向扩展。 若要确保可长期访问映像,应考虑从使用要用于规模集的社区库映像创建的 VM 在自己的库中创建映像。 有关详细信息,请参阅创建映像定义和映像版本

作为最终用户,若要获取社区库的公共名称,需要使用门户。 转到“虚拟机”>“创建”>“Azure 虚拟机”>“映像”>“查看所有映像”>“社区映像”>“公共库名称”。

如果选择在本地安装并使用 CLI,社区库要求运行 Azure CLI 版本 2.35.0 或更高版本。 运行 az --version 即可查找版本。 如果需要进行安装或升级,请参阅安装 Azure CLI

在此示例中,请根据需要替换资源名称。

注意

作为最终用户,若要获取社区库的公共名称,需要使用门户。 转到“虚拟机”>“创建”>“Azure 虚拟机”>“映像”>“查看所有映像”>“社区映像”>“公共库名称”。

若要使用共享到社区库的映像创建 VM,请使用 --image 的映像的唯一 ID,其格式如下:

/CommunityGalleries/<community gallery name>/Images/<image name>/Versions/latest

使用 az sig image-definition list-community 列出社区库中可用的所有映像定义。 在此示例中,我们列出美国西部的 ContosoImage 库中的所有映像,以及创建 VM 所需的唯一 ID(按名称)、OS 和 OS 状态。

 az sig image-definition list-community \
   --public-gallery-name "ContosoImages-1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f" \
   --location westus \
   --query [*]."{Name:name,ID:uniqueId,OS:osType,State:osState}" -o table

通过将 --image 参数设置为社区库中映像的唯一 ID 来创建规模集。

az group create --name myResourceGroup --location eastus

imgDef="/CommunityGalleries/ContosoImages-1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f/Images/myLinuxImage/Versions/latest"

az vmss create \
   --resource-group myResourceGroup \
   --name myScaleSet \
   --image $imgDef \
   --orchestration-mode Flexible \
   --admin-username azureuser \
   --generate-ssh-keys

使用社区映像时,系统会提示你接受法律条款。 消息将如下所示:

To create the scale set from community gallery image, you must accept the license agreement and privacy statement: http://contoso.com. (If you want to accept the legal terms by default, please use the option '--accept-term' when creating VM/VMSS) (Y/n): 

后续步骤

Azure 映像生成器(预览版)可以帮助自动创建映像版本,你甚至可以使用它进行更新以及从现有的映像版本创建新映像版本

还可使用模板创建 Azure Compute Gallery 资源。 提供多个 Azure 快速入门模板:

有关共享映像库的详细信息,请参阅概述。 如果遇到问题,请参阅排查共享映像库问题