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

如何使用 Blobfuse 将 Blob 存储装载为文件系统How to mount Blob storage as a file system with blobfuse

概述Overview

Blobfuse 是 Azure Blob 存储的虚拟文件系统驱动程序。Blobfuse is a virtual file system driver for Azure Blob storage. Blobfuse 允许通过 Linux 文件系统访问存储帐户中的现有块 Blob 数据。Blobfuse allows you to access your existing block blob data in your storage account through the Linux file system. Azure Blob 存储是一项对象存储服务,并且没有分层命名空间。Azure Blob storage is an object storage service and doesn't have a hierarchical namespace. Blobfuse 使用虚拟目录方案提供这种命名空间,并使用正斜杠“/”作为分隔符。Blobfuse provides this namespace using the virtual directory scheme with the forward-slash '/' as a delimiter.

本指南介绍如何使用 Blobfuse,以及如何在 Linux 上装载 Blob 存储容器并访问数据。This guide shows you how to use blobfuse, and mount a Blob storage container on Linux and access data. 若要详细了解 Blobfuse,请阅读 Blobfuse 存储库中的详细信息。To learn more about blobfuse, read the details in the blobfuse repository.

警告

Blobfuse 不保证 100% 的 POSIX 符合性,因为它只是将请求转换成 Blob REST APIBlobfuse doesn't guarantee 100% POSIX compliance as it simply translates requests into Blob REST APIs. 例如,重命名操作在 POSIX 中是原子操作,但在 Blobfuse 中不是。For example, rename operations are atomic in POSIX, but not in blobfuse. 有关本机文件系统和 Blobfuse 之间差异的完整列表,请访问 Blobfuse 源代码存储库For a full list of differences between a native file system and blobfuse, visit the blobfuse source code repository.

在 Linux 上安装 BlobfuseInstall blobfuse on Linux

适用于 Ubuntu 和 RHEL 发行版的 Blobfuse 二进制文件在适用于 Linux 的 Microsoft 软件存储库中提供。Blobfuse binaries are available on the Microsoft software repositories for Linux for Ubuntu and RHEL distributions. 若要在这些发行版上安装 blobfuse,请从列表中配置其中一个存储库。To install blobfuse on those distributions, configure one of the repositories from the list. 如果你的发行版没有可用的二进制文件,还可以按照 Azure 存储安装步骤从源代码生成二进制文件。You can also build the binaries from source code following the Azure Storage installation steps if there are no binaries available for your distribution.

Blobfuse 支持在 Ubuntu 14.04 和 16.04 上进行安装。Blobfuse supports installation on Ubuntu 14.04 and 16.04. 运行以下命令以确保你已部署了以下版本之一:Run this command to make sure that you have one of those versions deployed:

lsb_release -a

配置 Microsoft 包存储库Configure the Microsoft package repository

配置 Microsoft 产品的 Linux 包存储库Configure the Linux Package Repository for Microsoft Products.

例如,在 Enterprise Linux 6 发行版中:As an example, on an Enterprise Linux 6 distribution:

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/6/packages-microsoft-prod.rpm

类似地,将 URL 更改为 .../rhel/7/...,使之指向 Enterprise Linux 7 发行版。Similarly, change the URL to .../rhel/7/... to point to an Enterprise Linux 7 distribution.

Ubuntu 14.04 发行版上的另一个示例:Another example on an Ubuntu 14.04 distribution:

wget https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update

类似地,将 URL 更改为 .../ubuntu/16.04/...,使之指向 Ubuntu 16.04 发行版。Similarly, change the URL to .../ubuntu/16.04/... to point to an Ubuntu 16.04 distribution.

安装 BlobfuseInstall blobfuse

在 Ubuntu/Debian 发行版中:On a Ubuntu/Debian distribution:

sudo apt-get install blobfuse

在 Enterprise Linux 发行版中:On an Enterprise Linux distribution:

sudo yum install blobfuse

准备装载Prepare for mounting

Blobfuse 要求文件系统中存在一个临时路径,用于缓冲和缓存任何打开的文件,以便提供类似本机的性能。Blobfuse provides native-like performance by requiring a temporary path in the file system to buffer and cache any open files. 对于此临时路径,请选择性能最高的磁盘,或者使用 ramdisk 来获得最佳性能。For this temporary path, choose the most performant disk, or use a ramdisk for best performance.

备注

Blobfuse 将所有打开的文件内容存储在临时路径中。Blobfuse stores all open file contents in the temporary path. 请确保有足够的空间来容纳所有打开的文件。Make sure to have enough space to accommodate all open files.

(可选)将 ramdisk 用于临时路径(Optional) Use a ramdisk for the temporary path

以下示例创建一个 16 GB 的 ramdisk,并创建一个用于 Blobfuse 的目录。The following example creates a ramdisk of 16 GB and a directory for blobfuse. 请根据需要选择大小。Choose the size based on your needs. 此 ramdisk 允许 Blobfuse 打开多个文件,只要其大小总计不超过 16 GB 即可。This ramdisk allows blobfuse to open files up to 16 GB in size.

sudo mount -t tmpfs -o size=16g tmpfs /mnt/ramdisk
sudo mkdir /mnt/ramdisk/blobfusetmp
sudo chown <youruser> /mnt/ramdisk/blobfusetmp

将 SSD 用作临时路径Use an SSD as a temporary path

在 Azure 中,可以使用 VM 上提供的临时磁盘 (SSD),为 Blobfuse 提供低延迟缓冲区。In Azure, you may use the ephemeral disks (SSD) available on your VMs to provide a low-latency buffer for blobfuse. 在 Ubuntu 发行版中,此临时磁盘装载在“/mnt”上。In Ubuntu distributions, this ephemeral disk is mounted on '/mnt'. 在 Red Hat 和 CentOS 发行版中,此临时磁盘装载在“/mnt/resource/”上。In Red Hat and CentOS distributions, the disk is mounted on '/mnt/resource/'.

请确保用户有权访问该临时路径:Make sure your user has access to the temporary path:

sudo mkdir /mnt/resource/blobfusetmp
sudo chown <youruser> /mnt/resource/blobfusetmp

配置存储帐户凭据Configure your storage account credentials

Blobfuse 要求将凭据采用以下格式存储在文本文件中:Blobfuse requires your credentials to be stored in a text file in the following format:

accountName myaccount
accountKey storageaccesskey
containerName mycontainer

创建此文件以后,请确保限制对它的访问权限,防止其他用户读取它。Once you've created this file, make sure to restrict access so no other user can read it.

chmod 600 fuse_connection.cfg

备注

如果已在 Windows 上创建了配置文件,请确保运行 dos2unix 以清理该文件并将其转换为 Unix 格式。If you have created the configuration file on Windows, make sure to run dos2unix to sanitize and convert the file to Unix format.

创建装载用的空目录Create an empty directory for mounting

mkdir ~/mycontainer

装载Mount

备注

有关装载选项的完整列表,请查看 Blobfuse 存储库For a full list of mount options, check the blobfuse repository.

若要装载 Blobfuse,请以用户身份运行以下命令。To mount blobfuse, run the following command with your user. 此命令将“/path/to/fuse_connection.cfg”中指定的容器装载到“/mycontainer”位置。This command mounts the container specified in '/path/to/fuse_connection.cfg' onto the location '/mycontainer'.

sudo blobfuse ~/mycontainer --tmp-path=/mnt/resource/blobfusetmp  --config-file=/path/to/fuse_connection.cfg -o attr_timeout=240 -o entry_timeout=240 -o negative_timeout=120

现在应该可以通过常规文件系统 API 访问块 Blob。You should now have access to your block blobs through the regular file system APIs. 装载该目录的用户是可以访问它的唯一人员,默认情况下,这可以保护访问权限。The user who mounts the directory is the only person who can access it, by default, which secures the access. 若要允许所有用户进行访问,可以通过选项 -o allow_other 进行装载。To allow access to all users, you can mount via the option -o allow_other.

cd ~/mycontainer
mkdir test
echo "hello world" > test/blob.txt

后续步骤Next steps