【Azure Batch】使用Start Task來(lái)掛載Storage Blob
問(wèn)題描述
本文將介紹如何使用開(kāi)始任務(wù)(Start Task)為Batch Account Node配置Storage Account Blob掛載
問(wèn)題解答
第一步:準(zhǔn)備 blobfuse2 mount的配置文件
這里參考的是文檔How to configure settings for BlobFuse2 (https://learn.microsoft.com/en-us/azure/storage/blobs/blobfuse2-configuration)中介紹的最簡(jiǎn)單的配置模板。
簡(jiǎn)單模板如下:
logging: type: syslog level: log_debug components: - libfuse - file_cache - attr_cache - azstorage libfuse: attribute-expiration-sec: 120 entry-expiration-sec: 120 negative-entry-expiration-sec: 240 file_cache: path: /mycontainer timeout-sec: 120 max-size-mb: 4096 attr_cache: timeout-sec: 7200 azstorage: type: block account-name: <your storage account name> account-key: <your storage account access key> mode: key container: forbatch endpoint: https://<your storage account name>.blob.core.chinacloudapi.cn
PS:關(guān)于模板中參數(shù)的意義,可以參考文檔中的詳細(xì)介紹。
第二步:準(zhǔn)備Batch Account Node的Start Task 腳本
腳本內(nèi)容
/bin/bash -c "apt-get update && apt-get install -y blobfuse2 && cd /mnt/batch/tasks/fsmounts && mkdir /mnt/batch/tasks/fsmounts/mycontainerblob && sudo blobfuse2 mount /mnt/batch/tasks/fsmounts/mycontainerblob --config-file=$AZ_BATCH_NODE_STARTUP_DIR/wd/mountconfig.yaml
腳本介紹
1) 因?yàn)锽atch Account的節(jié)點(diǎn)為L(zhǎng)inux系統(tǒng),所以第一步更新系統(tǒng)apt-get,確保最新版本
2) apt-get install -y blobfuse2 : 自動(dòng)安裝 blobfuse2,這是azure提供的工具,用于將blob掛載為本地系統(tǒng)文件
3) cd /mnt/batch/tasks/fsmounts : 切換到 Azure Batch 的掛載目錄。
4) mkdir /mnt/batch/tasks/fsmounts/mycontainerblob 創(chuàng)建一個(gè)用于掛載 Blob 容器的本地目錄。 mycontainerblob 是掛載點(diǎn)的名稱,可以根據(jù)實(shí)際容器名稱修改。
5) sudo blobfuse2 mount /mnt/batch/tasks/fsmounts/mycontainerblob --config-file=$AZ_BATCH_NODE_STARTUP_DIR/wd/mountconfig.yaml : 使用 BlobFuse2 掛載 Azure Blob 容器到剛創(chuàng)建的目錄。 --config-file 指定了一個(gè) YAML 配置文件,包含連接字符串、容器名稱、緩存設(shè)置等。 $AZ_BATCH_NODE_STARTUP_DIR/wd/ 是 Azure Batch 節(jié)點(diǎn)啟動(dòng)任務(wù)的工作目錄,mountconfig.yaml 是第一步時(shí)準(zhǔn)備好的配置文件。
6) && : 用于連接前后兩個(gè)命令。特別注意,兩個(gè)命令之間必須使用 && 連接字符
第三步:把啟動(dòng)命令和配置文件填入Node Start Task頁(yè)面
因命令中有安裝/創(chuàng)建操作,所以需要提升權(quán)限為 Pool autouser, Admin權(quán)限。
此外,第二步中的config-file的文件路徑就是下圖中的 Resource Files。需要特別注意的就是,正確的工作目錄為 $AZ_BATCH_NODE_STARTUP_DIR/wd/ , 需要多加一級(jí) /wd/

保存,等待節(jié)點(diǎn)創(chuàng)建完成后就可以正常使用掛載目錄,把文件直接寫入到Storage Blob中。
參考資料
How to configure settings for BlobFuse2 : https://learn.microsoft.com/en-us/azure/storage/blobs/blobfuse2-configuration
在 Batch 池上裝載虛擬文件系統(tǒng): https://docs.azure.cn/zh-cn/batch/virtual-file-mount?tabs=windows
當(dāng)在復(fù)雜的環(huán)境中面臨問(wèn)題,格物之道需:濁而靜之徐清,安以動(dòng)之徐生。 云中,恰是如此!

浙公網(wǎng)安備 33010602011771號(hào)