快速入门:通过 Windows 虚拟机创建和管理 Azure 文件共享Quickstart: Create and manage Azure Files share with Windows virtual machines

本文演示创建和使用 Azure 文件存储共享的基本步骤。The article demonstrates the basic steps for creating and using an Azure Files share. 本快速入门重点介绍如何快速设置 Azure 文件存储共享,以便可以体验该服务的工作原理。In this quickstart, the emphasis is on quickly setting up an Azure Files share so you can experience how the service works. 如需有关在自己环境中创建和使用 Azure 文件共享的更多详细说明,请参阅在 Windows 中使用 Azure 文件共享If you need more detailed instructions for creating and using Azure file shares in your own environment, see Use an Azure file share with Windows.

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

登录 AzureSign in to Azure

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

准备环境Prepare your environment

在本快速入门中,请设置以下项目:In this quickstart, you set up the following items:

  • Azure 存储帐户和 Azure 文件共享An Azure storage account and an Azure file share
  • Windows Server 2016 Datacenter VMA Windows Server 2016 Datacenter VM

创建存储帐户Create a storage account

在使用 Azure 文件共享之前,必须创建 Azure 存储帐户。Before you can work with an Azure file share, you have to create an Azure storage account. 可以使用常规用途 v2 存储帐户访问所有 Azure 存储服务:Blob、文件、队列、表。A general-purpose v2 storage account provides access to all of the Azure Storage services: blobs, files, queues, and tables. 本快速入门创建常规用途 v2 存储帐户,但创建任何类型的存储帐户的步骤都相似。The quickstart creates a general-purpose v2 storage account but, the steps to create any type of storage account are similar. 一个存储帐户可以包含无数个共享。A storage account can contain an unlimited number of shares. 一个共享可以存储无数个文件,直至达到存储帐户的容量限制为止。A share can store an unlimited number of files, up to the capacity limits of the storage account.

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

  1. 在 Azure 门户菜单中,选择“所有服务” 。On the Azure portal menu, select All services. 在资源列表中,键入“存储帐户” 。In the list of resources, type Storage Accounts. 开始键入时,会根据输入筛选该列表。As you begin typing, the list filters based on your input. 选择“存储帐户” 。Select Storage Accounts.

  2. 在显示的“存储帐户”窗口中,选择“添加”。 On the Storage Accounts window that appears, choose Add.

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

  4. 在“资源组” 字段下,选择“新建” 。Under the Resource group field, select Create new. 输入新资源组的名称,如下图中所示。Enter a name for your new resource group, as shown in the following image.

    显示如何在门户中创建资源组的屏幕截图

  5. 然后,输入存储帐户的名称。Next, enter a name for your storage account. 所选名称在 Azure 中必须唯一。The name you choose must be unique across Azure. 该名称还必须为 3 到 24 个字符,并且只能包含数字和小写字母。The name also must be between 3 and 24 characters in length, and can include numbers and lowercase letters only.

  6. 选择存储帐户的位置或使用默认位置。Select a location for your storage account, or use the default location.

  7. 将这些字段设置为其默认值:Leave these fields set to their default values:

    字段Field Value
    部署模型Deployment model 资源管理器Resource Manager
    性能Performance StandardStandard
    帐户类型Account kind StorageV2(常规用途 v2)StorageV2 (general-purpose v2)
    复制Replication 读取访问异地冗余存储 (RA-GRS)Read-access geo-redundant storage (RA-GRS)
    访问层Access tier Hot
  8. 如果计划使用 Azure Data Lake Storage,请选择“高级” 选项卡,然后将“分层命名空间” 设置为“启用” 。If you plan to use Azure Data Lake Storage, choose the Advanced tab, and then set Hierarchical namespace to Enabled.

  9. 选择“查看+创建” 可查看存储帐户设置并创建帐户。Select Review + Create to review your storage account settings and create the account.

  10. 选择“创建” 。Select Create.

有关存储帐户类型和其他存储帐户设置的详细信息,请参阅 Azure 存储帐户概述For more information about types of storage accounts and other storage account settings, see Azure storage account overview. 有关资源组的详细信息,请参阅 Azure 资源管理器概述For more information on resource groups, see Azure Resource Manager overview.

创建 Azure 文件共享Create an Azure file share

接下来,创建文件共享。Next, you create a file share.

  1. Azure 存储帐户部署完成后,请选择“转到资源”。 When the Azure storage account deployment is complete, select Go to resource.

  2. 在存储帐户窗格中选择“文件” 。Select Files from the storage account pane.

    选择文件

  3. 选择“文件共享”。 Select File Share.

    选择”添加文件共享”按钮

  4. 将新文件共享命名为 qsfileshare,在“配额”中输入“1”,然后选择“创建”。 Name the new file share qsfileshare > enter "1" for the Quota > select Create. 配额最高可为 5 TiB,但本快速入门只需 1 GiB。The quota can be a maximum of 5 TiB, but you only need 1 GiB for this quickstart.

  5. 在本地计算机上创建名为 qsTestFile 的新 txt 文件。Create a new txt file called qsTestFile on your local machine.

  6. 选择新文件共享,然后在文件共享位置选择“上传”。 Select the new file share, then on the file share location, select Upload.

    上传文件

  7. 浏览到创建 .txt 文件的位置,然后依次选择“qsTestFile.txt”、“上传”。 Browse to the location where you created your .txt file > select qsTestFile.txt > select Upload.

目前已在 Azure 中创建 Azure 存储帐户和包含一个文件的文件共享。So far, you've created an Azure storage account and a file share with one file in it in Azure. 接下来,请创建 Azure VM,其中的 Windows Server 2016 Datacenter 代表本快速入门中的本地服务器。Next you'll create the Azure VM with Windows Server 2016 Datacenter to represent the on-premises server in this quickstart.

部署 VMDeploy a VM

  1. 接下来,请展开 Azure 门户左侧的菜单,然后在左上角选择“创建资源”。 Next, expand the menu on the left side of the portal and choose Create a resource in the upper left-hand corner of the Azure portal.

  2. Azure 市场资源列表上方的搜索框中,搜索并选择“Windows Server 2016 Datacenter”,然后选择“创建” 。In the search box above the list of Azure Marketplace resources, search for and select Windows Server 2016 Datacenter, then choose Create.

  3. 在“基本信息”选项卡的“项目详细信息”下,选择为本快速入门创建的资源组。 In the Basics tab, under Project details, select the resource group you created for this quickstart.

    在门户边栏选项卡中输入 VM 的基本信息

  4. 在“实例详细信息”下,将 VM 命名为 qsVMUnder Instance details, name the VM qsVM.

  5. 保留“区域”、“可用性选项”、“映像”和“大小”的默认设置。 Leave the default settings for Region, Availability options, Image, and Size.

  6. 在“管理员帐户”下,添加 VMadmin 作为用户名,并输入 VM 的密码Under Administrator account, add VMadmin as the Username and enter a Password for the VM.

  7. 在“入站端口规则” 下,选择“允许所选端口” ,然后从下拉列表中选择“RDP (3389)” 和“HTTP” 。Under Inbound port rules, choose Allow selected ports and then select RDP (3389) and HTTP from the drop-down.

  8. 选择“查看 + 创建” 。Select Review + create.

  9. 选择“创建” 。Select Create. 创建新的 VM 需要数分钟才能完成。Creating a new VM will take a few minutes to complete.

  10. VM 部署完成以后,请选择“转到资源”。 Once your VM deployment is complete, select Go to resource.

目前已创建一个新虚拟机并附加一个数据磁盘。At this point, you've created a new virtual machine and attached a data disk. 现在需连接到 VM。Now you need to connect to the VM.

连接到 VMConnect to your VM

  1. 选择虚拟机属性页上的“连接”。 Select Connect on the virtual machine properties page.

    从门户连接到 Azure VM

  2. 在“连接到虚拟机”页中保留默认选项,以使用 IP 地址通过端口号 3389 进行连接,然后选择“下载 RDP 文件”。 In the Connect to virtual machine page, keep the default options to connect by IP address over port number 3389 and select Download RDP file.

  3. 打开下载的 RDP 文件,然后在出现提示时选择“连接” 。Open the downloaded RDP file and select Connect when prompted.

  4. 在“Windows 安全性” 窗口中,依次选择“更多选择” 、“使用其他帐户” 。In the Windows Security window, select More choices and then Use a different account. localhost\username 格式键入用户名,其中,<username> 是为虚拟机创建的 VM 管理员用户名。Type the username as localhost\username, where <username> is the VM admin username you created for the virtual machine. 输入针对虚拟机创建的密码,然后选择“确定”。 Enter the password you created for the virtual machine, and then select OK.

    更多选择

  5. 你可能会在登录过程中收到证书警告。You may receive a certificate warning during the sign-in process. 选择“是”或“继续”以创建连接。 select Yes or Continue to create the connection.

将 Azure 文件共享映射到 Windows 驱动器Map the Azure file share to a Windows drive

  1. 在 Azure 门户中,导航到“qsfileshare”文件共享并选择“连接”。 In the Azure portal, navigate to the qsfileshare fileshare and select Connect.

  2. 复制第二个框中的内容并将其粘贴到记事本中。Copy the contents of the second box and paste it in Notepad.

    Azure 文件“连接”窗格中的 UNC 路径

  3. 在 VM 中打开“文件资源管理器”,并在窗口中选择“此电脑”。 In the VM, open File Explorer and select This PC in the window. 这会更改功能区中的可用菜单。This selection will change the menus available on the ribbon. 在“计算机”菜单中,选择“映射网络驱动器”。 On the Computer menu, select Map network drive.

  4. 选择驱动器号并输入 UNC 路径。Select the drive letter and enter the UNC path. 如果已按本快速入门中的建议命名,请从记事本复制 \qsstorageacct.file.core.chinacloudapi.cn\qsfileshareIf you've followed the naming suggestions in this quickstart, copy \qsstorageacct.file.core.chinacloudapi.cn\qsfileshare from Notepad.

    确保选中这两个复选框。Make sure both checkboxes are checked.

    “映射网络驱动器”对话框的屏幕截图

  5. 选择“完成”。 Select Finish.

  6. 在“Windows 安全性”对话框中: In the Windows Security dialog box:

    • 从记事本中复制前面带有 AZURE\ 的存储帐户名,并将其作为用户名粘贴到“Windows 安全性”对话框中。 From Notepad, copy the storage account name prepended with AZURE\ and paste it in the Windows Security dialog box as the username. 如果已按本快速入门中的建议命名,请复制 AZURE\qsstorageacctIf you've followed the naming suggestions in this quickstart, copy AZURE\qsstorageacct.

    • 从记事本中复制存储帐户密钥,并将其作为密码粘贴到“Windows 安全性”对话框中。 From Notepad, copy the storage account key and paste it in the Windows Security dialog box as the password.

      Azure 文件“连接”窗格中的 UNC 路径

创建共享快照Create a share snapshot

映射驱动器后,可以创建快照。Now that you've mapped the drive, you can create a snapshot.

  1. 在门户中,导航到你的文件共享并选择“创建快照”。 In the portal, navigate to your file share and select Create snapshot.

    创建快照

  2. 在 VM 中打开“qstestfile.txt”,键入“this file has been modified”,然后保存并关闭该文件。 In the VM, open the qstestfile.txt and type "this file has been modified" > Save and close the file.

  3. 创建另一个快照。Create another snapshot.

浏览共享快照Browse a share snapshot

  1. 在文件共享中,选择“查看快照” 。On your file share, select View snapshots.

  2. 在“文件共享快照”窗格中,选择列表中的第一个快照。 On the File share snapshots pane, select the first snapshot in the list.

    时间戳列表中的选定快照

  3. 在该快照的窗格中,选择“qsTestFile.txt”。 On the pane for that snapshot, select qsTestFile.txt.

从快照还原Restore from a snapshot

  1. 在文件共享快照边栏选项卡中,右键单击“qsTestFile”,然后选择“还原”按钮。 From the file share snapshot blade, right-click the qsTestFile, and select the Restore button.

  2. 选择“覆盖原始文件”。 Select Overwrite original file.

    “下载”和“还原”按钮

  3. 在 VM 中打开该文件。In the VM, open the file. 未修改的版本已还原。The unmodified version has been restored.

删除共享快照Delete a share snapshot

  1. 在文件共享中,选择“查看快照” 。On your file share, select View snapshots.

  2. 在“文件共享快照”窗格中,选择列表中的最后一个快照并单击“删除”。 On the File share snapshots pane, select the last snapshot in the list and click Delete.

    “删除”按钮

在 Windows 中使用共享快照Use a share snapshot in Windows

与使用本地 VSS 快照时一样,可以使用“以前的版本”选项卡通过装载的 Azure 文件共享查看快照。Just like with on-premises VSS snapshots, you can view the snapshots from your mounted Azure file share by using the Previous Versions tab.

  1. 在文件资源管理器中找到装载的共享。In File Explorer, locate the mounted share.

    文件资源管理器中的已装载共享

  2. 选择“qsTestFile.txt”,然后单击右键并从菜单中选择“属性”。 Select qsTestFile.txt and > right-click and select Properties from the menu.

    所选目录的右键单击菜单

  3. 选择"以前版本” ,以查看此目录的共享快照列表。Select Previous Versions to see the list of share snapshots for this directory.

  4. 选择“打开”以打开该快照。 Select Open to open the snapshot.

    “以前版本”选项卡

从以前版本还原Restore from a previous version

  1. 选择“还原”。 Select Restore. 此操作以递归方式将整个目录的内容复制到创建共享快照时所在的原始位置。This action copies the contents of the entire directory recursively to the original location at the time the share snapshot was created.

    警告消息中的“还原”按钮 注意:如果文件未更改,则不会看到该文件的之前版本,因为该文件的版本与快照的版本相同。Restore button in warning message Note:If your file has not changed, you will not see a previous version for that file because that file is the same version as the snapshot. 这与 Windows 文件服务器上的工作原理一致。This is consistent with how this works on a Windows file server.

清理资源Clean up resources

完成后,可以删除资源组。When you're done, you can delete the resource group. 删除资源组时会删除该资源组中部署的存储帐户、Azure 文件共享和其他任何资源。Deleting the resource group deletes the storage account, the Azure file share, and any other resources that you deployed inside the resource group.

  1. 在左侧菜单中,选择“资源组” 。In the left menu, select Resource groups.
  2. 右键单击该资源组,并选择“删除资源组”。 Right-click the resource group, and then select Delete resource group. 此时会打开一个窗口,其中显示有关将要与资源组一起删除的资源的警告。A window opens and displays a warning about the resources that will be deleted with the resource group.
  3. 输入资源组的名称,然后选择“删除” 。Enter the name of the resource group, and then select Delete.

后续步骤Next steps