如何部署 Azure 文件How to deploy Azure Files

Azure 文件在云中提供完全托管的文件共享,这些共享项可通过行业标准 SMB 协议进行访问。Azure Files offers fully managed file shares in the cloud that are accessible via the industry standard SMB protocol. 本文介绍如何在组织内实际部署 Azure 文件。This article will show you how to practically deploy Azure Files within your organization.

强烈建议在按照本文中的步骤操作之前,阅读规划 Azure 文件部署We strongly recommend reading Planning for an Azure Files deployment prior to following the steps in this article.

必备条件Prerequisites

本文假设你已完成下列步骤:This article assumes that you have already completed the following steps:

  • 在所需区域创建了具有所需复原和加密选项的 Azure 存储帐户。Created an Azure Storage Account with your desired resiliency and encryption options, in the region you desire. 有关如何创建存储帐户的分步说明,请参阅创建存储帐户See Create a Storage Account for step-by-step directions on how to create a Storage Account.
  • 在存储帐户中创建了具有所需配额的 Azure 文件共享。Created an Azure file share with your desired quota in your Storage Account. 有关如何创建文件共享的分步说明,请参阅创建文件共享See Create a file share for step-by-step directions on how to create a file share.

将数据传输到 Azure 文件Transfer data into Azure Files

可能需要将现有文件共享(例如本地存储的文件共享)迁移到新的 Azure 文件共享。You may wish to migrate existing file shares, such as those stored on-premises, to your new Azure file share. 本部分介绍如何通过规划指南中详述的几种常用方法将数据移动到 Azure 文件共享This section will show you how to move data into an Azure file share via several popular methods detailed from the planning guide

Azure 导入/导出Azure Import/Export

使用 Azure 导入/导出服务,可将硬盘驱动器寄送到 Azure 数据中心,从而安全地将大量数据传输到 Azure 文件共享。The Azure Import/Export service allows you to securely transfer large amounts of data into an Azure file share by shipping hard disk drives to an Azure datacenter. 有关此服务的更详细概述,请参阅使用 Azure 导入/导出服务将数据传输到 Azure 存储See Use the Azure Import/Export service to transfer data to Azure storage for a more detailed overview of the service.

备注

Azure 导入/导出服务目前不支持从 Azure 文件共享导出文件。The Azure Import/Export service does not support the export of files from an Azure file share at this time.

执行以下步骤可将数据从本地位置导入 Azure 文件共享。The following steps will import data from an on-premises location to your Azure file share.

  1. 获取所需数量的硬盘,将其邮寄到 Azure。Procure the required number of hard disks to mail into Azure. 硬盘可以是任何磁盘大小,但必须是支持 SATA II 或 SATA III 标准的 2.5 英寸或 3.5 英寸 SSD 或 HDD。Hard disks may be of any disk size, but must be either a 2.5" or 3.5" SSD or HDD supporting the SATA II or SATA III standard.

  2. 在执行数据传输的服务器/电脑上连接并装载每个磁盘。Connect and mount each disk on the server/PC doing the data transfer. 为了获得最佳性能,建议在包含该数据的服务器上本地运行本地导出作业。For optimal performance, we recommend running the on-premises export job locally on the server that contains the data. 在某些情况下,例如提供数据的文件服务器是 NAS 设备时,可能无法实现这一点。In some cases, such as when the file server that serves the data is a NAS device, this may not be possible. 在这种情况下,完全可以在电脑上装载所有磁盘。In that case, it is perfectly acceptable to mount each disk on a PC.

  3. 确保每个驱动器处于联机状态、已初始化,并分配有驱动器号。Ensure each drive is online, initialized, and is assigned a drive letter. 要对驱动器执行联机、初始化和分配驱动器号等操作,请打开磁盘管理 MMC 管理单元 (diskmgmt.msc)。To do bring a drive online, initialize, and assign a drive letter, open the Disk Management MMC snap-in (diskmgmt.msc).

    • 要使磁盘联机(如尚未联机),请在磁盘管理 MMC 的下方窗格中右键单击磁盘,然后选择“联机”。To bring a disk online (if it's not already online), right-click on the disk in the lower pane of the Disk Management MMC and select "Online".

    • 要初始化磁盘,请在下方窗格中右键单击磁盘(磁盘已联机),然后选择“初始化”。To initialize a disk, right-click on the disk in the lower pane (after the disk is online), and select "Initialize". 请务必在出现提示时选择“GPT”。Be sure to select "GPT" when asked.

      磁盘管理 MMC 中“初始化磁盘”菜单的屏幕截图

    • 要为磁盘分配驱动器号,请右键单击处于联机状态且已初始化的磁盘的“未分配”空间,然后单击“新建简单卷”。To assign a drive letter to the disk, right-click on the "unallocated" space of the online and initialized disk, and click "New Simple Volume". 可据此分配驱动器号。This will allow you to assign drive letter. 请注意,不需要格式化卷,因为稍后会执行此操作。Note that you do not need to format the volume as this will be done later.

      磁盘管理 MMC 中“新建简单卷”向导的屏幕截图

  4. 创建数据集 CSV 文件。Create the dataset CSV file. 数据集 CSV 文件是本地数据路径与数据应复制到的所需 Azure 文件共享之间的映射。The dataset CSV file is a mapping between the path to the data on-premises and the desired Azure file share the data should be copied to. 例如,以下数据集 CSV 文件将本地文件共享(“F:\shares\scratch”)映射到 Azure 文件共享(“MyAzureFileShare”):For example, the following dataset CSV file maps an on-premises file share ("F:\shares\scratch") to an Azure file share ("MyAzureFileShare"):

    BasePath,DstItemPathOrPrefix,ItemType,Disposition,MetadataFile,PropertiesFile
    "F:\shares\scratch\","MyAzureFileShare/",file,rename,"None",None
    

    可以指定同一存储帐户的多个共享。Multiple shares with a Storage Account may be specified. 有关详细信息,请参阅准备数据集 CSV 文件See Prepare the dataset CSV file for more information.

  5. 创建驱动器集 CSV 文件。Create the driveset CSV file. 驱动器集 CSV 文件可列出本地导出代理可用的磁盘。The driveset CSV file lists the disks available to the on-premises export agent. 例如,以下驱动器集 CSV 文件可列出用于本地导出作业的 X:Y:Z: 驱动器:For example, the following driveset CSV file lists X:, Y:, and Z: drives to be used in the on-premises export job:

    DriveLetter,FormatOption,SilentOrPromptOnFormat,Encryption,ExistingBitLockerKey
    X,Format,SilentMode,Encrypt,
    Y,Format,SilentMode,Encrypt,
    Z,Format,SilentMode,Encrypt,
    

    有关详细信息,请参阅准备驱动器集 CSV 文件See Prepare the driveset CSV file for more information.

  6. 使用 WAImportExport 工具将数据复制到一个或多个硬盘驱动器。Use the WAImportExport Tool to copy your data to one or more hard drives.

    WAImportExport.exe PrepImport /j:<JournalFile> /id:<SessionId> [/logdir:<LogDirectory>] [/sk:<StorageAccountKey>] [/silentmode] [/InitialDriveSet:<driveset.csv>] DataSet:<dataset.csv>
    

    警告

    完成磁盘准备操作以后,请勿修改硬盘驱动器上的数据,也勿修改日志文件。Do not modify the data on the hard disk drives or the journal file after completing disk preparation.

  7. 创建导入作业Create an import job.

RobocopyRobocopy

Robocopy 是 Windows 和 Windows Server 自带的一款知名复制工具。Robocopy is a well known copy tool that ships with Windows and Windows Server. Robocopy 可用于将数据传输到 Azure 文件,方法是在本地装载文件共享,然后使用装载位置作为 Robocopy 命令的目标位置。Robocopy may be used to transfer data into Azure Files by mounting the file share locally, and then using the mounted location as the destination in the Robocopy command. Robocopy 操作非常简单:Using Robocopy is quite simple:

  1. 装载 Azure 文件共享Mount your Azure file share. 为了获得最佳性能,建议在包含该数据的服务器上本地装载 Azure 文件共享。For optimal performance, we recommend mounting the Azure file share locally on the server that contains the data. 在某些情况下,例如提供数据的文件服务器是 NAS 设备时,可能无法实现这一点。In some cases, such as when the file server that serves the data is a NAS device, this may not be possible. 在这种情况下,完全可以在电脑上装载 Azure 文件共享。In that case, it is perfectly acceptable to mount the Azure file share on a PC. 本示例在命令行处使用 net use 来装载文件共享:In this example, net use is used at the command line to mount the file share:

    net use <desired-drive-letter>: \\<storage-account-name>.file.core.chinacloudapi.cn\<share-name> <storage-account-key> /user:Azure\<storage-account-name>
    
  2. 在命令行处使用 robocopy 将数据移动到 Azure 文件共享:Use robocopy at the command line to move data to the Azure file share:

    robocopy <path-to-local-share> <path-to-azure-file-share> /E /Z /MT:32
    

    Robocopy 提供丰富的选项,用户可根据需要修改复制行为。Robocopy has a significant number of options to modify the copy behavior as desired. 有关详细信息,请查看 Robocopy 手册页。For more information, view the Robocopy manual page.

AzCopyAzCopy

AzCopy 是一个命令行实用程序,专用于使用具有优化性能的简单命令在 Azure 文件和 Azure Blob 存储中复制/粘贴数据。AzCopy is a command-line utility designed for copying data to and from Azure Files, as well as Azure Blob storage, using simple commands with optimal performance. AzCopy 操作简单:Using AzCopy is easy:

  1. 下载最新版本的 AzCopy on WindowsAzCopy on LinuxDownload the latest version of AzCopy on Windows or Linux.

  2. 在命令行处使用 azcopy 将数据移动到 Azure 文件共享。Use azcopy at the command line to move data to the Azure file share. 对于 Windows,其语法如下:The syntax on Windows is as follows:

    azcopy /Source:<path-to-local-share> /Dest:https://<storage-account>.file.core.chinacloudapi.cn/<file-share>/ /DestKey:<storage-account-key> /S
    

    对于 Linux,命令语法稍有不同:On Linux, the command syntax is a little different:

    azcopy --source <path-to-local-share> --destination https://<storage-account>.file.core.chinacloudapi.cn/<file-share>/ --dest-key <storage-account-key> --recursive
    

    AzCopy 提供丰富的选项,用户可根据需要修改复制行为。AzCopy has a significant number of options to modify the copy behavior as desired. 有关详细信息,请参阅 AzCopy on WindowsAzCopy on LinuxFor more information, view AzCopy on Windows and AzCopy on Linux.

在所需电脑或服务器上自动装载Automatically mount on needed PCs/Servers

要替换本地文件共享,最好在将要使用的计算机上预先装载共享。To replace an on-premises file share, it is helpful to pre-mount the shares on the machines it will be used on. 可在一系列计算机上自动完成此操作。This can be done automatically on a list of machines.

备注

装载 Azure 文件共享需要使用存储帐户密钥作为密码,因此最好仅在受信任的环境中进行装载。Mounting an Azure file share requires using the storage account key as the password, therefore we only recommend mounting in trusted environments.

WindowsWindows

可使用 PowerShell 在多台电脑上运行装载命令。PowerShell can be used run the mount command on multiple PCs. 在以下示例中,需要手动填充 $computers,但你可以生成要自动装载的计算机列表。In the following example, $computers is manually populated, but you can generate the list of computers to mount automatically. 例如,可使用 Active Directory 中的结果填充此变量。For example, you can populate this variable with results from Active Directory.

$computer = "MyComputer1", "MyComputer2", "MyComputer3", "MyComputer4"
$computer | ForEach-Object { Invoke-Command -ComputerName $_ -ScriptBlock { net use <desired-drive-letter>: \\<storage-account-name>.file.core.chinacloudapi.cn\<share-name> <storage-account-key> /user:Azure\<storage-account-name> /PERSISTENT:YES } }

LinuxLinux

与 SSH 结合使用的简单 bash 脚本可以在以下示例中产生相同的结果。A simple bash script combined with SSH can yield the same result in the following example. 同样,$computer 变量也需要用户手动填充:The $computer variable is similarly left to be populated by the user:

computer = ("MyComputer1" "MyComputer2" "MyComputer3" "MyComputer4")
for item in "${computer[@]}"
do
    ssh $item "sudo bash -c 'echo \"//<storage-account-name>.file.core.chinacloudapi.cn/<share-name> /mymountpoint cifs vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino\" >> /etc/fstab'", "sudo mount -a"
done

后续步骤Next steps