从通用化映像创建规模集Create a scale set from a generalized image

使用 Azure CLI 从共享映像库中存储的通用化映像版本创建规模集。Create a scale set from a generalized image version stored in a Shared Image Gallery using the Azure CLI. 若要使用专用化映像版本创建规模集,请参阅从专用化映像创建规模集实例If want to create a scale set using a specialized image version, see Create scale set instances from a specialized image.

如果选择在本地安装并使用 CLI,本教程要求运行 Azure CLI 2.4.0 或更高版本。If you choose to install and use the CLI locally, this tutorial requires that you are running the Azure CLI version 2.4.0 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

在此示例中,请根据需要替换资源名称。Replace resource names as needed in this example.

使用 az sig image-definition list 列出库中的映像定义,以查看定义的名称和 ID。List the image definitions in a gallery using az sig image-definition list to see the name and ID of the definitions.

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

使用 az vmss create 创建规模集。Create the scale set using az vmss create.

使用 --image 的映像定义 ID 从可用的最新映像版本创建规模集实例。Use the image definition ID for --image to create the scale set instances from the latest version of the image that is available. 还可以通过提供 --image 的映像版本 ID 从特定版本创建规模集实例。You can also create the scale set instances from a specific version by supplying the image version ID for --image. 请注意,使用特定映像版本意味着:如果该特定映像版本由于已删除或已从区域中删除而无法使用,则自动化可能会失败。Be aware that using a specific image version means automation could fail if that specific image version isn't available because it was deleted or removed from the region. 建议使用映像定义 ID 来创建新的 VM(除非需要特定的映像版本)。We recommend using the image definition ID for creating your new VM, unless a specific image version is required.

在此示例中,我们将从 myImageDefinition 映像的最新版本创建实例。In this example, we are creating instances from the latest version of the myImageDefinition image.

az group create --name myResourceGroup --location chinanorth
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 需要几分钟时间。It takes a few minutes to create and configure all the scale set resources and VMs.

后续步骤Next steps

可以使用模板创建共享映像库资源。You can create Shared Image Gallery resource using templates. 提供多个 Azure 快速入门模板:There are several Azure Quickstart Templates available:

有关共享映像库的详细信息,请参阅概述For more information about Shared Image Galleries, see the Overview. 如果遇到问题,请参阅排查共享映像库问题If you run into issues, see Troubleshooting shared image galleries.