使用 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 中,選取 [延伸 模組] 窗格,並在 [延伸模組: MARKETPLACE] 中搜尋 AzuriteWithin Visual Studio Code, select the EXTENSIONS pane and search for Azurite in the EXTENSIONS:MARKETPLACE.

Visual Studio Code 擴充功能 marketplace

您也可以在瀏覽器中流覽至 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:清除 -重設所有 Azurite services 持續性資料Azurite: Clean - Reset all Azurite services persistency data
  • Azurite:清除 Blob 服務 -清除 blob 服務Azurite: Clean Blob Service - Clean blob service
  • Azurite:清理佇列服務 -清理佇列服務Azurite: Clean Queue Service - Clean queue service
  • Azurite:關閉 並關閉所有 Azurite 服務Azurite: Close - Close all Azurite services
  • Azurite:關閉 Blob 服務 -關閉 blob 服務Azurite: Close Blob Service - Close blob service
  • Azurite:關閉佇列服務 -關閉佇列服務Azurite: Close Queue Service - Close queue service
  • Azurite:啟動 -啟動所有 Azurite 服務Azurite: Start - Start all Azurite services
  • Azurite:啟動 Blob 服務 -啟動 blob 服務Azurite: Start Blob Service - Start blob service
  • Azurite:啟動佇列服務 -啟動佇列服務Azurite: Start Queue Service - Start queue service

若要在 Visual Studio Code 中設定 Azurite,請選取 [擴充功能] 窗格。To configure Azurite within Visual Studio Code, select the extensions pane. 選取 [ 管理 (齒輪) ] 圖示以進行 AzuriteSelect the Manage (gear) icon for Azurite. 選取 [ 延伸模組設定]。Select Extension Settings.

Azurites 設定延伸模組設定

以下是支援的設定: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: Cert -本機信任 PEM 或 PFX 憑證檔案路徑的路徑,以啟用 HTTPS 模式。Azurite: Cert - Path to a locally trusted PEM or PFX certificate file path to enable HTTPS mode.
  • Azurite: debug -將 debug 記錄輸出至 Azurite 通道。Azurite: Debug - Output the debug log to the Azurite channel. 預設值為 falseThe default value is false.
  • Azurite:Azurite: Cert 指向 PEM 檔案時,所需的本機受信任 PEM 金鑰檔的金鑰路徑。Azurite: Key - Path to a locally trusted PEM key file, required when Azurite: Cert points to a PEM file.
  • Azurite: Location -工作區位置路徑。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: Cert 指向 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: Queue port -佇列服務接聽埠。Azurite: Queue Port - The Queue service listening port. 預設通訊埠為10001。The default port is 10001.
  • Azurite:無 訊息無訊息模式停用存取記錄檔。Azurite: Silent - Silent mode disables the access log. 預設值為 falseThe default value is false.
  • Azurite:略過 Api 版本檢查 -略過要求 api 版本檢查。Azurite: Skip Api Version Check - Skip the request API version check. 預設值為 falseThe 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. 您必須先建立目錄( c:/azurite),才能執行 Docker 命令。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.

HelpHelp

選擇性 -使用或參數取得命令列說明 -h --helpOptional - 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 --silentDisable the display of the access log by using the -s or --silent switch.

azurite -s
azurite --silent

Debug 記錄檔Debug log

選擇性 -debug 記錄檔包含每個要求和例外狀況堆疊追蹤的詳細資訊。Optional - The debug log includes detailed information on every request and exception stack trace. 藉由提供有效的本機檔案路徑給或 switch 來啟用 debug 記錄檔 -d --debugEnable 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 會套用 strict 模式來封鎖不支援的要求標頭和參數。Optional - By default, Azurite applies strict mode to block unsupported request headers and parameters. 使用或參數停用 strict -L 模式 --looseDisable strict mode by using the -L or --loose switch. 請注意大寫的 ' L '。Note the capital 'L'.

azurite -L
azurite --loose

版本Version

選擇性 -使用或參數顯示已安裝的 Azurite 版本 -v 號碼 --versionOptional - 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. 提供隱私權增強郵件 ( pem) 或個人資訊交換 ( .pfx) 憑證檔案的路徑,以啟用 HTTPS 模式。 --certEnable HTTPS mode by providing a path to a Privacy Enhanced Mail (.pem) or Personal Information Exchange (.pfx) certificate file to the --cert switch.

--cert 提供 PEM 檔案的時,您必須提供對應的 --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

--cert 提供 PFX 檔案的時,您必須提供對應的 --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

選擇性 -使用參數啟用 Azurite 的 OAuth 驗證 --oauthOptional - 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. 藉由提供交換器和交換器來確定已啟用 HTTPS --cert --oauthMake sure HTTPS is enabled by providing --cert switch along with the --oauth switch.

Azurite 藉由指定參數參數來支援基本驗證 basic --oauthAzurite 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 或工具連接到 Azurite,例如 Azure 儲存體總管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,請使用選項來啟動 Azurite --oauth basic and --cert --key/--pwdIf 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 佇列儲存體Azure 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

新增 Azurite via HTTPS 連接字串Add 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.windows.net/<resource-path>

下列 URI 是 Azure 儲存體帳戶中 blob 的有效位址:The following URI is a valid address for a blob in an Azure Storage account:

https://myaccount.blob.core.windows.net/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 支援讀取權限異地冗余複寫 (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

資料表支援Table support

Azurite 中的資料表支援目前正在開發中,並已開放參與!Support for tables in Azurite is currently under development and open to contribution! 如需最新的進度,請檢查 Azurite V3 資料表 專案。For the latest progress, check the Azurite V3 Table project.

持久函式的支援需要資料表。Support for durable functions requires tables.

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