R2需要依赖cloudflare的DNS,准备换对象存储了,把我的图床迁移到oss上去
连接与配置对象存储
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 操作环境: AlmaLinux release 9.5 yum -y install rclone rclone config n) New remote s) Set configuration password q) Quit config n/s/q> n name> r2 Storage> s3 provider> Cloudflare env_auth> false access_key_id> xxx secret_access_key> xxx region> auto endpoint> https://da2c2a71e23cbacf4d351c67aa6025ef.r2.cloudflarestorage.com location_constraint> APAC e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q> n name> oss Storage> s3 provider> Alibaba env_auth> false access_key_id> xxx secret_access_key> xxx endpoint> oss-cn-hangzhou.aliyuncs.com
验证是否连接成功
1 2 3 4 5 6 7 8 9 10 11 查看当前配置 rclone config show r2 rclone config show oss 尝试列出文件 [root@1panel oss] 0 2025 -02-20 18 :20 :07 -1 wangsheng [root@1panel oss] 0 2025 -02-20 18 :20 :15 -1 wangsheng 0 2025 -02-20 18 :20 :15 -1 ws-img.akemi.zj.cn
执行迁移
1 2 3 4 开始迁移 rclone copy r2:wangsheng/ oss:ws-blog-img/ -P -v 这里的wangsheng和ws-blog-img分别是我在r2和oss中的桶名
原链接修改
1 2 3 4 5 6 7 8 如果弃用cloudflare的DNS,必然以前的图片就无法使用了 所以我需要将我所有已经有的图片外链修改为新的格式 ws-img.akemi.zj.cn ↓ ws-blog-img.oss-cn-hangzhou.aliyuncs.com find ./ -type f -name '*.md' -exec sed -i 's#ws-img\.akemi\.zj\.cn#ws-blog-img.oss-cn-hangzhou.aliyuncs.com#g' {} \;
批量修改oss权限
1 2 3 4 5 6 迁移过来的图片全都是私有的 安装ossutil直接进行一手递归设置权限: ossutil set -acl oss://ws-blog-img public-read -r Do you really mean to recursivlly set acl on objects of oss://ws-blog-img(y or N)? y Succeed: Total 168 objects. Setted acl on 168 objects(skip 0 objects).