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

使用 Azure 门户创建虚拟机规模集

本文将详细介绍如何使用 Azure CLI 创建虚拟机规模集。

确保已安装最新的 Azure CLI,并且已使用 az login 登录到 Azure 帐户。

启动 Azure Cloud Shell

Azure Cloud Shell 是免费的交互式 shell,可以使用它运行本文中的步骤。 它预安装有常用 Azure 工具并将其配置与帐户一起使用。

若要打开 Cloud Shell,只需要从代码块的右上角选择“试一试”。 也可以通过转到 https://shell.azure.com/cli 在单独的浏览器标签页中启动 Cloud Shell。 选择“复制”以复制代码块,将其粘贴到 Cloud Shell 中,然后按 Enter 来运行它。

创建资源组

使用 az group create 创建资源组,如下所示:

az group create --name myResourceGroup --location eastus

创建虚拟机规模集

重要

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

现在,使用 az vmss create 创建虚拟机规模集。 以下示例创建实例计数为 2 的规模集,并生成 SSH 密钥。

az vmss create \
  --resource-group myResourceGroup \
  --name myScaleSet \
  --orchestration-mode Flexible \
  --image <SKU Linux Image> \
  --instance-count 2 \
  --admin-username azureuser \
  --generate-ssh-keys

清理资源

若要删除规模集和其他资源,请使用 az group delete 删除资源组及其所有资源。 --no-wait 参数会使光标返回提示符处,无需等待操作完成。 使用 --yes 参数将确认你希望删除资源,不会再通过其他提示进行询问。

az group delete --name myResourceGroup --yes --no-wait

后续步骤