【应用服务 App Service】App Service For Linux 中如何挂载一个共享文件夹呢? Mount Azure Storage Account File Share
问题描述
使用Linux作为服务器运行Web App时,如何将 Storage Account 作为本地共享装载到 App Service for Linux / Container 中的应用呢?
问题解答
根据官网介绍, App Service For Linux / Container 是可以通过配置完成Mount Azure Storage Account的blob或者是File Share 到Linux环境中的。 它主要的优势有以下四点:
- 为App Service 应用配置永久性存储,并单独管理存储。
- 使静态内容(如视频和图像)可随时用于App Service 应用。
- 将应用程序日志文件写入 Azure 文件共享,或将较旧的应用程序日志存档到 Azure 文件共享。
- 跨多个应用或与其他 Azure 服务共享内容。
操作步骤可以详细参考:以本地共享(容器)形式装载 Azure 存储 - Azure App Service | Microsoft Docs
添加 Azure Storage Mount 的内容说明如下:
名称(Name) :装载配置的名称。 不允许空格。
配置选项 (Configuration options): 如果存储帐户未使用服务终结点或专用终结点,则选择“基本”。 否则,选择“高级”。
存储帐户 (Storage accounts):Azure 存储帐户。
存储类型 (Storage type):根据要装载的存储选择类型。 Azure Blob 仅支持只读访问。
存储容器 / 共享名(Storage container / Share name) :要装载的文件共享或 Blob 容器。
访问密钥(仅高级)(Access Key) :存储帐户的访问密钥。
装载路径(Mount path) :要装载到 Azure 存储的 Linux 容器中的目录。 不要使用 / 或 /home。
问题验证
在App Service门户中,进入SSH页面( https://<yourappservicename>.scm.chinacloudsites.cn/webssh/host ),执行 df –h 显示查看File Share是否Mount成功。
在/appcontent目录中新建文件test1.txt,然后在Storage Account中查看文件是否存在
也可以在SSH中通过 tcpping 来查看App Service Storage Account之间的网络连通性
tcpping <Storageaccount>.file.core.chinacloudapi.cn
附录一:容器app service 如何添加启动参数 --privileged
可以在App Service的Configuration 配置页面中对启动命令一项中根据需求进行设置。如设置 –privileged = true
设置保存后,通过kudu( https://<your app service name>.scm.chinacloudsites.cn/ )站点进入bash页面,查看Logfiles中的日志文件。可以查看到docker run指令中已经包含了 –privileged=ture 参数。
参考文档
将 Azure 存储作为本地共享装载到应用服务中的容器应用 :https://docs.microsoft.com/zh-cn/azure/app-service/configure-connect-to-azure-storage?tabs=portal&pivots=container-linux#mount-storage-to-linux-container
Linux df command - displays number of free disk blocks and free files : https://docs.oracle.com/cd/E23823_01/html/816-5166/df-1m.html#REFMAN1Mdf-1m
-h
Like -k, except that sizes are in a more human readable format. The output consists of one line of information for each specified file system. This information includes the file system name, the total space allocated in the file system, the amount of space allocated to existing files, the total amount of space available for the creation of new files by unprivileged users, and the percentage of normally available space that is currently allocated to all files on the file system. All sizes are scaled to a human readable format, for example, 14K, 234M, 2.7G, or 3.0T. Scaling is done by repetitively dividing by 1024.This option overrides the -b, -e, -g, -k, -n, -t, and -V options. This option only works on mounted filesystems and can not be used together with -o option.
-k
Prints the allocation in kbytes. The output consists of one line of information for each specified file system. This information includes the file system name, the total space allocated in the file system, the amount of space allocated to existing files, the total amount of space available for the creation of new files by unprivileged users, and the percentage of normally available space that is currently allocated to all files on the file system. This option overrides the -b, -e, -n, and -t options.-l
Reports on local file systems only. This option is used only for mounted file systems. It can not be used with the -o option.
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!