标签 rclone 下的文章

本教程适用于将 Microsoft 365 E5 开发者订阅(MSDN)的 5TB OneDrive 空间挂载为 Linux 本地磁盘。当然也适用其他版本的空间挂载,但是需要自己根据实际情况做出修改。

请输入图片描述

一、 基础准备在开始之前,请确保你拥有 MSDN 管理员账号,并在 Linux 服务器上安装 fuse3(挂载必需依赖)。

# 1. 安装 Rclone
curl https://rclone.org/install.sh | sudo bash
# 2. 安装 FUSE 依赖
# Ubuntu / Debian:
apt update && apt install -y fuse3
# CentOS / AlmaLinux:
yum install -y fuse3
# 3. 修正 FUSE 权限配置(允许非 root 用户访问)
sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf

二、 Rclone 配置步骤

执行 rclone config
按照以下逻辑操作:n) New remote: 输入名称 onedrive
Storage Type: 输入 42 (Microsoft OneDrive)
client_id/client_secret: 直接回车跳过
region: 输入 1 (global)
Edit advanced config: 输入 n
Use auto config: 输入 n (因为是远程服务器)获取
Token:在你的本地电脑

  • (Windows/Mac)下载 Rclone。
  • 在本地终端运行:rclone authorize "onedrive"
  • 浏览器弹出授权,登录 MSDN 账号并确认。
  • 将本地终端生成的 {"access_token":...} 整个 JSON 字符串复制。回到服务器粘贴。

config_type: 输入 1 (OneDrive Personal or Business)
Drive Selection: 搜索到 5TB 盘后,输入序号 0。
Confirm: 输入 y 确认,最后输入 q 退出。

三、 手动挂载测试创建挂载点并尝试手动挂载,确认没有报错:

# 创建挂载点
mkdir -p /mnt/onedrive

# 手动挂载命令(测试用)
rclone mount onedrive:/ /mnt/onedrive \
  --vfs-cache-mode writes \
  --vfs-cache-max-size 50G \
  --allow-other \
  --header "Referer:https://onedrive.live.com/" \
  --vfs-read-chunk-size 16M \
  --vfs-read-chunk-size-limit 1G \
  --buffer-size 64M \
  --daemon

使用 df -h 查看是否出现了 5TB 的磁盘。

四、 配置开机自动挂载 (Systemd)为了保证服务器重启后自动挂载,建议配置系统服务。

1. 创建服务文件

nano /etc/systemd/system/rclone.service

2. 粘贴以下内容(请确保 /usr/bin/rclone 路径正确,可用 which rclone 查看)

[Unit]
Description=Rclone OneDrive Mount
After=network-online.target

[Service]
Type=simple
# 核心挂载命令
ExecStart=/usr/bin/rclone mount onedrive:/ /mnt/onedrive \
    --vfs-cache-mode writes \
    --vfs-cache-max-size 50G \
    --vfs-cache-max-age 24h \
    --allow-other \
    --header "Referer:https://onedrive.live.com/" \
    --vfs-read-chunk-size 16M \
    --vfs-read-chunk-size-limit 1G \
    --buffer-size 64M \
    --dir-cache-time 5m \
    --low-level-retries 10
# 停止时卸载
ExecStop=/bin/fusermount3 -qzu /mnt/onedrive
Restart=on-failure
RestartSec=10
User=root

[Install]
WantedBy=multi-user.target

3. 启用服务

//先卸载之前手动挂载的路径
fusermount3 -qzu /mnt/onedrive
//启用并启动服务
systemctl daemon-reload
systemctl enable rclone
systemctl start rclone
//检查状态
systemctl status rclone

五、 常用维护指令汇总

目的                        命令

验证 5TB 容量 rclone about onedrive:
查看实时挂载日志 journalctl -u rclone -f
重启挂载服务 systemctl restart rclone
强制卸载挂载点 fusermount3 -qzu /mnt/onedrive
清空 OneDrive 回收站 建议去网页端操作,可释放 Trashed 占用的配额

突然想用一个简单的方法可以直接修改cloudflare R2储存的html和txt文件,想了一下用rclone+宝塔面板或许更简单,于是开始了这部分内容,这里只是把r2储存挂载到服务器的步骤……
全篇文章均是以debian/ubuntu为主,其他系统自行替换安装命令……

安装 rclone

Debian / Ubuntu:

curl https://rclone.org/install.sh | bash

创建 R2 的配置

执行:

rclone config

选择:n 新建一个,这里仔细对照一下括号内的内容

n) New remote
name: r2
然后依次:(以下内容要自己仔细看哟)
Storage: s3(Amazon S3 Compliant Storage Providers including AWS……)
provider: Cloudflare(Cloudflare R2 Storage)
env_auth: false(Enter AWS credentials in the next step.)
access_key_id: <你的R2 Access Key>
secret_access_key: <你的R2 Secret Key>
region: auto(1)
endpoint: https://12*****f799e.r2.cloudflarestorage.com

到这里基本就算搞定了

Configuration complete.
Options:
- type: s3
- provider: Cloudflare
- access_key_id: e141d989a****dfbff4da9
- secret_access_key: 649fcef77cd84a45e29b66c****71003188e01f0417
- region: auto
- endpoint: https://122393bf79ab9****ba1ef799e.r2.cloudflarestorage.com
Keep this "r2" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 

选择Y

然后q) Quit config

创建挂载目录

mkdir -p /mnt/r2

安装 rclone FUSE 支持(必须)
Debian / Ubuntu:

apt install fuse3 -y

CentOS:

yum install fuse -y

fusermount -u /mnt/r2 2>/dev/null
rclone mount r2:你的r2bucket(如我这里是img那么就是img) /mnt/r2 --allow-other --vfs-cache-mode full --daemon

测试是否获取成功

ls -lah /mnt/r2

设置开机自启动(我是设置的一个脚本然后添加到启动项)

通过rc.local设置自启动

创建启动脚本

nano /usr/local/bin/rclone_r2_mount.sh

写入:

#!/bin/bash

# 延迟,防止网络未完全启动
sleep 10

/usr/bin/rclone mount r2:你的r2bucket /mnt/r2 \
    --allow-other \
    --vfs-cache-mode full \
    --vfs-cache-max-age 24h \
    --vfs-cache-max-size 1G \
    --dir-cache-time 12h \
    --poll-interval 5m \
    --log-file /var/log/rclone-r2.log \
    --log-level INFO &

保存:Ctrl+X → Y → Enter

赋予执行权限:

chmod +x /usr/local/bin/rclone_r2_mount.sh

编辑 rc.local

nano /etc/rc.local

如果不存在,创建:

内容如下:

#!/bin/bash
/usr/local/bin/rclone_r2_mount.sh &
exit 0

保存 → 赋权(这一步也许有些不需要操作):
chmod +x /etc/rc.local

通过systemctl设置自启动

创建启动文件
nano /etc/systemd/system/rclone-r2.service

内容如下

[Unit]
Description=rclone-r2-mount
After=network-online.target

[Service]
Type=simple
User=root
# 这里的 r2:image 对应你刚才创建的配置名和桶名
ExecStart=/usr/bin/rclone mount r2:你的r2bucket /mnt/r2 \
  --allow-other \
  --vfs-cache-mode writes \
  --vfs-cache-max-age 24h \
  --vfs-cache-max-size 10G \
  --config /root/.config/rclone/rclone.conf
# 停止时自动卸载,防止挂载点残留
ExecStop=/bin/fusermount -qzu /mnt/r2
Restart=on-failure

[Install]
WantedBy=multi-user.target

启动并设置自启动

# 重新加载配置
systemctl daemon-reload

# 启动服务
systemctl start rclone-r2

# 设置开机自启
systemctl enable rclone-r2