让服务器/电脑轻松挂载云存储到本地,像访问本地文件夹一样使用 OneDrive、Google Drive 等。
bash
rclone --version
如果未安装,根据系统选择:
bash
# macOS
brew install rclone
# Ubuntu / Debian
sudo apt install rclone
# CentOS / RHEL
sudo dnf install rclone
# 其他系统:https://rclone.org/install/
bash
# macOS
brew install rclone
# Ubuntu / Debian
sudo apt install rclone
# CentOS / RHEL
sudo dnf install rclone
# 验证安装
rclone --version
bash
# 交互式配置(推荐新手)
rclone config
详细步骤:
n 创建新配置onedrive(或你喜欢的名字)41drivealidriven(否)n(使用授权码方式)yy → qbash
# 列出云存储根目录文件
rclone lsd onedrive:
# 应该能看到你的云盘文件夹列表
bash
mkdir -p ~/cloud-storage/onedrive
bash
# 手动挂载(测试用)
rclone mount onedrive: ~/cloud-storage/onedrive --daemon --vfs-cache-mode writes
# 验证挂载
ls ~/cloud-storage/onedrive/
# 应该能看到云盘中的文件
使用提供的 systemd user service 脚本(无需 sudo):
bash
# 编辑配置
nano ~/.config/cloud-mount/config.sh
# 启用服务(无需 sudo)
~/cloud-mount/scripts/enable-autostart.sh enable
基本用法:
bash
# 使用默认配置挂载
~/cloud-mount/scripts/mount-cloud.sh onedrive
# 指定挂载点
~/cloud-mount/scripts/mount-cloud.sh onedrive ~/my-cloud
# 检查状态
~/cloud-mount/scripts/mount-cloud.sh --status
参数说明:
参数说明默认值remote_namerclone 配置的远程名称onedrivemount_point本地挂载点~/cloud-storage/
选项:
选项说明--status, -s显示所有挂载状态--help, -h显示帮助信息
基本用法:
bash
# 检查指定挂载点
~/cloud-mount/scripts/check-mount.sh ~/cloud-storage/onedrive
# 检查所有云存储挂载
~/cloud-mount/scripts/check-mount.sh --all
# 查看 rclone 进程
~/cloud-mount/scripts/check-mount.sh --processes
输出示例:
text
✓ /home/user/cloud-storage/onedrive - 已挂载
挂载源:onedrive:
文件系统:fuse.rclone
权限:可读写
进程:运行中 (PID: 12345)
使用 systemd user service,无需 sudo 权限。
命令:
bash
# 启用服务(无需 sudo)
~/cloud-mount/scripts/enable-autostart.sh enable
# 禁用服务
~/cloud-mount/scripts/enable-autostart.sh disable
# 查看状态
~/cloud-mount/scripts/enable-autostart.sh status
# 重启服务
~/cloud-mount/scripts/enable-autostart.sh restart
# 查看日志
~/cloud-mount/scripts/enable-autostart.sh logs
~/.config/cloud-mount/config.sh
bash
#!/bin/bash
# cloud-mount 配置文件
# 云存储远程名称(rclone config 中配置的名字)
CLOUD_REMOTE="onedrive"
# 本地挂载点
MOUNT_POINT="$HOME/cloud-storage/onedrive"
# 挂载选项
MOUNT_OPTIONS="--daemon --vfs-cache-mode writes --vfs-cache-max-size 1G"
# 是否开机自启
AUTO_START=true
选项说明推荐值备注--daemon后台运行必需不要省略--vfs-cache-mode缓存模式writes可选:minimal/writes/full--vfs-cache-max-size最大缓存1G根据内存调整--allow-other允许其他用户访问按需需要 fuse 配置--uid指定文件所有者 UID按需配合 allow-other--gid指定文件所有者 GID按需配合 allow-other--read-only只读模式按需保护云端数据--timeout空闲超时1h自动断开空闲连接
模式说明适用场景minimal最小缓存内存紧张、只读访问writes写入缓存(推荐)日常使用、平衡性能full完整缓存频繁读写、内存充足
云存储rclone 类型难度地区备注OneDrive 个人版onedrive⭐⭐全球最常用,5GB 免费OneDrive 商业版onedrive⭐⭐⭐全球需要企业账号Google Drivedrive⭐⭐海外15GB 免费,需科学上网阿里云盘alidrive⭐⭐中国速度快,容量大百度网盘baidu⭐⭐⭐中国需申请 API keyDropboxdropbox⭐⭐全球国际通用Amazon S3s3⭐⭐⭐全球对象存储,按量付费WebDAVwebdav⭐⭐通用支持坚果云、天翼云盘等SFTPsftp⭐⭐通用远程服务器FTPftp⭐⭐通用传统文件传输
💡 提示:支持所有 rclone 支持的云存储(70+ 种),查看完整列表: https://rclone.org/
bash
# 1. 配置 rclone(OneDrive)
rclone config
# 2. 挂载云存储
~/cloud-mount/scripts/mount-cloud.sh onedrive
# 3. 设置开机自启
sudo ~/cloud-mount/scripts/enable-autostart.sh enable
# 4. 在 Obsidian 中打开 vault
# 路径:~/cloud-storage/onedrive/ObsidianVault/
同步说明:
bash
# 1. 配置 Google Drive 用于备份
rclone config
# 2. 挂载备份盘
~/cloud-mount/scripts/mount-cloud.sh gdrive ~/backup
# 3. 创建备份脚本
cat > ~/backup.sh << 'EOF'
#!/bin/bash
rsync -av --delete /var/www/ ~/backup/www/
rsync -av --delete /etc/ ~/backup/etc/
rsync -av --delete /home/ ~/backup/home/
EOF
# 4. 设置定时任务
crontab -e
# 每天凌晨 2 点备份
0 2 * * * /bin/bash ~/backup.sh
bash
# 配置多个云存储
rclone config
# onedrive-personal
# onedrive-work
# gdrive-backup
# 分别挂载
~/cloud-mount/scripts/mount-cloud.sh onedrive-personal ~/cloud/personal
~/cloud-mount/scripts/mount-cloud.sh onedrive-work ~/cloud/work
~/cloud-mount/scripts/mount-cloud.sh gdrive-backup ~/backup
# 一键检查所有挂载
~/cloud-mount/scripts/check-mount.sh --all
内存优化(2GB 内存服务器):
bash
# 编辑配置
nano ~/.config/cloud-mount/config.sh
# 使用最小缓存
MOUNT_OPTIONS="--daemon --vfs-cache-mode minimal --vfs-cache-max-size 256M"
性能优化(8GB+ 内存服务器):
bash
# 使用完整缓存
MOUNT_OPTIONS="--daemon --vfs-cache-mode full --vfs-cache-max-size 2G"
症状: 挂载成功,但目录为空
排查步骤:
bash
# 1. 验证 rclone 配置
rclone lsd onedrive:
# 应该能看到云盘文件夹
# 2. 检查挂载进程
ps aux | grep rclone
# 应该有 rclone 进程在运行
# 3. 查看挂载点
ls -la ~/cloud-storage/onedrive/
# 4. 查看系统日志
dmesg | tail -20
# 5. 重新挂载
fusermount -u ~/cloud-storage/onedrive
~/cloud-mount/scripts/mount-cloud.sh onedrive
症状: InvalidAuthenticationToken 错误
解决方案:
bash
# 刷新 token
rclone config reconnect onedrive:
# 或重新配置
rclone config
症状: Permission denied 或 fusermount: mount failed
解决方案:
bash
# 1. 确保挂载点目录存在
mkdir -p ~/cloud-storage/onedrive
# 2. 检查目录权限
chmod 755 ~/cloud-storage/onedrive
# 3. 检查 fuse 是否安装
sudo apt install fuse # Debian/Ubuntu
sudo yum install fuse # CentOS/RHEL
# 4. 检查 fuse 模块
lsmod | grep fuse
# 如果没有,加载模块
sudo modprobe fuse
症状: 服务器内存紧张,OOM
解决方案:
bash
# 1. 减少缓存大小
nano ~/.config/cloud-mount/config.sh
MOUNT_OPTIONS="--daemon --vfs-cache-mode minimal --vfs-cache-max-size 256M"
# 2. 重启服务
sudo ~/cloud-mount/scripts/enable-autostart.sh restart
# 3. 监控内存使用
watch -n 1 'ps aux | grep rclone | grep -v grep'
症状: 重启后挂载未自动恢复
排查步骤:
bash
# 1. 查看服务状态
sudo systemctl status cloud-mount
# 2. 查看详细日志
sudo journalctl -u cloud-mount -n 50
# 3. 检查配置文件
cat ~/.config/cloud-mount/config.sh
# 4. 检查 rclone 配置
rclone config show onedrive
# 5. 重新启用服务
sudo ~/cloud-mount/scripts/enable-autostart.sh disable
sudo ~/cloud-mount/scripts/enable-autostart.sh enable
症状: 无法创建或修改文件
解决方案:
bash
# 1. 检查云存储权限
# 确认账号有写入权限
# 2. 检查挂载选项
# 确保没有使用 --read-only
# 3. 检查磁盘空间
rclone about onedrive:
# 4. 检查缓存目录权限
ls -la ~/.cache/rclone/
适合批量部署或自动化配置:
bash
# 创建 rclone 配置文件
mkdir -p ~/.config/rclone
cat > ~/.config/rclone/rclone.conf << 'EOF'
[onedrive]
type = onedrive
token = {"access_token":"...","refresh_token":"...","expiry":"..."}
drive_id = YOUR_DRIVE_ID
drive_type = personal
EOF
# 获取授权
rclone authorize onedrive
# 将返回的 JSON 替换上面的 token 占位符
bash
# ~/.config/cloud-mount/config-onedrive.sh
CLOUD_REMOTE="onedrive-personal"
MOUNT_POINT="$HOME/cloud-storage/personal"
MOUNT_OPTIONS="--daemon --vfs-cache-mode writes"
# ~/.config/cloud-mount/config-gdrive.sh
CLOUD_REMOTE="gdrive-backup"
MOUNT_POINT="$HOME/cloud-storage/backup"
MOUNT_OPTIONS="--daemon --vfs-cache-mode full --vfs-cache-max-size 2G"
手动创建服务文件 /etc/systemd/system/cloud-mount@.service:
ini
[Unit]
Description=Cloud Storage Mount (%i)
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
User=%i
Group=%i
Environment="HOME=/home/%i"
ExecStart=/usr/bin/rclone mount %i: /home/%i/cloud-storage/%i --daemon --vfs-cache-mode writes --vfs-cache-max-size 1G
ExecStop=/usr/bin/fusermount -u /home/%i/cloud-storage/%i || /bin/true
Restart=on-failure
RestartSec=10
StartLimitBurst=3
StartLimitInterval=60s
# 资源限制(防止内存泄漏)
MemoryMax=512M
MemoryHigh=256M
[Install]
WantedBy=multi-user.target
启用服务:
bash
sudo systemctl enable cloud-mount@onedrive.service
sudo systemctl start cloud-mount@onedrive.service
创建监控脚本 /usr/local/bin/watch-cloud-mount.sh:
bash
#!/bin/bash
# 监控云存储挂载状态
MOUNT_POINT="$HOME/cloud-storage/onedrive"
LOG_FILE="/var/log/cloud-mount-monitor.log"
if ! mount | grep -q "$MOUNT_POINT"; then
echo "$(date): Mount point $MOUNT_POINT not found, attempting to remount..." >> $LOG_FILE
# 尝试重新挂载
~/cloud-mount/scripts/mount-cloud.sh onedrive
if [ $? -eq 0 ]; then
echo "$(date): Remount successful" >> $LOG_FILE
else
echo "$(date): Remount failed!" >> $LOG_FILE
# 可以添加邮件/短信通知
fi
fi
添加到 crontab:
bash
# 每 5 分钟检查一次
*/5 * * * * /usr/local/bin/watch-cloud-mount.sh
bash
# 设置 rclone 配置文件权限
chmod 600 ~/.config/rclone/rclone.conf
# 不要将配置文件上传到代码仓库
# 添加到 .gitignore
echo ".config/rclone/rclone.conf" >> ~/.gitignore
bash
# 仅当前用户可访问
MOUNT_OPTIONS="--daemon --vfs-cache-mode writes"
# 多用户共享时(谨慎使用)
MOUNT_OPTIONS="--daemon --allow-other --uid 1000 --gid 1000"
bash
# 检查挂载状态
~/cloud-mount/scripts/check-mount.sh --all
# 查看服务日志
sudo journalctl -u cloud-mount --since "24 hours ago"
# 监控资源使用
ps aux | grep rclone
bash
# 备份 cloud-mount 配置(不包含 token)
tar -czf cloud-mount-config-backup.tar.gz \
~/.config/cloud-mount/config.sh \
~/cloud-mount/scripts/
# 注意:不要备份 rclone.conf(包含敏感 token)
文件说明scripts/mount-cloud.sh一键挂载脚本scripts/check-mount.sh状态检测脚本scripts/enable-autostart.sh开机自启脚本~/.config/cloud-mount/config.sh配置文件~/.config/rclone/rclone.confrclone 配置(含 token)
版本: 1.2.0
作者: LuckyYou (@Liqiuyue9597)
许可: MIT License
最后更新: 2026-03-21