8.3. 从通用虚拟机准备 Azure 镜像版本


要从通用虚拟机创建可重复使用的 Azure 镜像版本,您必须首先创建一个资源组来组织相关资源,如计算、网络和存储。在这个资源组中,设置一个 Azure Compute Gallery 来管理并跨机构共享镜像。在 gallery 中定义镜像定义,以对镜像进行逻辑分组并指定其属性和要求。基于这些镜像定义,您可以创建多个镜像版本以实现一致性和可扩展性。

使用镜像版本,您可以创建同一镜像的副本和多个版本。使用 Azure Compute Gallery,您可以创建一个市场兼容的自定义镜像来跨机构共享。您可以使用 Azure CLI 或 Azure Cloud Shell。有关 Azure Cloud Shell 的详情,请参阅开始使用 Azure Cloud Shell

先决条件

流程

  1. 创建用于托管 gallery 的资源组:

    $ az group create --name <example_image_resource_group>
  2. 在以上资源组中创建 gallery:

    $ az sig create --resource-group <example_image_resource_group> \
    --gallery-name <example_image_gallery_name>
  3. 为订阅将安全类型设置为 Standard

    $ az feature register --name UseStandardSecurityType \
    --namespace Microsoft.Compute
  4. 注册供应商:

    $ az provider register --namespace Microsoft.Compute
  5. 创建镜像定义来管理镜像版本:

    $ az sig image-definition create --resource-group <example_image_resource_group> \
    --gallery-name <example_image_gallery_name> \
    --gallery-image-definition <example_image_definition> \
    --publisher <example_publisher> \
    --offer <example_offer> \
    --sku <example_sky> \
    --os-type Linux \
    --os-state Generalized \
    --hyper-v-generation V2 \
    --features SecurityType=Standard
    <publisher>
    提供镜像的实体或机构。
    <offer>
    来自发布者的相关镜像集合。
    <stock Keeping Unit (SKU)>
    提供的版本,表示主版本。
    <VERSION>
    给定 SKU 的版本号。
  6. 获取有关镜像的信息:

    $ az vm list --output table
  7. 使用输出中的常规镜像名称:

    $ az vm get-instance-view --resource-group <example_vm_resource_group> \
    --name <example_vm_name> \
    --query id
  8. 从输出中复制镜像定义的 ID。
  9. 使用上一步中获取的镜像 ID 创建镜像版本:

    $ az sig image-version create \
    --resource-group <example_image_resource_group> \
    --gallery-name <example_image_gallery_name> \
    --gallery-image-definition <example_image_definition> \
    --gallery-image-version <example_version> \
    --virtual-machine <example_id>
  10. 可选:删除虚拟机和相关资源:

    $ az vm delete --resource-group <example_image_resource_group> \
    --name <example_vm_name>
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部