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

快速入门:创建 Azure Data Lake Storage Gen2 存储帐户Quickstart: Create an Azure Data Lake Storage Gen2 storage account

Azure Data Lake Storage Gen2 支持分层命名空间,该命名空间提供了一个适合与 Hadoop 分布式文件系统 (HDFS) 配合使用的基于本机目录的文件系统。Azure Data Lake Storage Gen2 supports a hierarchical namespace which provides a native directory-based file system tailored to work with the Hadoop Distributed File System (HDFS). 可以通过 ABFS 驱动程序从 HDFS 访问 Data Lake Storage Gen2 数据。Access to Data Lake Storage Gen2 data from the HDFS is available through the ABFS driver.

本快速入门展示了如何使用 Azure 门户Azure PowerShell 或通过 Azure CLI 创建帐户。This quickstart demonstrates how to create an account using the Azure portal, Azure PowerShell, or via the Azure CLI.

先决条件Prerequisites

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

先决条件Prerequisite
门户Portal None
PowerShellPowerShell 本快速入门需要 PowerShell 模块 Az.Storage 0.7 或更高版本 。This quickstart requires the PowerShell module Az.Storage version 0.7 or later. 若要查找当前版本,请运行 Get-Module -ListAvailable Az.Storage 命令。To find your current version, run the Get-Module -ListAvailable Az.Storage command. 如果在运行此命令后,没有显示任何结果,或者如果出现 0.7 以外的版本,则必须升级 powershell 模块 。If after you run this command, no results appear, or if a version other than 0.7 appears, then you'll have to upgrade your powershell module. 请参阅本指南的升级 powershell 模块部分。See the Upgrade your powershell module section of this guide.
CLICLI 可以登录到 Azure,然后采用以下两种方式之一运行 Azure CLI 命令:You can sign in to Azure and run Azure CLI commands in one of two ways:
  • 可以在 Azure 门户的 Azure Cloud Shell 中运行 CLI 命令You can run CLI commands from within the Azure portal, in Azure Cloud Shell
  • 可以安装 CLI 并在本地运行 CLI 命令You can install the CLI and run CLI commands locally

使用命令行时,可以运行 Azure Cloud shell,也可以在本地安装 CLI。When working on the command line you have the option of running the Azure Cloud shell or installing the CLI locally.

使用 Azure Cloud ShellUse Azure Cloud Shell

Azure Cloud Shell 是可直接在 Azure 门户中运行的免费 Bash shell。Azure Cloud Shell is a free Bash shell that you can run directly within the Azure portal. 它预安装有 Azure CLI 并将其配置为与帐户一起使用。It has the Azure CLI preinstalled and configured to use with your account. 单击 Azure 门户右上角菜单上的“Cloud Shell” 按钮:Click the Cloud Shell button on the menu in the upper-right of the Azure portal:

Cloud ShellCloud Shell

该按钮会启动交互式 shell,用于运行本快速入门中的步骤:The button launches an interactive shell that you can use to run the steps in this quickstart:

显示门户中 Cloud Shell 窗口的屏幕截图Screenshot showing the Cloud Shell window in the portal

在本地安装 CLIInstall the CLI locally

也可在本地安装和使用 Azure CLI。You can also install and use the Azure CLI locally. 本快速入门需要运行 Azure CLI 2.0.38 或更高版本。This quickstart requires that you are running the Azure CLI version 2.0.38 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如需进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install the Azure CLI.

创建启用了 Azure Data Lake Storage Gen2 的存储帐户Create a storage account with Azure Data Lake Storage Gen2 enabled

在创建帐户前,首先创建一个资源组,使其充当你创建的存储帐户或任何其他 Azure 资源的逻辑容器。Before you create an account, you first create a resource group that acts as a logical container to storage accounts or any other Azure resources you create. 若要清理本快速入门创建的资源,可以直接删除资源组。If you wish to clean up the resources created by this quickstart, you can simply delete the resource group. 删除资源组也会删除相关联的存储帐户,以及与资源组相关联的任何其他资源。Deleting the resource group also deletes the associated storage account, and any other resources associated with the resource group. 有关资源组的详细信息,请参阅 Azure 资源管理器概述For more information regarding resource groups, see Azure Resource Manager overview.

备注

必须将新的存储帐户创建为 StorageV2(常规用途 v2 ) 类型才能利用 Data Lake Storage Gen2 功能。You must create new storage accounts as type StorageV2 (general-purpose V2) to take advantage of Data Lake Storage Gen2 features.

有关存储帐户的详细信息,请参阅 Azure 存储帐户概述For more information about storage accounts, see Azure Storage account overview.

为存储帐户命名时,请记住以下规则:When naming your storage account, keep these rules in mind:

  • 存储帐户名称必须为 3 到 24 个字符,并且只能包含数字和小写字母。Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only.
  • 存储帐户名称在 Azure 中必须是唯一的。Your storage account name must be unique within Azure. 没有两个存储帐户可以有相同的名称。No two storage accounts can have the same name.

使用 Azure 门户创建帐户Create an account using the Azure portal

登录到 Azure 门户Sign in to the Azure portal.

创建资源组Create a resource group

若要在 Azure 门户中创建资源组,请执行以下步骤:To create a resource group in the Azure portal, follow these steps:

  1. 在 Azure 门户中展开左侧的菜单,打开服务菜单,然后选择“资源组”。 In the Azure portal, expand the menu on the left side to open the menu of services, and choose Resource Groups.

  2. 单击“添加”按钮添加新的资源组。Click the Add button to add a new resource group.

  3. 输入新资源组的名称。Enter a name for the new resource group.

  4. 选择要在其中创建新资源组的订阅。Select the subscription in which to create the new resource group.

  5. 选择资源组的位置。Choose the location for the resource group.

  6. 单击“创建” 按钮。Click the Create button.

    显示 Azure 门户中资源组创建情况的屏幕截图

创建常规用途 v2 存储帐户Create a general-purpose v2 storage account

若要在 Azure 门户中创建常规用途 v2 存储帐户,请执行以下步骤:To create a general-purpose v2 storage account in the Azure portal, follow these steps:

备注

分层命名空间目前在所有公共区域中提供。The hierarchical namespace is currently available in all public regions.

  1. 在 Azure 门户中展开左侧的菜单,打开服务菜单,然后选择“所有服务”。 In the Azure portal, expand the menu on the left side to open the menu of services, and choose All services. 然后向下滚动到“存储” ,接着选择“存储帐户” 。Then, scroll down to Storage, and choose Storage accounts. 在显示的“存储帐户”窗口中,选择“添加”。 On the Storage Accounts window that appears, choose Add.

  2. 选择之前创建的订阅和资源组 。Select your Subscription and the Resource group you created earlier.

  3. 输入存储帐户的名称。Enter a name for your storage account.

  4. 将“位置” 设置为“美国西部 2”。 Set Location to West US 2

  5. 将这些字段设置为其默认值:性能、帐户类型、复制、访问层 。Leave these fields set to their defaults: Performance, Account kind, Replication, Access tier.

  6. 选择要在其中创建存储帐户的订阅。Choose the subscription in which you want to create the storage account.

  7. 选择“下一步: 高级 >”Select Next : Advanced >

  8. 将“SECURITY”和“VIRTUAL NETWORKS”字段下的值设置为默认值 。Leave the values under SECURITY and VIRTUAL NETWORKS fields set to their defaults.

  9. 在“Data Lake Storage Gen2” 部分中,将“分层命名空间”设置为“已启用”。 In the Data Lake Storage Gen2 section set Hierarchical namespace to Enabled.

  10. 单击“查看 + 创建”以创建存储帐户 。Click Review + Create to create the storage account.

    显示 Azure 门户中存储帐户创建情况的屏幕截图

现在已通过门户创建了存储帐户。Your storage account is now created through the portal.

清理资源Clean up resources

若要使用 Azure 门户删除资源组,请执行以下操作:To remove a resource group using the Azure portal:

  1. 在 Azure 门户中展开左侧的菜单,打开服务菜单,然后选择“资源组”以显示资源组的列表。 In the Azure portal, expand the menu on the left side to open the menu of services, and choose Resource Groups to display the list of your resource groups.
  2. 找到要删除的资源组,右键单击列表右侧的“更多”按钮 ( ... )。 Locate the resource group to delete, and right-click the More button (...) on the right side of the listing.
  3. 选择“删除资源组”并进行确认。 Select Delete resource group, and confirm.

使用 PowerShell 创建帐户Create an account using PowerShell

首先,安装最新版本的 PowerShellGet 模块。First, install the latest version of the PowerShellGet module.

然后,升级 powershell 模块,登录到 Azure 订阅,创建资源组,然后创建存储帐户。Then, upgrade your powershell module, sign in to your Azure subscription, create a resource group, and then create a storage account.

升级 powershell 模块Upgrade your powershell module

备注

本文进行了更新,以便使用新的 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.

若要使用 PowerShell 与 Data Lake Storage Gen2 交互,需要安装模块 Az.Storage 0.7 或更高版本 。To interact with Data Lake Storage Gen2 by using PowerShell, you'll need to install module Az.Storage version 0.7 or later.

首先使用提升的权限打开 PowerShell 会话。Start by opening a PowerShell session with elevated permissions.

安装 Az.Storage 模块Install the Az.Storage module

Install-Module Az.Storage -Repository PSGallery -AllowPrerelease -AllowClobber -Force

登录到 Azure 订阅Sign in to your Azure Subscription

使用 Login-AzAccount 命令并按照屏幕上的说明进行身份验证。Use the Login-AzAccount command and follow the on-screen directions to authenticate.

Login-AzAccount

创建资源组Create a resource group

若要通过 PowerShell 创建新的资源组,请使用 New-AzResourceGroup 命令:To create a new resource group with PowerShell, use the New-AzResourceGroup command:

备注

分层命名空间目前在所有公共区域中提供。The hierarchical namespace is currently available in all public regions.

# put resource group in a variable so you can use the same group name going forward,
# without hardcoding it repeatedly
$resourceGroup = "storage-quickstart-resource-group"
$location = "westus2"
New-AzResourceGroup -Name $resourceGroup -Location $location

创建常规用途 v2 存储帐户Create a general-purpose v2 storage account

若要使用本地冗余存储 (LRS) 从 PowerShell 创建常规用途 v2 存储帐户,请使用 New-AzStorageAccount 命令:To create a general-purpose v2 storage account from PowerShell with locally-redundant storage (LRS), use the New-AzStorageAccount command:

$location = "westus2"

New-AzStorageAccount -ResourceGroupName $resourceGroup `
  -Name "storagequickstart" `
  -Location $location `
  -SkuName Standard_LRS `
  -Kind StorageV2 `
  -EnableHierarchicalNamespace $True

清理资源Clean up resources

若要删除资源组及其关联的资源(包括新的存储帐户),请使用 Remove-AzResourceGroup 命令:To remove the resource group and its associated resources, including the new storage account, use the Remove-AzResourceGroup command:

Remove-AzResourceGroup -Name $resourceGroup

使用 Azure CLI 创建帐户Create an account using Azure CLI

若要启动 Azure Cloud Shell,请登录到 Azure 门户To start Azure Cloud Shell, sign in to the Azure portal.

若要登录到本地安装的 CLI,请运行登录命令:If you want to sign in to your local installation of the CLI, run the login command:

az login

为 Azure Data Lake Gen 2 添加 CLI 扩展Add the CLI extension for Azure Data Lake Gen 2

若要使用 CLI 来与 Data Lake Storage Gen2 交互,必须将扩展添加到 shell。To interact with Data Lake Storage Gen2 by using the CLI, you'll have to add an extension to your shell.

为此,请使用 Cloud Shell 或本地 shell 输入以下命令:az extension add --name storage-previewTo do that, enter the following command by using either the Cloud Shell or a local shell: az extension add --name storage-preview

创建资源组Create a resource group

若要通过 Azure CLI 创建新的资源组,请使用 az group create 命令。To create a new resource group with Azure CLI, use the az group create command.

az group create `
    --name storage-quickstart-resource-group `
    --location westus2

备注

分层命名空间目前在所有公共区域中提供。The hierarchical namespace is currently available in all public regions.

创建常规用途 v2 存储帐户Create a general-purpose v2 storage account

若要使用本地冗余存储从 Azure CLI 创建常规用途 v2 存储帐户,请使用 az storage account create 命令。To create a general-purpose v2 storage account from the Azure CLI with locally-redundant storage, use the az storage account create command.

az storage account create `
    --name storagequickstart `
    --resource-group storage-quickstart-resource-group `
    --location westus2 `
    --sku Standard_LRS `
    --kind StorageV2 `
    --hierarchical-namespace true

清理资源Clean up resources

若要删除资源组及其关联的资源(包括新的存储帐户),请使用 az group delete 命令。To remove the resource group and its associated resources, including the new storage account, use the az group delete command.

az group delete --name myResourceGroup

后续步骤Next steps

在本快速入门中,你已创建了一个具有 Data Lake Storage Gen2 功能的存储帐户。In this quickstart, you've created a storage account with Data Lake Storage Gen2 capabilities. 若要了解如何通过存储帐户上传和下载 Blob,请参阅以下主题。To learn how to upload and download blobs to and from your storage account, see the following topic.