您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:将 Azure 存储帐户与 Azure CDN 集成Quickstart: Integrate an Azure storage account with Azure CDN

在此快速入门中,你将启用 Azure 内容分发网络 (CDN) 来缓存 Azure 存储中的内容。In this quickstart, you enable Azure Content Delivery Network (CDN) to cache content from Azure storage. Azure CDN 为开发人员提供了一个用于交付高带宽内容的全局解决方案。Azure CDN offers developers a global solution for delivering high-bandwidth content. 它可以在遍布美国、欧洲、亚洲、澳大利亚和南美洲的众多物理节点上缓存 blob 和计算实例的静态内容。It can cache blobs and static content of compute instances at physical nodes in the United States, Europe, Asia, Australia, and South America.

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

登录到 Azure 门户Log in to the Azure portal

使用 Azure 帐户登录到 Azure 门户Log in to the Azure portal with your Azure account.

创建存储帐户Create a storage account

使用以下过程为 Azure 订阅创建新的存储帐户。Use the following procedure to create a new storage account for an Azure subscription. 通过存储帐户可访问 Azure 存储服务。A storage account gives access to Azure Storage services. 存储帐户表示用于访问每个 Azure 存储器服务组件的最高级别的命名空间:Azure Blob、队列和表存储。The storage account represents the highest level of the namespace for accessing each of the Azure Storage service components: Azure Blob, Queue, and Table storage. 有关详细信息,请参阅 Microsoft Azure 存储简介For more information, see Introduction to Microsoft Azure Storage.

要创建存储帐户,必须是相关订阅的服务管理员或联合管理员。To create a storage account, you must be either the service administrator or a coadministrator for the associated subscription.

可使用多种方法创建存储帐户,包括 Azure 门户和 PowerShell。You can use several methods to create a storage account, including the Azure portal and PowerShell. 此快速入门演示了如何使用 Azure 门户。This quickstart demonstrates how to use the Azure portal.

为 Azure 订阅创建存储帐户To create a storage account for an Azure subscription

  1. 在 Azure 门户的左上角,选择“创建资源”。 In the Azure portal, in the upper left, select Create a resource.

    此时会显示“新建”窗格。 The New pane appears.

  2. 选择“存储”,然后选择“存储帐户 - Blob、文件、表、队列” 。Select Storage, then select Storage account - blob, file, table, queue.

    选择存储资源

    此时会显示“创建存储帐户”窗格 。The Create storage account pane appears.

    “创建存储帐户”窗格

  3. 在“名称”框中,输入子域名称 。In the Name box, enter a subdomain name. 此条目可包含 3-24 个小写字母和数字。This entry can contain 3-24 lowercase letters and numbers.

    此值会成为用于对订阅的 Blob、队列或表资源进行寻址的 URI 中的主机名。This value becomes the host name within the URI that's used to address blob, queue, or table resources for the subscription. 要在 Blob 存储中对容器资源进行寻址,请使用以下格式的 URI:To address a container resource in Blob storage, use a URI in the following format:

    http:// <StorageAcountLabel> .blob.core.windows.net/ <mycontainer>http://<StorageAcountLabel>.blob.core.windows.net/<mycontainer>

    其中,<StorageAccountLabel> 引用在“名称”框中输入的值 。where <StorageAccountLabel> refers to the value you entered in the Name box.

    重要

    该 URL 标签构成存储帐户 URI 的子域,在 Azure 中的所有托管服务中必须是唯一的。The URL label forms the subdomain of the storage account URI and must be unique among all hosted services in Azure.

    此值还用作门户中存储帐户的名称,或者以编程方式访问此帐户时的名称。This value is also used as the name of the storage account in the portal or when you're accessing this account programmatically.

  4. 对于其余设置,请使用下表中指定的值:For the remainder of the settings, use the values specified in the following table:

    设置Setting Value
    部署模型Deployment model 使用默认值。Use the default value.
    帐户种类Account kind 使用默认值。Use the default value.
    位置Location 从下拉列表中选择“美国中部”。 Select Central US from the drop-down list.
    复制Replication 使用默认值。Use the default value.
    性能Performance 使用默认值。Use the default value.
    需要安全传输Secure transfer required 使用默认值。Use the default value.
    订阅Subscription 从下拉列表中选择一个 Azure 订阅。Select an Azure subscription from the drop-down list.
    资源组Resource group 选择“新建”,然后输入 my-resource-group-123 作为资源组名称。 Select Create new and enter my-resource-group-123 for your resource group name. 该名称必须全局唯一。This name must be globally unique. 如果它已被使用,可以输入一个不同的名称,也可以选择“使用现有” 并从下拉列表中选择 my-resource-group-123If it is already in use, you may enter a different name or you can select Use existing and select my-resource-group-123 from the drop-down list.
    有关资源组的信息,请参阅 Azure 资源管理器概述For information about resource groups, see Azure Resource Manager overview.
    配置虚拟网络Configure virtual networks 使用默认值。Use the default value.
  5. 选择“固定到仪表板” ,以便在创建存储帐户后将其保存到仪表板。Select Pin to dashboard to save the storage account to your dashboard after it is created.

  6. 选择“创建” 。Select Create. 创建存储帐户可能需要几分钟时间才能完成。Creating the storage account might take several minutes to finish.

为存储帐户启用 Azure CDNEnable Azure CDN for the storage account

可以直接从存储帐户中为存储帐户启用 Azure CDN。You can enable Azure CDN for your storage account directly from your storage account. 若要为 CDN 终结点指定高级配置设置(例如大文件下载优化),可以改用 Azure CDN 扩展来创建 CDN 配置文件和终结点。If you want to specify advanced configuration settings for your CDN endpoint, such as large file download optimization, you can instead use the Azure CDN extension to create a CDN profile and endpoint.

  1. 从仪表板中选择一个存储帐户,然后从左窗格中选择“Azure CDN” 。Select a storage account from the dashboard, then select Azure CDN from the left pane. 如果未立即显示“Azure CDN”按钮,可在左窗格的“搜索”框中输入 CDN 来查找它 。If the Azure CDN button is not immediately visible, you can enter CDN in the Search box of the left pane to find it.

    “Azure CDN”页面随即显示。 The Azure CDN page appears.

    创建 CDN 终结点

  2. 输入下表中指定的必需信息来创建新的终结点:Create a new endpoint by entering the required information specified in the following table:

    设置Setting Value
    CDN 配置文件CDN profile 选择“新建” 并输入配置文件名称,例如“my-cdn-profile-123” 。Select Create new and enter your profile name, for example, my-cdn-profile-123. 该名称必须全局唯一。This name must be globally unique.
    定价层Pricing tier 从下拉列表中选择“标准 Verizon”。 Select Standard Verizon from the drop-down list.
    CDN 终结点名称CDN endpoint name 输入终结点主机名,即 my-endpoint-123Enter your endpoint hostname, i.e. my-endpoint-123. 该名称必须全局唯一。This name must be globally unique. 此名称用于访问在域 <终结点名称> .azureedge.net 中缓存的资源。This name is used to access your cached resources at the domain <endpoint name>.azureedge.net.
    源服务器主机名Origin hostname 默认情况下,新的 CDN 终结点使用存储帐户的主机名作为源服务器。By default, a new CDN endpoint uses the hostname of your storage account as the origin server.
  3. 选择“创建” 。Select Create. 创建终结点之后,它会出现在终结点列表中。After the endpoint is created, it appears in the endpoint list.

    存储新的 CDN 终结点

启用其他 CDN 功能Enable additional CDN features

在存储帐户的“Azure CDN”页面中,从列表中选择 CDN 终结点以打开 CDN 终结点配置页面 。From the storage account Azure CDN page, select the CDN endpoint from the list to open the CDN endpoint configuration page. 从此页面中,可以为交付内容启用其他 CDN 功能,例如压缩查询字符串缓存地区筛选From this page, you can enable additional CDN features for your delivery, such as compression, query string caching, and geo filtering.

存储 CDN 终结点配置

启用 SASEnable SAS

如果希望授予受限制的私有存储容器访问权限,可以使用 Azure 存储帐户的共享访问签名 (SAS) 功能。If you want to grant limited access to private storage containers, you can use the Shared Access Signature (SAS) feature of your Azure storage account. SAS 是授予对 Azure 存储资源进行有限访问权限的 URI,而无需公开你的帐户密钥。A SAS is a URI that grants restricted access rights to your Azure Storage resources without exposing your account key. 有关详细信息,请参阅将 Azure CDN 与 SAS 一起使用For more information, see Using Azure CDN with SAS.

访问 CDN 内容Access CDN content

若要访问 CDN 上的缓存内容,请使用门户中提供的 CDN URL。To access cached content on the CDN, use the CDN URL provided in the portal. 缓存 blob 的地址采用以下格式:The address for a cached blob has the following format:

http://<EndpointName>.azureedge.net/<myPublicContainer>/<BlobName>http://<EndpointName>.azureedge.net/<myPublicContainer>/<BlobName>

备注

启用对存储帐户的 Azure CDN 访问之后,所有公开可用的对象即有资格获得 CDN POP 缓存。After you enable Azure CDN access to a storage account, all publicly available objects are eligible for CDN POP caching. 如果修改了当前缓存在 CDN 中的对象,则除非 Azure CDN 在缓存内容的生存时间到期后刷新其内容,否则无法通过 Azure CDN 访问新内容。If you modify an object that's currently cached in the CDN, the new content will not be available via Azure CDN until Azure CDN refreshes its content after the time-to-live period for the cached content expires.

删除 CDN 中的内容Remove content from Azure CDN

如果不再需要在 Azure CDN 中缓存对象,则可以执行以下步骤之一:If you no longer want to cache an object in Azure CDN, you can take one of the following steps:

  • 将容器设为专用容器而不是公用容器。Make the container private instead of public. 有关详细信息,请参阅管理对容器和 Blob 的匿名读取访问For more information, see Manage anonymous read access to containers and blobs.
  • 通过 Azure 门户禁用或删除 CDN 终结点。Disable or delete the CDN endpoint by using the Azure portal.
  • 将托管服务修改为不再响应此对象的请求。Modify your hosted service to no longer respond to requests for the object.

已在 Azure CDN 中缓存的对象保持缓存状态,直至对象的生存时间到期,或直至清除终结点为止。An object that's already cached in Azure CDN remains cached until the time-to-live period for the object expires or until the endpoint is purged. 当生存时间到期时,Azure CDN 会确定 CDN 终结点是否仍有效,以及是否仍可对该对象进行匿名访问。When the time-to-live period expires, Azure CDN determines whether the CDN endpoint is still valid and the object is still anonymously accessible. 如果不能,则不再缓存该对象。If they are not, the object will no longer be cached.

清理资源Clean up resources

在前面的步骤中,在资源组中创建了 CDN 配置文件和终结点。In the preceding steps, you created a CDN profile and an endpoint in a resource group. 若要转到后续步骤,以便了解如何向终结点添加自定义域,请保存这些资源。Save these resources if you want to go to Next steps and learn how to add a custom domain to your endpoint. 但是,如果认为将来不需要这些资源,可以通过删除资源组来删除它们,避免额外付费:However, if you don't expect to use these resources in the future, you can delete them by deleting the resource group, thus avoiding additional charges:

  1. 在 Azure 门户的左侧菜单中,选择“资源组” ,然后选择“my-resource-group-123” 。From the left-hand menu in the Azure portal, select Resource groups and then select my-resource-group-123.

  2. 在“资源组”页上选择“删除资源组”,在文本框中输入 my-resource-group-123,然后选择“删除”。 On the Resource group page, select Delete resource group, enter my-resource-group-123 in the text box, then select Delete.

    此操作会删除在本快速入门中创建的资源组、配置文件和终结点。This action will delete the resource group, profile, and endpoint that you created in this quickstart.

  3. 若要删除存储帐户,请从仪表板中选择它,然后从顶部的菜单中选择“删除”。 To delete your storage account, select it from the dashboard, then select Delete from the top menu.

后续步骤Next steps

若要了解如何在 CDN 终结点上添加自定义域和启用 HTTPS,请参阅以下教程:To learn about adding a custom domain and enable HTTPS on your CDN endpoint, see the following tutorial: