Azure 文件存储 #

什么是 Azure 文件存储? #

Azure 文件存储提供完全托管的文件共享,支持 SMB 和 NFS 协议。

text
┌─────────────────────────────────────────────────────────────┐
│                    Azure 文件存储概览                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  特点                                                        │
│  ├── 完全托管:无需管理硬件                                 │
│  ├── SMB 3.0 协议:Windows 兼容                             │
│  ├── NFS 4.1 协议:Linux 兼容                               │
│  ├── 多端访问:云和本地                                     │
│  └── 高可用:内置冗余                                       │
│                                                             │
│  适用场景                                                    │
│  ├── 企业文件共享                                           │
│  ├── 应用配置共享                                           │
│  ├── 持久化容器存储                                         │
│  ├── 混合云文件同步                                         │
│  └── Lift and Shift 迁移                                    │
│                                                             │
│  与传统文件服务器对比                                        │
│  ├── 无需维护硬件                                           │
│  ├── 自动扩展                                               │
│  ├── 内置高可用                                             │
│  └── 按使用付费                                             │
│                                                             │
└─────────────────────────────────────────────────────────────┘

文件共享类型 #

性能层级 #

text
┌─────────────────────────────────────────────────────────────┐
│                    性能层级                                  │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  事务优化 (Transaction Optimized)                            │
│  ├── 高事务量                                               │
│  ├── 低延迟                                                 │
│  ├── 支持标准存储                                           │
│  └── 适合: 高频访问                                         │
│                                                             │
│  热层 (Hot)                                                  │
│  ├── 通用工作负载                                           │
│  ├── 平衡性能和成本                                         │
│  ├── 支持标准存储                                           │
│  └── 适合: 大多数场景                                       │
│                                                             │
│  冷层 (Cool)                                                 │
│  ├── 低频访问                                               │
│  ├── 存储成本低                                             │
│  ├── 支持标准存储                                           │
│  └── 适合: 归档场景                                         │
│                                                             │
│  高级 (Premium)                                              │
│  ├── 最高性能                                               │
│  ├── SSD 后端                                               │
│  ├── 低延迟                                                 │
│  └── 适合: 高性能应用                                       │
│                                                             │
└─────────────────────────────────────────────────────────────┘

创建文件共享 #

使用 Azure CLI #

bash
# 创建资源组
az group create --name myResourceGroup --location eastus

# 创建存储账户
az storage account create \
  --name mystorageaccount \
  --resource-group myResourceGroup \
  --location eastus \
  --sku Standard_LRS \
  --kind StorageV2

# 创建文件共享
az storage share create \
  --name myfileshare \
  --account-name mystorageaccount \
  --quota 1024

# 查看文件共享
az storage share list \
  --account-name mystorageaccount \
  --output table

使用 Azure 门户 #

text
┌─────────────────────────────────────────────────────────────┐
│                    创建文件共享步骤                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  步骤 1: 选择存储账户                                        │
│  └── 或创建新的存储账户                                     │
│                                                             │
│  步骤 2: 创建文件共享                                        │
│  ├── 名称: myfileshare                                      │
│  ├── 配额: 1-100000 GB                                      │
│  ├── 层级: 事务优化/热/冷                                   │
│  └── 协议: SMB/NFS                                          │
│                                                             │
│  步骤 3: 配置网络                                            │
│  ├── 公网访问                                               │
│  └── 私有端点                                               │
│                                                             │
└─────────────────────────────────────────────────────────────┘

文件操作 #

上传和下载 #

bash
# 上传文件
az storage file upload \
  --account-name mystorageaccount \
  --share-name myfileshare \
  --source ./localfile.txt \
  --path documents/

# 下载文件
az storage file download \
  --account-name mystorageaccount \
  --share-name myfileshare \
  --path documents/localfile.txt \
  --dest ./downloaded.txt

# 列出文件
az storage file list \
  --account-name mystorageaccount \
  --share-name myfileshare \
  --output table

# 创建目录
az storage directory create \
  --account-name mystorageaccount \
  --share-name myfileshare \
  --name documents

挂载文件共享 #

Windows 挂载 #

powershell
# 使用 PowerShell 挂载
$connectTestResult = Test-NetConnection -ComputerName mystorageaccount.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
    cmd.exe /C "cmdkey /add:`"mystorageaccount.file.core.windows.net`" /user:`"Azure\mystorageaccount`" /pass:`"<storage-key>`""
    cmd.exe /C "net use Z: `\\mystorageaccount.file.core.windows.net\myfileshare`"
} else {
    Write-Error "Port 445 is blocked"
}

# 使用脚本获取挂载命令
az storage share-rm show \
  --storage-account mystorageaccount \
  --name myfileshare \
  --query "properties.protocolSettings.smb.mountOptions"

Linux 挂载 #

bash
# 安装 cifs-utils
sudo apt-get install cifs-utils

# 创建挂载点
sudo mkdir -p /mnt/azurefileshare

# 挂载文件共享
sudo mount -t cifs //mystorageaccount.file.core.windows.net/myfileshare /mnt/azurefileshare -o vers=3.0,username=mystorageaccount,password=<storage-key>,dir_mode=0777,file_mode=0777

# 永久挂载 (编辑 /etc/fstab)
//mystorageaccount.file.core.windows.net/myfileshare /mnt/azurefileshare cifs vers=3.0,username=mystorageaccount,password=<storage-key>,dir_mode=0777,file_mode=0777,_netdev 0 0

macOS 挂载 #

bash
# 创建挂载点
sudo mkdir -p /Volumes/azurefileshare

# 挂载文件共享
sudo mount_smbfs //mystorageaccount:<storage-key>@mystorageaccount.file.core.windows.net/myfileshare /Volumes/azurefileshare

NFS 文件共享 #

创建 NFS 共享 #

bash
# 创建支持 NFS 的存储账户
az storage account create \
  --name mystorageaccount \
  --resource-group myResourceGroup \
  --location eastus \
  --sku Premium_LRS \
  --kind FileStorage \
  --enable-nfs-v3 true

# 创建 NFS 文件共享
az storage share-rm create \
  --storage-account mystorageaccount \
  --name mynfsshare \
  --enabled-protocols NFS \
  --root-squash NoRootSquash

挂载 NFS 共享 #

bash
# 安装 NFS 客户端
sudo apt-get install nfs-common

# 创建挂载点
sudo mkdir -p /mnt/nfsshare

# 挂载 NFS 共享
sudo mount -t nfs mystorageaccount.file.core.windows.net:/mystorageaccount/mynfsshare /mnt/nfsshare -o vers=4,minorversion=1,sec=sys

Azure 文件同步 #

文件同步架构 #

text
┌─────────────────────────────────────────────────────────────┐
│                    Azure 文件同步                            │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  组件                                                        │
│  ├── 存储同步服务: 同步拓扑管理                             │
│  ├── 同步组: 同步关系定义                                   │
│  ├── 已注册服务器: 本地服务器                               │
│  └── Azure 文件共享: 云端端点                               │
│                                                             │
│  同步模式                                                    │
│  ├── 云分层: 热数据本地,冷数据云端                         │
│  └── 完全同步: 所有数据同步                                 │
│                                                             │
│  架构示意:                                                  │
│                                                             │
│  ┌──────────────┐     ┌──────────────┐                     │
│  │ 本地服务器 A  │     │ 本地服务器 B  │                     │
│  │ (服务器端点)  │     │ (服务器端点)  │                     │
│  └──────┬───────┘     └──────┬───────┘                     │
│         │                    │                              │
│         └────────┬───────────┘                              │
│                  │                                          │
│                  ▼                                          │
│         ┌──────────────┐                                    │
│         │ 存储同步服务  │                                    │
│         └──────┬───────┘                                    │
│                │                                            │
│                ▼                                            │
│         ┌──────────────┐                                    │
│         │ Azure 文件共享│                                    │
│         │ (云端端点)    │                                    │
│         └──────────────┘                                    │
│                                                             │
└─────────────────────────────────────────────────────────────┘

部署文件同步 #

bash
# 创建存储同步服务
az storagesync create \
  --name myStorageSyncService \
  --resource-group myResourceGroup \
  --location eastus

# 创建同步组
az storagesync sync-group create \
  --name mySyncGroup \
  --storage-sync-name myStorageSyncService \
  --resource-group myResourceGroup

# 添加云端端点
az storagesync sync-group cloud-endpoint create \
  --name myCloudEndpoint \
  --storage-sync-name myStorageSyncService \
  --sync-group-name mySyncGroup \
  --storage-account mystorageaccount \
  --storage-account-resource-group myResourceGroup \
  --azure-file-share-name myfileshare

私有端点 #

创建私有端点 #

bash
# 创建虚拟网络
az network vnet create \
  --name myVNet \
  --resource-group myResourceGroup \
  --subnet-name default

# 创建私有端点
az network private-endpoint create \
  --name myPrivateEndpoint \
  --resource-group myResourceGroup \
  --vnet-name myVNet \
  --subnet default \
  --private-connection-resource-id /subscriptions/.../resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount \
  --group-id file \
  --connection-name myConnection

# 配置私有 DNS
az network private-dns zone create \
  --name privatelink.file.core.windows.net \
  --resource-group myResourceGroup

# 链接虚拟网络
az network private-dns link vnet create \
  --name myDNSLink \
  --resource-group myResourceGroup \
  --zone-name privatelink.file.core.windows.net \
  --virtual-network myVNet \
  --registration-enabled false

快照和备份 #

创建快照 #

bash
# 创建文件共享快照
az storage share snapshot \
  --account-name mystorageaccount \
  --name myfileshare

# 列出快照
az storage share list \
  --account-name mystorageaccount \
  --include-snapshot \
  --query "[?snapshot!=null]"

# 从快照恢复文件
az storage file download \
  --account-name mystorageaccount \
  --share-name myfileshare \
  --path documents/file.txt \
  --snapshot <snapshot-time> \
  --dest ./restored.txt

软删除 #

bash
# 启用软删除
az storage account file-service-properties update \
  --account-name mystorageaccount \
  --enable-delete-retention true \
  --delete-retention-days 14

# 查看软删除设置
az storage account file-service-properties show \
  --account-name mystorageaccount

最佳实践 #

性能优化 #

text
┌─────────────────────────────────────────────────────────────┐
│                    性能优化建议                              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  1. 选择正确的层级                                           │
│     ├── 高事务量: 事务优化                                  │
│     ├── 高性能需求: 高级                                    │
│     └── 低频访问: 冷层                                      │
│                                                             │
│  2. 使用私有端点                                             │
│     └── 降低延迟,提高安全性                                │
│                                                             │
│  3. 优化 SMB 设置                                            │
│     ├── 多通道                                              │
│     └── 缓存设置                                            │
│                                                             │
│  4. 云分层策略                                               │
│     └── 合理设置分层策略                                    │
│                                                             │
└─────────────────────────────────────────────────────────────┘

安全建议 #

text
┌─────────────────────────────────────────────────────────────┐
│                    安全最佳实践                              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  1. 使用私有端点                                             │
│     └── 限制公网访问                                        │
│                                                             │
│  2. 启用加密                                                 │
│     └── 传输中加密                                          │
│                                                             │
│  3. 使用 Azure AD 认证                                       │
│     └── 基于身份的访问                                      │
│                                                             │
│  4. 启用软删除                                               │
│     └── 数据保护                                            │
│                                                             │
│  5. 定期备份                                                 │
│     └── 使用 Azure Backup                                   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

下一步 #

现在你已经掌握了文件存储的使用,接下来学习 磁盘存储 了解 Azure 托管磁盘!

最后更新:2026-03-29