使用 PowerShell 管理 Azure 独立云中的存储Managing Storage in the Azure independent clouds using PowerShell

大多数人为其全球 Azure 部署使用了 Azure 公有云。Most people use Azure Public Cloud for their global Azure deployment. 但出于主权等方面的原因,还存在一些独立的 Azure 部署。There are also some independent deployments of Azure for reasons of sovereignty and so on. 这些独立部署称为“环境”。These independent deployments are referred to as "environments." 以下列表详细说明了当前存在的独立云。The following list details the independent clouds currently available.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

使用独立云Using an independent cloud

若要在某个独立云中使用 Azure 存储,需要连接到该云而不是 Azure 公有云。To use Azure Storage in one of the independent clouds, you connect to that cloud instead of Azure Public. 若要使用某个独立云而不是 Azure 公有云,需要:To use one of the independent clouds rather than Azure Public:

  • 指定要连接到的环境。You specify the environment to which to connect.
  • 确定并使用可用的区域。You determine and use the available regions.
  • 使用正确的终结点后缀,它不同于 Azure 公有云。You use the correct endpoint suffix, which is different from Azure Public.

本文中的示例需要 Azure PowerShell 模块 Az 版本 0.7 或更高版本。The examples require Azure PowerShell module Az version 0.7 or later. 在 PowerShell 窗口中,运行 Get-Module -ListAvailable Az 可查找版本。In a PowerShell window, run Get-Module -ListAvailable Az to find the version. 如果未列出任何信息或需要升级,请参阅安装 Azure PowerShell 模块If nothing is listed, or you need to upgrade, see Install Azure PowerShell module.

登录 AzureLog in to Azure

运行 Get-AzEnvironment cmdlet 以查看可用的 Azure 环境:Run the Get-AzEnvironment cmdlet to see the available Azure environments:

Get-AzEnvironment

登录到有权访问所要连接的云的帐户,并设置环境。Sign in to your account that has access to the cloud to which you want to connect and set the environment. 此示例演示如何登录到使用 Azure 中国云的帐户。This example shows how to sign into an account that uses the Azure China Cloud.

Connect-AzAccount –Environment AzureChinaCloud

此时,如果需要查看可在其中创建存储帐户或其他资源的位置列表,可以使用 Get-AzLocation 查询所选云可用的位置。At this point, if you need the list of locations to create a storage account or another resource, you can query the locations available for the selected cloud using Get-AzLocation.

Get-AzLocation | select Location, DisplayName

下表显示了针对中国云返回的位置。The following table shows the locations returned for the China cloud.

位置Location 显示名称Display Name
chinaeastchinaeast 中国东部China East
chinaeast 2chinaeast 2 中国东部 2China East 2
chinanorthchinanorth 中国北部China North
chinanorth 2chinanorth 2 中国北部 2China North 2

终结点后缀Endpoint suffix

其中每个环境的终结点后缀不同于 Azure 公有云终结点。The endpoint suffix for each of these environments is different from the Azure Public endpoint. 例如,Azure 公有云的 Blob 终结点后缀为 blob.core.windows.netFor example, the blob endpoint suffix for Azure Public is blob.core.windows.net. 对于中国云,Blob 终结点后缀为 blob.core.chinacloudapi.cnFor the China Cloud, the blob endpoint suffix is blob.core.chinacloudapi.cn.

使用 Get-AzEnvironment 获取终结点Get endpoint using Get-AzEnvironment

使用 Get-AzEnvironment 检索终结点后缀。Retrieve the endpoint suffix using Get-AzEnvironment. 终结点是环境的 StorageEndpointSuffix 属性。The endpoint is the StorageEndpointSuffix property of the environment.

下面的代码片段演示如何检索终结点后缀。The following code snippets show how to retrieve the endpoint suffix. 所有这些命令返回类似于“core.chinacloudapi.cn”的内容。All of these commands return something like "core.chinacloudapi.cn". 将此后缀追加到存储服务即可访问该服务。Append the suffix to the storage service to access that service. 例如,追加“queue.core.chinacloudapi.cn”可访问中国云中的队列服务。For example, "queue.core.chinacloudapi.cn" will access the queue service in China Cloud.

此代码片段检索所有环境,以及每个环境的终结点后缀。This code snippet retrieves all of the environments and the endpoint suffix for each one.

Get-AzEnvironment | select Name, StorageEndpointSuffix 

此命令返回以下结果。This command returns the following results.

名称Name core.usgovcloudapi.netStorageEndpointSuffix
AzureChinaCloudAzureChinaCloud core.chinacloudapi.cncore.chinacloudapi.cn
AzureCloudAzureCloud core.windows.netcore.windows.net
AzureGermanCloudAzureGermanCloud core.cloudapi.decore.cloudapi.de
AzureUSGovernmentAzureUSGovernment core.usgovcloudapi.netcore.usgovcloudapi.net

若要检索指定环境的所有属性,请调用 Get-AzEnvironment 并指定云名称。To retrieve all of the properties for the specified environment, call Get-AzEnvironment and specify the cloud name. 此代码片段返回属性列表;请在列表中查找 StorageEndpointSuffixThis code snippet returns a list of properties; look for StorageEndpointSuffix in the list. 以下示例适用于中国云。The following example is for the China Cloud.

Get-AzEnvironment -Name AzureChinaCloud 

结果类似于以下值:The results are similar to the following values:

|属性名称Property Name|ValueValue| |----|----| | 名称Name | AzureChinaCloud | | EnableAdfsAuthenticationEnableAdfsAuthentication | False | | ActiveDirectoryServiceEndpointResourceIActiveDirectoryServiceEndpointResourceI | https://management.core.chinacloudapi.cn/ | | GalleryURLGalleryURL | https://gallery.cloudapi.de/ | | ManagementPortalUrlManagementPortalUrl | https://portal.azure.cn | | ServiceManagementUrlServiceManagementUrl | https://management.core.chinacloudapi.cn/ | | PublishSettingsFileUrlPublishSettingsFileUrl| https://go.microsoft.com/fwlink/?LinkID=301776 | | ResourceManagerUrlResourceManagerUrl | https://management.chinacloudapi.cn/ | | SqlDatabaseDnsSuffixSqlDatabaseDnsSuffix | .database.chinacloudapi.cn | | StorageEndpointSuffixStorageEndpointSuffix | core.chinacloudapi.cn | | ...... | ...... | 若只要检索存储终结点后缀属性,请检索特定的云,并仅请求该属性。To retrieve just the storage endpoint suffix property, retrieve the specific cloud and ask for just that one property.

$environment = Get-AzEnvironment -Name AzureChinaCloud
Write-Host "Storage EndPoint Suffix = " $environment.StorageEndpointSuffix

此命令返回以下信息:This command returns the following information:

Storage Endpoint Suffix = core.chinacloudapi.cn

从存储帐户获取终结点Get endpoint from a storage account

还可以通过检查存储帐户的属性来检索终结点:You can also examine the properties of a storage account to retrieve the endpoints:

# Get a reference to the storage account.
$resourceGroup = "myexistingresourcegroup"
$storageAccountName = "myexistingstorageaccount"
$storageAccount = Get-AzStorageAccount `
  -ResourceGroupName $resourceGroup `
  -Name $storageAccountName 
  # Output the endpoints.
Write-Host "blob endpoint = " $storageAccount.PrimaryEndPoints.Blob 
Write-Host "file endpoint = " $storageAccount.PrimaryEndPoints.File
Write-Host "queue endpoint = " $storageAccount.PrimaryEndPoints.Queue
Write-Host "table endpoint = " $storageAccount.PrimaryEndPoints.Table

对于中国云中的存储帐户,此命令返回以下信息:For a storage account in the China Cloud, this returns the following:

blob endpoint = http://myexistingstorageaccount.blob.core.chinacloudapi.cn/
file endpoint = http://myexistingstorageaccount.file.core.chinacloudapi.cn/
queue endpoint = http://myexistingstorageaccount.queue.core.chinacloudapi.cn/
table endpoint = http://myexistingstorageaccount.table.core.chinacloudapi.cn/

设置环境之后After setting the environment

现在可以使用 PowerShell 来管理存储帐户并访问 blob、队列、文件和表数据。You can now use PowerShell to manage your storage accounts and access blob, queue, file, and table data. 有关详细信息,请参阅 Az.StorageFor more information, see Az.Storage.

清理资源Clean up resources

如果为本练习创建了新的资源组和存储帐户,可以通过删除资源组来删除这两个资产。If you created a new resource group and a storage account for this exercise, you can remove both assets by deleting the resource group. 删除资源组会删除其包含的所有资源。Deleting the resource group deletes all resources contained within the group.

Remove-AzResourceGroup -Name $resourceGroup

后续步骤Next steps