强曰为道
与天地相似,故不违。知周乎万物,而道济天下,故不过。旁行而不流,乐天知命,故不忧.
文档目录

Rclone 数据迁移完全指南 / 第 7 章 - 挂载远程存储

第 7 章 - 挂载远程存储


7.1 挂载概述

Rclone 的 mount 命令可以将远程存储挂载为本地文件系统,使云存储像本地磁盘一样使用。

支持的操作

  • 使用标准文件操作(lscpmvrm)访问云存储
  • 使用本地应用程序打开云端文件
  • 流式读取大文件(如视频、音频)
  • 写入文件到云端

系统要求

平台 依赖 安装命令
Linux FUSE 2 / FUSE 3 sudo apt install fuse3fuse
macOS macFUSE osxfuse.github.io
Windows WinFsp winfsp.dev

7.2 基本挂载

Linux / macOS

# 创建挂载点
mkdir -p ~/cloud

# 挂载 Google Drive
rclone mount gdrive: ~/cloud &

# 现在可以像本地目录一样访问
ls ~/cloud/
cp ~/cloud/document.pdf /tmp/

Windows (CMD / PowerShell)

# 挂载为盘符
rclone mount gdrive: G: --volname "Google Drive"

# 或挂载为目录
rclone mount gdrive: C:\Users\user\cloud --volname "Cloud"

卸载

# Linux / macOS
fusermount -u ~/cloud
# 或
umount ~/cloud

# Windows
rclone mount gdrive: G: --unmount

7.3 挂载参数详解

常用参数

参数 说明 默认值
--allow-other 允许其他用户访问
--allow-root 允许 root 访问
--read-only 只读挂载
--vfs-cache-mode VFS 缓存模式 off
--vfs-cache-max-age 缓存过期时间 1h
--vfs-cache-max-size 缓存最大大小 无限制
--dir-cache-time 目录缓存时间 5m
--poll-interval 轮询间隔检测变化 1m
--attr-timeout 文件属性缓存时间 1s
--daemon 后台运行
--volname 卷名 远程名

完整示例

rclone mount gdrive: ~/cloud \
  --allow-other \
  --vfs-cache-mode full \
  --vfs-cache-max-age 72h \
  --vfs-cache-max-size 10G \
  --dir-cache-time 24h \
  --poll-interval 15s \
  --attr-timeout 1h \
  --buffer-size 64M \
  --transfers 4 \
  --log-file /var/log/rclone-mount.log \
  --log-level INFO

7.4 VFS(Virtual File System)缓存

VFS 缓存是 Rclone 挂载性能的关键。理解 VFS 缓存模式对于正确使用挂载至关重要。

缓存模式对比

模式 说明 读性能 写性能 磁盘占用 适用场景
off 不缓存 极简单次读取
minimal 最小缓存 极小 偶尔读取
writes 缓存写操作 主要写入
full 完全缓存 推荐日常使用

off 模式

# 不缓存,直接访问远程存储
# 优点:不占用本地磁盘
# 缺点:性能差,不支持随机读取
rclone mount gdrive: ~/cloud --vfs-cache-mode off

minimal 模式

# 只缓存打开的文件的元数据
# 文件内容不缓存
rclone mount gdrive: ~/cloud --vfs-cache-mode minimal

writes 模式

# 写操作先写入本地缓存,后台异步上传到远程
# 读操作直接访问远程
rclone mount gdrive: ~/cloud --vfs-cache-mode writes

full 模式(推荐)

# 读写都经过本地缓存
# 优点:性能最好,支持随机读取
# 缺点:占用本地磁盘空间
rclone mount gdrive: ~/cloud \
  --vfs-cache-mode full \
  --vfs-cache-max-size 10G \
  --vfs-cache-max-age 72h

缓存清理

# 手动清理 VFS 缓存
rclone backend vfs/forget gdrive:

# 查看缓存统计
rclone backend vfs/stats gdrive:

# 清理过期缓存
rclone backend vfs/purge gdrive: --max-age 24h

7.5 FUSE 挂载详解

Linux FUSE 配置

# 安装 FUSE
sudo apt install fuse3  # 推荐 FUSE 3
# 或
sudo apt install fuse    # FUSE 2

# 允许其他用户访问挂载(需要编辑 /etc/fuse.conf)
sudo sed -i '/^#user_allow_other/s/^#//' /etc/fuse.conf

# 使用 --allow-other
rclone mount gdrive: ~/cloud --allow-other

macOS macFUSE

# 安装 macFUSE
brew install macfuse

# 挂载
rclone mount gdrive: ~/cloud --volname "Google Drive"

Windows WinFsp

# 1. 下载安装 WinFsp: https://winfsp.dev/rel/
# 2. 挂载为盘符
rclone mount gdrive: G: --volname "Google Drive"

# 3. 查看挂载
rclone mount gdrive: G: --network-mode  # 网络驱动器模式

7.6 性能调优

针对不同场景的优化

大文件读取(视频、备份)

rclone mount s3:videos/ ~/videos \
  --vfs-cache-mode full \
  --vfs-read-ahead 128M \
  --buffer-size 64M \
  --transfers 2 \
  --vfs-cache-max-size 50G

大量小文件(项目代码、文档)

rclone mount gdrive:projects/ ~/projects \
  --vfs-cache-mode full \
  --dir-cache-time 1h \
  --poll-interval 30s \
  --attr-timeout 30s \
  --vfs-cache-max-age 24h \
  --vfs-cache-max-size 5G

只读归档(历史数据)

rclone mount s3:archive/ ~/archive \
  --read-only \
  --vfs-cache-mode full \
  --vfs-cache-max-age 168h \
  --dir-cache-time 24h \
  --buffer-size 128M

性能参数速查

参数 说明 推荐值
--buffer-size 读缓冲区 64M-256M
--vfs-read-ahead 预读取大小 64M-256M
--transfers 并行传输数 2-8
--dir-cache-time 目录缓存时间 5m-24h
--attr-timeout 属性缓存时间 1s-1h
--poll-interval 变化检测间隔 15s-5m

7.7 后台运行(Daemon 模式)

使用 –daemon 参数

# 后台运行
rclone mount gdrive: ~/cloud \
  --daemon \
  --vfs-cache-mode full \
  --vfs-cache-max-size 10G \
  --log-file /var/log/rclone-mount.log

使用 systemd(推荐)

创建服务文件:

sudo tee /etc/systemd/system/rclone-mount.service << 'EOF'
[Unit]
Description=Rclone Mount - Google Drive
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/rclone mount gdrive: /home/user/cloud \
  --vfs-cache-mode full \
  --vfs-cache-max-size 10G \
  --vfs-cache-max-age 72h \
  --dir-cache-time 24h \
  --poll-interval 15s \
  --allow-other \
  --log-level INFO \
  --log-file /var/log/rclone-mount.log
ExecStop=/bin/fusermount -uz /home/user/cloud
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

# 启用并启动
sudo systemctl daemon-reload
sudo systemctl enable rclone-mount
sudo systemctl start rclone-mount

# 查看状态
sudo systemctl status rclone-mount

使用 screen / tmux

# 使用 screen
screen -dmS rclone-mount rclone mount gdrive: ~/cloud --vfs-cache-mode full

# 使用 tmux
tmux new-session -d -s rclone-mount 'rclone mount gdrive: ~/cloud --vfs-cache-mode full'

7.8 多 Remote 挂载

同时挂载多个 Remote

# 挂载 Google Drive
rclone mount gdrive: ~/cloud/gdrive --daemon --vfs-cache-mode full

# 挂载 OneDrive
rclone mount onedrive: ~/cloud/onedrive --daemon --vfs-cache-mode full

# 挂载 S3
rclone mount s3:my-bucket/ ~/cloud/s3 --daemon --vfs-cache-mode full

使用 Union 合并挂载

# 配置合并 Remote
[all-cloud]
type = union
upstreams = gdrive: onedrive: dropbox:
action_policy = epl
create_policy = epm
search_policy = ff
# 一次挂载所有云存储
rclone mount all-cloud: ~/cloud --daemon --vfs-cache-mode full

7.9 挂载故障排除

常见问题

问题 原因 解决方案
fusermount: command not found FUSE 未安装 sudo apt install fuse3
transport endpoint is not connected 挂载进程崩溃 fusermount -uz /path && rclone mount ...
permission denied 权限问题 添加 --allow-other 或编辑 fuse.conf
文件操作超时 网络或缓存问题 增大 --dir-cache-time,检查网络
磁盘空间不足 VFS 缓存过大 减小 --vfs-cache-max-size

诊断命令

# 检查挂载状态
mount | grep rclone

# 查看挂载进程
ps aux | grep rclone

# 查看 FUSE 设备
ls -la /dev/fuse

# 测试读写速度
time dd if=~/cloud/testfile of=/dev/null bs=1M count=100

# 查看详细日志
tail -f /var/log/rclone-mount.log

注意事项

⚠️ FUSE 限制

  • 挂载的文件系统不支持所有 POSIX 操作
  • 文件锁定(flock)支持有限
  • 符号链接支持取决于后端

⚠️ 数据一致性

  • 多进程同时写入同一文件可能导致数据损坏
  • 使用 --poll-interval 定期检测远程变化
  • --dir-cache-time 控制目录元数据的缓存时间

💡 推荐配置:日常使用建议 --vfs-cache-mode full,配合合理的 --vfs-cache-max-size--vfs-cache-max-age

💡 生产环境:使用 systemd 管理挂载服务,确保开机自启和自动重启。


扩展阅读


上一章← 第 6 章 - 数据同步 下一章第 8 章 - 服务模式 →