使用 Azurite 模拟器进行本地 Azure 存储开发Use the Azurite emulator for local Azure Storage development

Azurite 开源模拟器提供一个免费的本地环境,用于测试 Azure Blob 和队列存储应用程序。The Azurite open-source emulator provides a free local environment for testing your Azure blob and queue storage applications. 如果你对应用程序在本地的工作状况感到满意,可以改用云中的 Azure 存储帐户。When you're satisfied with how your application is working locally, switch to using an Azure Storage account in the cloud. 该仿真器在 Windows、Linux 和 macOS 上提供跨平台支持。The emulator provides cross-platform support on Windows, Linux, and macOS.

Azurite 是未来的存储仿真器平台。Azurite is the future storage emulator platform. Azurite 取代了 Azure 存储仿真器Azurite supersedes the Azure Storage Emulator. Azurite 将持续更新,以支持最新版本的 Azure 存储 API。Azurite will continue to be updated to support the latest versions of Azure Storage APIs.

可通过多种不同的方法在本地系统上安装并运行 Azurite:There are several different ways to install and run Azurite on your local system:

  1. 安装并运行 Azurite Visual Studio Code 扩展Install and run the Azurite Visual Studio Code extension
  2. 使用 NPM 安装并运行 AzuriteInstall and run Azurite by using NPM
  3. 安装并运行 Azurite Docker 映像Install and run the Azurite Docker image
  4. 从 GitHub 存储库克隆、生成并运行 AzuriteClone, build, and run Azurite from the GitHub repository

安装并运行 Azurite Visual Studio Code 扩展Install and run the Azurite Visual Studio Code extension

在 Visual Studio Code 中选择“扩展”窗格,然后在“扩展: 市场”中搜索 AzuriteWithin Visual Studio Code, select the EXTENSIONS pane and search for Azurite in the EXTENSIONS:MARKETPLACE.

Visual Studio Code 扩展市场

也可在浏览器中导航到 Visual Studio Code 扩展市场You can also navigate to Visual Studio Code extension market in your browser. 选择“安装”按钮打开 Visual Studio Code,并直接转到 Azurite 扩展页。Select the Install button to open Visual Studio Code and go directly to the Azurite extension page.

该扩展支持以下 Visual Studio Code 命令。The extension supports the following Visual Studio Code commands. 若要打开命令面板,请在 Visual Studio Code 中按 F1。To open the command palette, press F1 in Visual Studio Code.

  • Azurite:Clean - 重置所有 Azurite 服务永久性数据Azurite: Clean - Reset all Azurite services persistency data
  • Azurite:Clean Blob Service - 清理 Blob 服务Azurite: Clean Blob Service - Clean blob service
  • Azurite:Clean Queue Service - 清理队列服务Azurite: Clean Queue Service - Clean queue service
  • Azurite:Close - 关闭所有 Azurite 服务Azurite: Close - Close all Azurite services
  • Azurite:Close Blob Service - 关闭 Blob 服务Azurite: Close Blob Service - Close blob service
  • Azurite:Close Queue Service - 关闭队列服务Azurite: Close Queue Service - Close queue service
  • Azurite:Start - 启动所有 Azurite 服务Azurite: Start - Start all Azurite services
  • Azurite:Start Blob Service - 启动 Blob 服务Azurite: Start Blob Service - Start blob service
  • Azurite:Start Queue Service - 启动队列服务Azurite: Start Queue Service - Start queue service

若要在 Visual Studio Code 中配置 Azurite,请选择“扩展”窗格。To configure Azurite within Visual Studio Code, select the extensions pane. 选择 Azurite 所对应的“管理”(齿轮)图标。Select the Manage (gear) icon for Azurite. 选择“扩展设置”。Select Extension Settings.

Azurite 的“配置扩展设置”

支持以下设置:The following settings are supported:

  • Azurite:Blob 主机 - Blob 服务的侦听终结点。Azurite: Blob Host - The Blob service listening endpoint. 默认设置为 127.0.0.1。The default setting is 127.0.0.1.
  • Azurite:Blob 端口 - Blob 服务的侦听端口。Azurite: Blob Port - The Blob service listening port. 默认端口为 10000。The default port is 10000.
  • Azurite:证书 - 本地受信任 PEM 的路径或 PFX 证书文件路径,用于启用 HTTPS 模式。Azurite: Cert - Path to a locally trusted PEM or PFX certificate file path to enable HTTPS mode.
  • Azurite:调试 - 将调试日志输出到 Azurite 通道。Azurite: Debug - Output the debug log to the Azurite channel. 默认值是 false秒。The default value is false.
  • Azurite:密钥 - 本地受信任 PEM 密钥文件的路径,在“Azurite:证书”指向 PEM 文件文件时是必需的。Azurite: Key - Path to a locally trusted PEM key file, required when Azurite: Cert points to a PEM file.
  • Azurite:位置 - 工作区位置路径。Azurite: Location - The workspace location path. 默认值为 Visual Studio Code 的工作文件夹。The default is the Visual Studio Code working folder.
  • Azurite:松散 - 启用松散模式,将会忽略不受支持的标头和参数。Azurite: Loose - Enable loose mode, which ignores unsupported headers and parameters.
  • Azurite:Oauth - 可选 OAuth 级别。Azurite: Oauth - Optional OAuth level.
  • Azurite:Pwd - PFX 文件的密码。Azurite: Pwd - Password for PFX file. 在“Azurite:证书”指向 PFX 文件时是必需的。Required when Azurite: Cert points to a PFX file.
  • Azurite:队列主机 - 队列服务的侦听终结点。Azurite: Queue Host - The Queue service listening endpoint. 默认设置为 127.0.0.1。The default setting is 127.0.0.1.
  • Azurite:队列端口 - 队列服务的侦听端口。Azurite: Queue Port - The Queue service listening port. 默认端口为 10001。The default port is 10001.
  • Azurite:无提示 - 无提示模式会禁用访问日志。Azurite: Silent - Silent mode disables the access log. 默认值是 false秒。The default value is false.
  • Azurite:跳过 API 版本检查 - 跳过请求 API 版本检查。Azurite: Skip Api Version Check - Skip the request API version check. 默认值是 false秒。The default value is false.

使用 NPM 安装并运行 AzuriteInstall and run Azurite by using NPM

此安装方法需要安装 Node.js 8.0 或更高版本This installation method requires that you have Node.js version 8.0 or later installed. Node 包管理器 (npm) 是每个 Node.js 安装随附的包管理工具。Node Package Manager (npm) is the package management tool included with every Node.js installation. 安装 Node.js 后,请执行以下 npm 命令以安装 Azurite。After installing Node.js, execute the following npm command to install Azurite.

npm install -g azurite

安装 Azurite 后,请参阅从命令行运行 AzuriteAfter installing Azurite, see Run Azurite from a command line.

安装并运行 Azurite Docker 映像Install and run the Azurite Docker image

使用以下命令通过 DockerHub 提取最新的 Azurite 映像Use DockerHub to pull the latest Azurite image by using the following command:

docker pull mcr.microsoft.com/azure-storage/azurite

运行 Azurite Docker 映像Run the Azurite Docker image:

以下命令运行 Azurite Docker 映像。The following command runs the Azurite Docker image. -p 10000:10000 参数将来自主机端口 10000 的请求重定向到 Docker 实例。The -p 10000:10000 parameter redirects requests from host machine's port 10000 to the Docker instance.

docker run -p 10000:10000 -p 10001:10001 \
    mcr.microsoft.com/azure-storage/azurite

指定工作区位置Specify the workspace location:

在以下示例中,-v c:/azurite:/data 参数指定“c:/azurite”作为 Azurite 永久性数据的位置。In the following example, the -v c:/azurite:/data parameter specifies c:/azurite as the Azurite persisted data location. 必须在运行 Docker 命令之前创建目录“c:/azurite”。The directory, c:/azurite, must be created before running the Docker command.

docker run -p 10000:10000 -p 10001:10001 \
    -v c:/azurite:/data mcr.microsoft.com/azure-storage/azurite

仅运行 blob 服务Run just the blob service

docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite \
    azurite-blob --blobHost 0.0.0.0 --blobPort 10000

若要详细了解如何在启动时配置 Azurite,请参阅命令行选项For more information about configuring Azurite at start-up, see Command-line options.

从 GitHub 存储库克隆、生成并运行 AzuriteClone, build, and run Azurite from the GitHub repository

此安装方法需要安装 GitThis installation method requires that you have Git installed. 使用以下控制台命令克隆 Azurite 项目的 GitHub 存储库Clone the GitHub repository for the Azurite project by using the following console command.

git clone https://github.com/Azure/Azurite.git

克隆源代码后,从克隆的存储库的根目录执行以下命令,以生成并安装 Azurite。After cloning the source code, execute following commands from the root of the cloned repo to build and install Azurite.

npm install
npm run build
npm install -g

安装并生成 Azurite 后,请参阅从命令行运行 AzuriteAfter installing and building Azurite, see Run Azurite from a command line.

从命令行运行 AzuriteRun Azurite from a command line

备注

如果只是安装了 Visual Studio Code 扩展,则无法从命令行运行 Azurite。Azurite cannot be run from the command line if you only installed the Visual Studio Code extension. 请改用 Visual Studio Code 命令面板。Instead, use the Visual Studio Code command palette. 有关详细信息,请参阅安装并运行 Azurite Visual Studio Code 扩展For more information, see Install and run the Azurite Visual Studio Code extension.

若要立即开始使用命令行,请创建名为 c:\azurite 的目录,然后发出以下命令以启动 Azurite:To get started immediately with the command line, create a directory called c:\azurite, then launch Azurite by issuing the following command:

azurite --silent --location c:\azurite --debug c:\azurite\debug.log

此命令告知 Azurite 要将所有数据存储在特定目录 c:\azurite 中。This command tells Azurite to store all data in a particular directory, c:\azurite. 如果省略 --location 选项,此命令将使用当前工作目录。If the --location option is omitted, it will use the current working directory.

命令行选项Command-line options

本部分详细说明启动 Azurite 时可用的命令行开关。This section details the command line switches available when launching Azurite.

帮助Help

可选 - 通过使用 -h--help 开关获取命令行帮助。Optional - Get command-line help by using the -h or --help switch.

azurite -h
azurite --help

Blob 侦听主机Blob listening host

可选 - 默认情况下,Azurite 将侦听本地服务器 127.0.0.1。Optional - By default, Azurite will listen to 127.0.0.1 as the local server. 可根据需要使用 --blobHost 开关设置地址。Use the --blobHost switch to set the address to your requirements.

仅接受本地计算机上的请求:Accept requests on the local machine only:

azurite --blobHost 127.0.0.1

允许远程请求:Allow remote requests:

azurite --blobHost 0.0.0.0

注意

允许远程请求可能会导致系统容易受到外部攻击。Allowing remote requests may make your system vulnerable to external attacks.

Blob 侦听端口配置Blob listening port configuration

可选 - 默认情况下,Azurite 将在端口 10000 上侦听 Blob 服务。Optional - By default, Azurite will listen for the Blob service on port 10000. 使用 --blobPort 开关可指定所需的侦听端口。Use the --blobPort switch to specify the listening port that you require.

备注

使用自定义端口后,需要在 Azure 存储工具或 SDK 中更新连接字符串或相应的配置。After using a customized port, you need to update the connection string or corresponding configuration in your Azure Storage tools or SDKs.

自定义 Blob 服务侦听端口:Customize the Blob service listening port:

azurite --blobPort 8888

让系统自动选择可用端口:Let the system auto select an available port:

azurite --blobPort 0

Azurite 启动期间,会显示正在使用的端口。The port in use is displayed during Azurite startup.

队列侦听主机Queue listening host

可选 - 默认情况下,Azurite 将侦听本地服务器 127.0.0.1。Optional - By default, Azurite will listen to 127.0.0.1 as the local server. 可根据需要使用 --queueHost 开关设置地址。Use the --queueHost switch to set the address to your requirements.

仅接受本地计算机上的请求:Accept requests on the local machine only:

azurite --queueHost 127.0.0.1

允许远程请求:Allow remote requests:

azurite --queueHost 0.0.0.0

注意

允许远程请求可能会导致系统容易受到外部攻击。Allowing remote requests may make your system vulnerable to external attacks.

队列侦听端口配置Queue listening port configuration

可选 - 默认情况下,Azurite 将在端口 10001 上侦听队列服务。Optional - By default, Azurite will listen for the Queue service on port 10001. 使用 --queuePort 开关可指定所需的侦听端口。Use the --queuePort switch to specify the listening port that you require.

备注

使用自定义端口后,需要在 Azure 存储工具或 SDK 中更新连接字符串或相应的配置。After using a customized port, you need to update the connection string or corresponding configuration in your Azure Storage tools or SDKs.

自定义队列服务侦听端口:Customize the Queue service listening port:

azurite --queuePort 8888

让系统自动选择可用端口:Let the system auto select an available port:

azurite --queuePort 0

Azurite 启动期间,会显示正在使用的端口。The port in use is displayed during Azurite startup.

工作区路径Workspace path

可选 - 在执行过程中,Azurite 会将数据存储到本地磁盘。Optional - Azurite stores data to the local disk during execution. 使用 -l--location 开关可将某个路径指定为工作区位置。Use the -l or --location switch to specify a path as the workspace location. 默认将使用当前进程的工作目录。By default, the current process working directory will be used. 请注意小写的“l”。Note the lowercase 'l'.

azurite -l c:\azurite
azurite --location c:\azurite

访问日志Access log

可选 - 默认情况下,访问日志会显示在控制台窗口中。Optional - By default, the access log is displayed in the console window. 使用 -s--silent 开关可以禁止显示访问日志。Disable the display of the access log by using the -s or --silent switch.

azurite -s
azurite --silent

调试日志Debug log

可选 - 调试日志包括有关每个请求和异常堆栈跟踪的详细信息。Optional - The debug log includes detailed information on every request and exception stack trace. -d--debug 开关中提供有效的本地文件路径可以启用调试日志。Enable the debug log by providing a valid local file path to the -d or --debug switch.

azurite -d path/debug.log
azurite --debug path/debug.log

松散模式Loose mode

可选 - 默认情况下,Azurite 应用严格模式来阻止不受支持的请求标头和参数。Optional - By default, Azurite applies strict mode to block unsupported request headers and parameters. 使用 -L--loose 开关禁用严格模式。Disable strict mode by using the -L or --loose switch. 请注意大写的“L”。Note the capital 'L'.

azurite -L
azurite --loose

版本Version

可选 - 通过使用 -v--version 开关显示已安装 Azurite 的版本号。Optional - Display the installed Azurite version number by using the -v or --version switch.

azurite -v
azurite --version

证书配置 (HTTPS)Certificate configuration (HTTPS)

可选 - 默认情况下,Azurite 使用 HTTP 协议。Optional - By default, Azurite uses the HTTP protocol. 启用 HTTPS 模式的方法是:向隐私增强邮件 (.pem) 提供路径,或者向 --cert 开关提供个人信息交换 (.pfx) 证书文件。Enable HTTPS mode by providing a path to a Privacy Enhanced Mail (.pem) or Personal Information Exchange (.pfx) certificate file to the --cert switch.

为 PEM 文件提供 --cert 时,必须提供相应的 --key 开关。When --cert is provided for a PEM file, you must provide a corresponding --key switch.

azurite --cert path/server.pem --key path/key.pem

为 PFX 文件提供 --cert 时,必须提供相应的 --pwd 开关。When --cert is provided for a PFX file, you must provide a corresponding --pwd switch.

azurite --cert path/server.pfx --pwd pfxpassword

若要详细了解如何创建 PEM 和 PFX 文件,请参阅 HTTPS 设置For detailed information on creating PEM and PFX files, see HTTPS Setup.

OAuth 配置OAuth configuration

可选 - 通过使用 --oauth 开关为 Azurite 启用 OAuth 身份验证。Optional - Enable OAuth authentication for Azurite by using the --oauth switch.

azurite --oauth basic --cert path/server.pem --key path/key.pem

备注

OAuth 需要 HTTPS 终结点。OAuth requires an HTTPS endpoint. 请确保通过提供 --cert 开关和 --oauth 开关来启用 HTTPS。Make sure HTTPS is enabled by providing --cert switch along with the --oauth switch.

Azurite 通过为 --oauth 开关指定 basic 参数来支持基本身份验证。Azurite supports basic authentication by specifying the basic parameter to the --oauth switch. Azurite 会执行基本身份验证,例如验证传入的持有者令牌;检查颁发者、受众和到期时间。Azurite will do basic authentication, like validating the incoming bearer token, checking the issuer, audience, and expiry. Azurite 不会检查令牌签名或权限。Azurite won't check the token signature or permissions.

跳过 API 版本检查Skip API Version Check

可选 - 启动时,Azurite 会检查请求的 API 版本是否有效。Optional - When starting up, Azurite checks that the requested API version is valid. 以下命令会跳过 API 版本检查:The following command skips the API version check:

azurite --skipApiVersionCheck

工具和 SDK 的授权Authorization for tools and SDKs

使用任何身份验证策略从 Azure 存储 SDK 或工具(例如 Azure 存储资源管理器)连接到 Azurite。Connect to Azurite from Azure Storage SDKs or tools, like Azure Storage Explorer, by using any authentication strategy. 需要身份验证。Authentication is required. Azurite 支持使用 OAuth、共享密钥和共享访问签名 (SAS) 进行授权。Azurite supports authorization with OAuth, Shared Key, and shared access signatures (SAS). Azurite 还支持匿名访问公共容器。Azurite also supports anonymous access to public containers.

如果使用的是 Azure SDK,请使用 --oauth basic and --cert --key/--pwd 选项启动 Azurite。If you're using the Azure SDKs, start Azurite with the --oauth basic and --cert --key/--pwd options.

已知的存储帐户和密钥Well-known storage account and key

Azurite 接受旧式 Azure 存储仿真器使用的众所周知的帐户和密钥。Azurite accepts the same well-known account and key used by the legacy Azure storage emulator.

  • 帐户名称:devstoreaccount1Account name: devstoreaccount1
  • 帐户密钥:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

自定义存储帐户和密钥Custom storage accounts and keys

Azurite 支持自定义存储帐户名称和密钥,但需将 AZURITE_ACCOUNTS 环境变量设置为以下格式:account1:key1[:key2];account2:key1[:key2];...Azurite supports custom storage account names and keys by setting the AZURITE_ACCOUNTS environment variable in the following format: account1:key1[:key2];account2:key1[:key2];....

例如,使用包含一个密钥的自定义存储帐户:For example, use a custom storage account that has one key:

set AZURITE_ACCOUNTS="account1:key1"
export AZURITE_ACCOUNTS="account1:key1"

也可使用多个存储帐户,每个存储帐户有两个密钥:Or use multiple storage accounts with two keys each:

set AZURITE_ACCOUNTS="account1:key1:key2;account2:key1:key2"
export AZURITE_ACCOUNTS="account1:key1:key2;account2:key1:key2"

默认情况下,Azurite 每分钟刷新环境变量中的自定义帐户名和密钥。Azurite refreshes custom account names and keys from the environment variable every minute by default. 利用此功能,可以动态轮换帐户密钥,或添加新的存储帐户,而无需重启 Azurite。With this feature, you can dynamically rotate the account key, or add new storage accounts without restarting Azurite.

备注

设置自定义存储帐户时,将禁用默认的 devstoreaccount1 存储帐户。The default devstoreaccount1 storage account is disabled when you set custom storage accounts.

连接字符串Connection strings

从应用程序连接到 Azurite 的最简单方法是在应用程序的配置文件中配置一个引用快捷方式 UseDevelopmentStorage=true 的连接字符串。The easiest way to connect to Azurite from your application is to configure a connection string in your application's configuration file that references the shortcut UseDevelopmentStorage=true. 下面是 app.config 文件中的连接字符串示例:Here's an example of a connection string in an app.config file:

<appSettings>
  <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>

HTTP 连接字符串HTTP connection strings

可将以下连接字符串传递到 Azure SDK 或者 Azure CLI 2.0 或存储资源管理器等工具。You can pass the following connection strings to the Azure SDKs or tools, like Azure CLI 2.0 or Storage Explorer.

完整的连接字符串为:The full connection string is:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;

若只连接到 blob 服务,则连接字符串为:To connect to the blob service only, the connection string is:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;

若只连接到队列服务,则连接字符串为:To connect to the queue service only, the connection string is:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;

HTTPS 连接字符串HTTPS connection strings

完整的 HTTPS 连接字符串为:The full HTTPS connection string is:

DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;

若只使用 blob 服务,则 HTTPS 连接字符串为:To use the blob service only, the HTTPS connection string is:

DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;

若只使用队列服务,则 HTTPS 连接字符串为:To use the queue service only, the HTTPS connection string is:

DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;

如果使用了 dotnet dev-certs 生成自签名证书,请使用以下连接字符串。If you used dotnet dev-certs to generate your self-signed certificate, use the following connection string.

DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://localhost:10000/devstoreaccount1;QueueEndpoint=https://localhost:10001/devstoreaccount1;

使用自定义存储帐户和密钥时,请更新连接字符串。Update the connection string when using custom storage accounts and keys.

有关详细信息,请参阅配置 Azure 存储连接字符串For more information, see Configure Azure Storage connection strings.

Azure SDKAzure SDKs

若要将 Azurite 与 Azure SDK 配合使用,请使用 OAuth 和 HTTPS 选项:To use Azurite with the Azure SDKs, use OAuth and HTTPS options:

azurite --oauth basic --cert certname.pem --key certname-key.pem

Azure Blob 存储Azure Blob Storage

然后,可以实例化 BlobContainerClient、Blobserviceclient 或 BlobClient。You can then instantiate a BlobContainerClient, BlobServiceClient, or BlobClient.

// With container URL and DefaultAzureCredential
var client = new BlobContainerClient(
    new Uri("https://127.0.0.1:10000/devstoreaccount1/container-name"), new DefaultAzureCredential()
  );

// With connection string
var client = new BlobContainerClient(
    "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;", "container-name"
  );

// With account name and key
var client = new BlobContainerClient(
    new Uri("https://127.0.0.1:10000/devstoreaccount1/container-name"),
    new StorageSharedKeyCredential("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==")
  );

Azure Queue StorageAzure Queue Storage

还可以实例化 QueueClient 或 QueueServiceClient。You can also instantiate a QueueClient or QueueServiceClient.

// With queue URL and DefaultAzureCredential
var client = new QueueClient(
    new Uri("https://127.0.0.1:10001/devstoreaccount1/queue-name"), new DefaultAzureCredential()
  );

// With connection string
var client = new QueueClient(
    "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;", "queue-name"
  );

// With account name and key
var client = new QueueClient(
    new Uri("https://127.0.0.1:10001/devstoreaccount1/queue-name"),
    new StorageSharedKeyCredential("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==")
  );

Microsoft Azure 存储资源管理器Microsoft Azure Storage Explorer

可以使用存储资源管理器查看存储在 Azurite 中的数据。You can use Storage Explorer to view the data stored in Azurite.

使用 HTTP 连接到 AzuriteConnect to Azurite using HTTP

在存储资源管理器中,按照以下步骤连接到 Azurite:In Storage Explorer, connect to Azurite by following these steps:

  1. 选择“管理帐户”图标Select the Manage Accounts icon
  2. 选择“添加帐户”Select Add an account
  3. 选择“附加到本地仿真器”Select Attach to a local emulator
  4. 选择“下一步”Select Next
  5. 将“显示名称”字段编辑为所选名称Edit the Display name field to a name of your choice
  6. 再次选择“下一步”Select Next again
  7. 选择“连接”Select Connect

使用 HTTPS 连接到 AzuriteConnect to Azurite using HTTPS

默认情况下,存储资源管理器不会打开使用自签名证书的 HTTPS 终结点。By default Storage Explorer won't open an HTTPS endpoint that uses a self-signed certificate. 如果你是使用 HTTPS 来运行 Azurite,则可能使用的是自签名证书。If you're running Azurite with HTTPS, you're likely using a self-signed certificate. 在存储资源管理器中,通过“编辑” -> “SSL 证书” -> “导入证书”对话框导入 SSL 证书。In Storage Explorer, import SSL certificates via the Edit -> SSL Certificates -> Import Certificates dialog.

将证书导入到存储资源管理器Import Certificate to Storage Explorer
  1. 在本地计算机上找到证书。Find the certificate on your local machine.
  2. 在存储资源管理器中转到“编辑” -> “SSL 证书” -> “导入证书”,然后导入你的证书。In Storage Explorer, go to Edit -> SSL Certificates -> Import Certificates and import your certificate.

如果不导入证书,则会出现错误:If you don't import a certificate, you'll get an error:

unable to verify the first certificateself signed certificate in chainunable to verify the first certificate or self signed certificate in chain

通过 HTTPS 连接字符串添加 AzuriteAdd Azurite via HTTPS connection string

按照以下步骤将 Azurite HTTPS 添加到存储资源管理器:Follow these steps to add Azurite HTTPS to Storage Explorer:

  1. 选择“切换资源管理器”Select Toggle Explorer
  2. 选择“本地和附加”Select Local & Attached
  3. 右键单击“存储帐户”,然后选择“连接到 Azure 存储”。 Right-click on Storage Accounts and select Connect to Azure Storage.
  4. 选择“使用连接字符串”Select Use a connection string
  5. 选择“下一步”。Select Next.
  6. 在“显示名称”字段中输入值。Enter a value in the Display name field.
  7. 输入本文档上一部分中的 HTTPS 连接字符串Enter the HTTPS connection string from the previous section of this document
  8. 选择“下一步”Select Next
  9. 选择“连接”Select Connect

工作区结构Workspace structure

初始化 Azurite 时,可以在工作区位置创建以下文件和文件夹。The following files and folders may be created in the workspace location when initializing Azurite.

  • __blobstorage__ - 目录,其中包含 Azurite blob 服务持久化二进制数据__blobstorage__ - Directory containing Azurite blob service persisted binary data
  • __queuestorage__ - 目录,其中包含 Azurite 队列服务持久化二进制数据__queuestorage__ - Directory containing Azurite queue service persisted binary data
  • __azurite_db_blob__.json - Azurite blob 服务元数据文件__azurite_db_blob__.json - Azurite blob service metadata file
  • __azurite_db_blob_extent__.json - Azurite blob 服务盘区元数据文件__azurite_db_blob_extent__.json - Azurite blob service extent metadata file
  • __azurite_db_queue__.json - Azurite 队列服务元数据文件__azurite_db_queue__.json - Azurite queue service metadata file
  • __azurite_db_queue_extent__.json - Azurite 队列服务盘区元数据文件__azurite_db_queue_extent__.json - Azurite queue service extent metadata file

若要清理 Azurite,请删除以上文件和文件夹,然后重启仿真器。To clean up Azurite, delete above files and folders and restart the emulator.

Azurite 与 Azure 存储之间的差别Differences between Azurite and Azure Storage

Azurite 本地实例与云中的 Azure 存储帐户在功能上有差别。There are functional differences between a local instance of Azurite and an Azure Storage account in the cloud.

终结点和连接 URLEndpoint and connection URL

Azurite 的服务终结点不同于 Azure 存储帐户的终结点。The service endpoints for Azurite are different from the endpoints of an Azure Storage account. 本地计算机不执行域名解析,要求 Azurite 终结点是本地地址。The local computer doesn't do domain name resolution, requiring Azurite endpoints to be local addresses.

对 Azure 存储帐户中的资源寻址时,帐户名称是 URI 主机名的一部分。When you address a resource in an Azure Storage account, the account name is part of the URI host name. 要寻址的资源是 URI 路径的一部分:The resource being addressed is part of the URI path:

<http|https>://<account-name>.<service-name>.core.chinacloudapi.cn/<resource-path>

以下 URI 是 Azure 存储帐户中某个 Blob 的有效地址:The following URI is a valid address for a blob in an Azure Storage account:

https://myaccount.blob.core.chinacloudapi.cn/mycontainer/myblob.txt

由于本地计算机不执行域名解析,帐户名称是 URI 路径的一部分,而不是主机名的一部分。Since the local computer doesn't do domain name resolution, the account name is part of the URI path instead of the host name. 对 Azurite 中的资源使用以下 URI 格式:Use the following URI format for a resource in Azurite:

http://<local-machine-address>:<port>/<account-name>/<resource-path>

可使用以下地址访问 Azurite 中的 Blob:The following address might be used for accessing a blob in Azurite:

http://127.0.0.1:10000/myaccount/mycontainer/myblob.txt

缩放和性能Scaling and performance

Azurite 不支持大量连接的客户端。Azurite doesn't support large numbers of connected clients. 它不提供性能方面的保证。There's no performance guarantee. Azurite 用于开发和测试目的。Azurite is intended for development and testing purposes.

错误处理。Error handling

Azurite 的错误处理逻辑与 Azure 存储相符,但存在一些差别。Azurite is aligned with Azure Storage error handling logic, but there are differences. 例如,错误消息可能不同,而错误状态代码是一致的。For example, error messages may be different, while error status codes align.

RA-GRSRA-GRS

Azurite 支持读取访问异地冗余复制 (RA-GRS)。Azurite supports read-access geo-redundant replication (RA-GRS). 对于存储资源,可以通过在帐户名称后面追加 -secondary 来访问次要位置。For storage resources, access the secondary location by appending -secondary to the account name. 例如,以下地址可用于访问 Azurite 中使用只读辅助副本的 Blob:For example, the following address might be used for accessing a blob using the read-only secondary in Azurite:

http://127.0.0.1:10000/devstoreaccount1-secondary/mycontainer/myblob.txt

Azurite 是开源的Azurite is open-source

欢迎为 Azurite 贡献作品和提出建议。Contributions and suggestions for Azurite are welcome. 请访问 Azurite GitHub 项目页或 GitHub 问题了解产品里程碑,以及我们针对即将推出的功能和 bug 修复正在跟进的工作项。Go to the Azurite GitHub project page or GitHub issues for milestones and work items we're tracking for upcoming features and bug fixes. GitHub 中也列出了详细的工作项。Detailed work items are also tracked in GitHub.

后续步骤Next steps