rclone-r2
非常好 👍
你现在的目标是:
把 Cloudflare R2(已配置成功的图床)挂载到本地电脑上,用 rclone 实现文件系统访问和管理。
下面是完整、详细的 rclone 配置 + 挂载步骤,适用于 Fedora 或任何 Linux 系统。
🧩 一、确认你的 R2 信息
你应该已经有以下信息(在 Cloudflare R2 控制台里能看到):
| 项目 | 示例 |
|---|---|
| Account ID | 11112222333344445555666677778888 |
| Access Key ID | R2_ACCESS_KEY |
| Secret Access Key | R2_SECRET_KEY |
| Bucket 名称 | my-bucket |
| 自定义域名(可选) | https://img.luoxingding.com |
| R2 Endpoint | https://<AccountID>.r2.cloudflarestorage.com |
⚙️ 二、安装 rclone
Fedora 上:
sudo dnf install rclone -y
验证版本:
rclone version
🪣 三、配置 R2 远程存储
运行:
rclone config
然后按提示操作:
1️⃣ 选择 n → New remote
2️⃣ 输入名称,比如:r2
3️⃣ 选择存储类型:
Storage> s3
4️⃣ 设置 provider → 输入:
provider = Cloudflare
5️⃣ 输入 Access Key ID / Secret:
env_auth = false
access_key_id = R2_ACCESS_KEY
secret_access_key = R2_SECRET_KEY
6️⃣ 设置 endpoint:
endpoint = https://<ACCOUNT_ID>.r2.cloudflarestorage.com
7️⃣ region 可以留空(回车即可)
8️⃣ 其余选项默认回车
9️⃣ 最后输入 y 确认保存配置。
完成后,可以测试:
rclone ls r2:my-bucket
若能列出文件,就成功了 ✅
🗂️ 四、挂载 R2 到本地目录
假设你想挂载到 /mnt/r2:
sudo mkdir -p /mnt/r2
挂载命令如下(推荐使用 --vfs-cache-mode writes 以支持写入):
rclone mount r2:my-bucket /mnt/r2 \
--vfs-cache-mode writes \
--allow-other \
--dir-cache-time 72h \
--poll-interval 5m \
--umask 002 \
--daemon
💡
--daemon会让 rclone 挂载在后台运行。
验证是否成功挂载:
df -h | grep r2
ls /mnt/r2
🧰 五、设置开机自动挂载(systemd 服务)
创建一个 systemd 单元文件:
sudo nano /etc/systemd/system/rclone-r2.service
内容如下:
[Unit]
Description=Mount Cloudflare R2 via rclone
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/rclone mount r2:my-bucket /mnt/r2 \
--vfs-cache-mode writes \
--allow-other \
--dir-cache-time 72h \
--poll-interval 5m \
--umask 002
ExecStop=/bin/fusermount -u /mnt/r2
Restart=on-failure
User=ding
[Install]
WantedBy=multi-user.target
然后启用并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable rclone-r2
sudo systemctl start rclone-r2
💡 六、挂载后使用建议
-
/mnt/r2下的内容就是你 Cloudflare R2 的 bucket 内容。 -
你可以直接拖放文件、用文件管理器、命令行、PicGo 或任何应用操作。
-
推荐只作为上传查看管理用途,不建议直接编辑大型文件(因 VFS 延迟)。
-
如需自动同步,可用:
rclone sync ~/Pictures r2:my-bucket
✅ 七、可选:用自定义域名访问验证
如果你在 Cloudflare R2 绑定了自定义域名(例如 https://img.luoxingding.com),
可通过浏览器访问任意对象,例如:
https://img.luoxingding.com/test.jpg
来验证上传的文件可正常访问。
是否希望我帮你直接生成一份适合你现有域名与 bucket 的完整 rclone.conf 配置文件模板(可直接复制粘贴)?
如果你告诉我:
-
R2 的 Account ID
-
Bucket 名称
-
Access Key ID
-
Secret Key
我会为你生成最终配置文件内容。
[ding@ArchLinux ~]$ rclone config file
Configuration file is stored at:
/home/ding/.config/rclone/rclone.conf
[ding@ArchLinux ~]$
rclone config
4 > 6 >
参考资料
https://rclone.cn/
Linux 下使用 Rclone 将本地文件复制到 Cludflare R2 存储桶中
https://senjianlu.com/2024/10/20/linux_rclone_cloudflare_r2/