使用门户创建共享映像库Create a Shared Image Gallery using the portal

共享映像库大大简化了整个组织中的自定义映像共享。A Shared Image Gallery simplifies custom image sharing across your organization. 自定义映像类似于市场映像,不同的是自定义映像的创建者是自己。Custom images are like marketplace images, but you create them yourself. 自定义映像可用于启动部署任务,例如预加载应用程序、应用程序配置和其他 OS 配置。Custom images can be used to bootstrap deployment tasks like preloading applications, application configurations, and other OS configurations.

使用共享映像库,你可以在 Azure AD 租户内在同一区域或跨区域与组织中的其他用户共享自定义 VM 映像。The Shared Image Gallery lets you share your custom VM images with others in your organization, within or across regions, within an Azure AD tenant. 选择要共享哪些映像,要在哪些区域中共享,以及希望与谁共享它们。Choose which images you want to share, which regions you want to make them available in, and who you want to share them with. 你可以创建多个库,以便可以按逻辑方式对共享映像进行分组。You can create multiple galleries so that you can logically group shared images.

库是顶级资源,它提供完全基于角色的访问控制 (RBAC)。The gallery is a top-level resource that provides full role-based access control (RBAC). 你可以控制映像的版本,并且可以选择将每个映像版本复制到一组不同的 Azure 区域。Images can be versioned, and you can choose to replicate each image version to a different set of Azure regions. 库仅适用于托管映像。The gallery only works with Managed Images.

共享映像库功能具有多种资源类型。The Shared Image Gallery feature has multiple resource types. 我们将在本文中使用或生成这些资源类型:We will be using or building these in this article:

资源Resource 说明Description
映像源Image source 这是可用于在映像库中创建“映像版本”的资源 。This is a resource that can be used to create an image version in an image gallery. 映像源可以是现有的 Azure VM(可以是通用或专用的)、托管映像、快照或其他映像库中的映像版本。An image source can be an existing Azure VM that is either generalized or specialized, a managed image, a snapshot, or an image version in another image gallery.
映像库Image gallery 与 Azure 市场一样,映像库是用于管理和共享映像的存储库,但你可以控制谁有权访问这些映像。Like the Azure Marketplace, an image gallery is a repository for managing and sharing images, but you control who has access.
映像定义Image definition 映像定义在库中创建,携带有关该映像以及在内部使用该映像的要求的信息。Image definitions are created within a gallery and carry information about the image and requirements for using it internally. 这包括了该映像是 Windows 还是 Linux 映像、发行说明以及最低和最高内存要求。This includes whether the image is Windows or Linux, release notes, and minimum and maximum memory requirements. 它是某种映像类型的定义。It is a definition of a type of image.
映像版本Image version 使用库时,将使用映像版本来创建 VM。An image version is what you use to create a VM when using a gallery. 可根据环境的需要创建多个映像版本。You can have multiple versions of an image as needed for your environment. 与托管映像一样,在使用映像版本创建 VM 时,将使用映像版本来创建 VM 的新磁盘。Like a managed image, when you use an image version to create a VM, the image version is used to create new disks for the VM. 可以多次使用映像版本。Image versions can be used multiple times.

准备阶段Before you begin

若要完成本文中的示例,必须准备好通用化 VM 的现有托管映像,或专用化 VM 的快照。To complete the example in this article, you must have an existing managed image of a generalized VM, or a snapshot of a specialized VM. 可以按照教程:使用 Azure PowerShell 创建 Azure VM 的自定义映像来创建托管映像,或按照创建快照来创建专用化 VM。You can follow Tutorial: Create a custom image of an Azure VM with Azure PowerShell to create a managed image, or Create a snapshot for a specialized VM. 对于托管映像和快照,数据磁盘大小不能超过 1 TB。For both managed images and snapshots, the data disk size cannot be more than 1 TB.

通过本文进行操作时,请根据需要替换资源组和 VM 名称。When working through this article, replace the resource group and VM names where needed.

映像库是用于启用映像共享的主要资源。An image gallery is the primary resource used for enabling image sharing. 允许用于库名称的字符为大写或小写字母、数字、点和句点。Allowed characters for Gallery name are uppercase or lowercase letters, digits, dots, and periods. 库名称不能包含短划线。The gallery name cannot contain dashes. 库名称在你的订阅中必须唯一。Gallery names must be unique within your subscription.

以下示例在“myGalleryRG”资源组中创建名为“myGallery”的库 。The following example creates a gallery named myGallery in the myGalleryRG resource group.

  1. 通过 https://portal.azure.cn 登录到 Azure 门户。Sign in to the Azure portal at https://portal.azure.cn.
  2. 在搜索框中使用“共享映像库”类型,在结果中选择“共享映像库”。 Use the type Shared image gallery in the search box and select Shared image gallery in the results.
  3. 在“共享映像库”页中,单击“添加”。 In the Shared image gallery page, click Add.
  4. 在“创建共享映像库”页上,选择正确的订阅。On the Create shared image gallery page, select the correct subscription.
  5. 在“资源组”中选择“新建”,键入 myGalleryRG 作为名称。 In Resource group, select Create new and type myGalleryRG for the name.
  6. 在“名称”中,键入 myGallery 作为库名称。In Name, type myGallery for the name of the gallery.
  7. 对“区域”保留默认值。Leave the default for Region.
  8. 可以键入库的简短说明,例如“我的映像库,用于测试”。You can type a short description of the gallery, like My image gallery for testing. 然后单击“查看 + 创建”。and then click Review + create.
  9. 通过验证后,选择“创建”。After validation passes, select Create.
  10. 部署完成后,选择“转到资源”。When the deployment is finished, select Go to resource.

创建映像定义Create an image definition

映像定义为映像创建一个逻辑分组。Image definitions create a logical grouping for images. 它们用于管理有关映像版本的信息,这些版本是在其中创建的。They are used to manage information about the image versions that are created within them. 映像定义名称可能包含大写或小写字母、数字、点、短划线和句点。Image definition names can be made up of uppercase or lowercase letters, digits, dots, dashes and periods. 若要详细了解可以为映像定义指定的值,请参阅映像定义For more information about the values you can specify for an image definition, see Image definitions.

在库中创建库映像定义。Create the gallery image definition inside of your gallery. 在本示例中,库映像名为 myImageDefinitionIn this example, the gallery image is named myImageDefinition.

  1. 在新映像库的页面顶部,选择“添加新的映像定义”。On the page for your new image gallery, select Add a new image definition from the top of the page.
  2. 在“向共享映像库添加新的映像定义”中,对于“区域”,选择“中国东部”。In the Add new image definition to shared image gallery, for Region, select China East.
  3. 对于“映像定义名称”,请键入 myImageDefinitionFor Image definition name, type myImageDefinition.
  4. 对于“操作系统”,请根据源 VM 选择正确的选项。For Operating system, select the correct option based on your source VM.
  5. 对于“VM 代系”,请根据源 VM 选择适当的选项。For VM generation, select the option based on your source VM. 大多数情况下都会选择“第 1 代”。In most cases, this will be Gen 1. 有关详细信息,请参阅对第 2 代 VM 的支持For more information, see Support for generation 2 VMs.
  6. 对于“操作系统状态”,请根据源 VM 选择适当的选项。For Operating system state, select the option based on your source VM. 有关详细信息,请参阅通用化和专用化For more information, see Generalized and specialized.
  7. 对于“发布者”,请键入 myPublisherFor Publisher, type myPublisher.
  8. 对于“套餐”,请键入 myOfferFor Offer, type myOffer.
  9. 对于“SKU”,请键入 mySKUFor SKU, type mySKU.
  10. 完成后,选择“查看 + 创建”。When finished, select Review + create.
  11. 映像定义通过验证后,请选择“创建”。After the image definition passes validation, select Create.
  12. 部署完成后,选择“转到资源”。When the deployment is finished, select Go to resource.

创建映像版本Create an image version

从托管映像创建映像版本。Create an image version from a managed image. 在此示例中,映像版本为 1.0.0,该版本被复制到中国北部和中国东部数据中心 。In this example, the image version is 1.0.0 and it's replicated to both China North and China East datacenters. 选择复制的目标区域时,请记住,你还需包括源区域作为复制的目标。When choosing target regions for replication, remember that you also have to include the source region as a target for replication.

允许用于映像版本的字符为数字和句点。Allowed characters for image version are numbers and periods. 数字必须在 32 位整数范围内。Numbers must be within the range of a 32-bit integer. 格式:MajorVersion.MinorVersion.PatchFormat: MajorVersion.MinorVersion.Patch.

创建映像版本的步骤略有不同,具体取决于源是通用化的映像,还是专用化 VM 的快照。The steps for creating an image version are slightly different, depending on whether the source is a generalized image or a snapshot of a specialized VM.

选项:通用Option: Generalized

  1. 在映像定义的页面顶部,选择“添加版本”。In the page for your image definition, select Add version from the top of the page.
  2. 在“区域”中,选择存储托管映像的区域。In Region, select the region where your managed image is stored. 需要在映像版本基于的托管映像所在的同一区域中创建映像版本。Image versions need to be created in the same region as the managed image they are created from.
  3. 对于“名称”,请键入 1.0.0For Name, type 1.0.0. 映像版本名称应遵循“主要版本.次要版本.修补版本”格式(使用整数)。 The image version name should follow major.minor.patch format using integers.
  4. 在“源映像”中,从下拉列表中选择源托管映像。In Source image, select your source managed image from the drop-down.
  5. 在“从最新版本中排除”中,保留默认设置“否”。In Exclude from latest, leave the default value of No.
  6. 对于“生命周期终结日期”,请从日历中选择处于未来几个月的某个日期。For End of life date, select a date from the calendar that is a couple of months in the future.
  7. 在“复制”中,将“默认副本计数”保留为 1。 In Replication, leave the Default replica count as 1. 需要复制到源区域,因此,请将第一个副本保留为默认副本,然后选择另一个副本区域“中国东部”。You need to replicate to the source region, so leave the first replica as the default and then pick a second replica region to be China East.
  8. 完成操作后,选择“查看 + 创建”。When you are done, select Review + create. Azure 将验证配置。Azure will validate the configuration.
  9. 映像版本通过验证后,请选择“创建”。When image version passes validation, select Create.
  10. 部署完成后,选择“转到资源”。When the deployment is finished, select Go to resource.

可能需要花费一段时间才能将映像复制到所有目标区域。It can take a while to replicate the image to all of the target regions.

选项:专用Option: Specialized

  1. 在映像定义的页面顶部,选择“添加版本”。In the page for your image definition, select Add version from the top of the page.
  2. 在“区域”中,选择存储快照的区域。In Region, select the region where your snapshot is stored. 需要在映像版本基于的源所在的同一区域中创建映像版本。Image versions need to be created in the same region as the source they are created from.
  3. 对于“名称”,请键入 1.0.0For Name, type 1.0.0. 映像版本名称应遵循“主要版本.次要版本.修补版本”格式(使用整数)。 The image version name should follow major.minor.patch format using integers.
  4. 在“OS 磁盘快照”中,从下拉列表中选择来自源 VM 的快照。In OS disk snapshot, select the snapshot from your source VM from the drop-down. 如果源 VM 有一个要包含的数据磁盘,请从下拉列表中选择正确的“LUN”编号,然后为“数据磁盘快照”选择数据磁盘的快照。 If your source VM had a data disk that you would like to include, select the correct LUN number from the drop-down, and then select the snapshot of the data disk for Data disk snapshot.
  5. 在“从最新版本中排除”中,保留默认设置“否”。In Exclude from latest, leave the default value of No.
  6. 对于“生命周期终结日期”,请从日历中选择处于未来几个月的某个日期。For End of life date, select a date from the calendar that is a couple of months in the future.
  7. 在“复制”中,将“默认副本计数”保留为 1。 In Replication, leave the Default replica count as 1. 需要复制到源区域,因此,请将第一个副本保留为默认副本,然后选择另一个副本区域“中国东部”。You need to replicate to the source region, so leave the first replica as the default and then pick a second replica region to be China East.
  8. 完成操作后,选择“查看 + 创建”。When you are done, select Review + create. Azure 将验证配置。Azure will validate the configuration.
  9. 映像版本通过验证后,请选择“创建”。When image version passes validation, select Create.
  10. 部署完成后,选择“转到资源”。When the deployment is finished, select Go to resource.

我们建议你在映像库级别共享访问权限。We recommend that you share access at the image gallery level. 下面逐步说明如何共享刚刚创建的库。The following walks you through sharing the gallery that you just created.

  1. 打开 Azure 门户Open the Azure portal.
  2. 在左侧菜单中,选择“资源组”。In the menu at the left, select Resource groups.
  3. 在资源组列表中,选择“myGalleryRG”。In the list of resource groups, select myGalleryRG. 此时会打开资源组的边栏选项卡。The blade for your resource group will open.
  4. 在“myGalleryRG”页左侧的菜单中,选择“访问控制(IAM)”。 In the menu on the left of the myGalleryRG page, select Access control (IAM).
  5. 在“添加角色分配”下,选择“添加”。 Under Add a role assignment, select Add. 此时会打开“添加角色分配”窗格。The Add a role assignment pane will open.
  6. 在“角色”下,选择“读取者”。 Under Role, select Reader.
  7. 在“将访问权限分配给”下,保留默认设置“Azure AD 用户、组或服务主体”。 Under assign access to, leave the default of Azure AD user, group, or service principal.
  8. 在“选择”下,键入要邀请的人员的电子邮件地址。Under Select, type in the email address of the person that you would like to invite.
  9. 如果该用户不在你的组织中,将会显示消息“将向此用户发送一封电子邮件,使其能够与 Microsoft 协作”。If the user is outside of your organization, you will see the message This user will be sent an email that enables them to collaborate with Microsoft. 选择具有该电子邮件地址的用户,然后单击“保存”。Select the user with the email address and then click Save.

如果该用户不在你的组织中,他(她)会收到一封邀请加入组织的电子邮件。If the user is outside of your organization, they will get an email invitation to join the organization. 该用户需要接受邀请,才能在其资源列表中看到库以及所有映像定义和版本。The user needs to accept the invitation, then they will be able to see the gallery and all of the image definitions and versions in their list of resources.

创建 VMCreate VMs

现在,可以创建一个或多个新的 VM。Now you can create one or more new VMs. 本示例在“中国东部”数据中心的 myResourceGroup 中创建名为 myVMfromImage 的 VM。This example creates a VM named myVMfromImage, in the myResourceGroup in the China East datacenter.

  1. 转到映像定义。Go to your image definition. 可以使用资源筛选器显示所有可用的映像定义。You can use the resource filter to show all image definitions available.
  2. 在映像定义的页面顶部,从菜单中选择“创建 VM”。On the page for your image definition, select Create VM from the menu at the top of the page.
  3. 对于“资源组”,请选择“新建”并键入 myResourceGroup 作为名称。 For Resource group, select Create new and type myResourceGroup for the name.
  4. 在“虚拟机名称”中键入 myVMIn Virtual machine name, type myVM.
  5. 对于“区域”,请选择“中国东部”。For Region, select China East.
  6. 对于“可用性选项”,请保留默认设置“无需基础结构冗余”。For Availability options, leave the default of No infrastructure redundancy required.
  7. 如果你是从映像定义的页面开始操作的,系统会自动使用 latest 映像版本填充“映像”的值。The value for Image is automatically filled with the latest image version if you started from the page for the image definition.
  8. 对于“大小”,请从可用大小列表中选择一种 VM 大小,然后选择“选择”。 For Size, choose a VM size from the list of available sizes and then choose Select.
  9. 在“管理员帐户”下,如果源 VM 是通用化的,请输入 用户名SSH 公钥Under Administrator account, if the source VM was generalized, enter your Username and SSH public key. 如果源 VM 是专用化的,则这些选项将会灰显,因为系统会使用源 VM 中的信息。If the source VM was specialized, these options will be greyed out because the information from the source VM is used.
  10. 若要允许远程访问 VM,请在“公共入站端口”下选择“允许所选端口”,然后从下拉列表中选择“SSH (22)”。 If you want to allow remote access to the VM, under Public inbound ports, choose Allow selected ports and then select SSH (22) from the drop-down. 如果你不希望允许远程访问 VM,请为“公共入站端口”保留选择“无”。 If you don't want to allow remote access to the VM, leave None selected for Public inbound ports.
  11. 完成后,选择页面底部的“查看 + 创建”按钮。When you are finished, select the Review + create button at the bottom of the page.
  12. VM 通过验证后,选择页面底部的“创建”以开始部署。After the VM passes validation, select Create at the bottom of the page to start the deployment.

清理资源Clean up resources

当不再需要时,可以删除资源组、虚拟机和所有相关资源。When no longer needed, you can delete the resource group, virtual machine, and all related resources. 为此,请选择虚拟机的资源组,选择“删除”,然后确认要删除的资源组的名称。To do so, select the resource group for the virtual machine, select Delete, then confirm the name of the resource group to delete.

若要删除单个资源,需要按相反的顺序删除。If you want to delete individual resources, you need to delete them in reverse order. 例如,若要删除某个映像定义,需要先删除基于该映像创建的所有映像版本。For example, to delete an image definition, you need to delete all of the image versions created from that image.

后续步骤Next steps

此外可以使用模板创建共享映像库资源。You can also 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.