用 rclone 把 R2 绑定到本地目录
突然想用一个简单的方法可以直接修改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
设置开机自启动(我是设置的一个脚本然后添加到启动项)
创建启动脚本
nano /usr/local/bin/rclone_r2_mount.sh
写入:
#!/bin/bash
# 延迟,防止网络未完全启动
sleep 10
/usr/bin/rclone mount r2:image /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