Lxn-Chan!

(~ ̄▽ ̄)→))* ̄▽ ̄*)o

在 Linux 下安装 rclone 并挂载 cloudflare r2 及相关的常用使用命令。包括能够ls但上传提示403的问题解决。

安装

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

配置

创建Key

登录Cloudflare Dashboard后,左侧选Storage & databases,R2 Object Storage,Overview,右下角API Tokens,Manage,点击Create User API Token创建。

然后能拿到一对Access Key ID和Secret Access Key。

配置

  1. rclone config进入交互配置,
  2. n创建新配置,
  3. s3选择Amazon S3 Compliant Storage Providers,
  4. Cloudflare选择Cloudflare,
  5. 输入上面获取到的access_key_idsecret_access_key
  6. region填auto
  7. endpoint在你获取key的界面有,忘了的话也不要紧,在bucket界面可以看到,去掉后面的bucket名即可,
  8. 高级设置跳过即可

403问题解决

开启-vv(调试)后可以看到rclone上来会先检测桶存在不存在,不存在的话会新建,但是r2又没有给新建桶的权限(和s3不太一样),就会报403。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@iZ6we6eiagycug2y8qcx25Z:~# rclone copy install.sh r2:/lxnchan-r2-bucket-main/install.sh -vv
2026/07/17 16:45:54 DEBUG : rclone: Version "v1.74.4" starting with parameters ["rclone" "copy" "install.sh" "r2:/lxnchan-r2-bucket-main/install.sh" "-vv"]
2026/07/17 16:45:54 DEBUG : Creating backend with remote "install.sh"
2026/07/17 16:45:54 DEBUG : Using config file from "/root/.config/rclone/rclone.conf"
2026/07/17 16:45:54 DEBUG : fs cache: renaming child cache item "install.sh" to be canonical for parent "/root"
2026/07/17 16:45:54 DEBUG : Creating backend with remote "r2:/lxnchan-r2-bucket-main/install.sh"
2026/07/17 16:45:55 DEBUG : fs cache: renaming cache item "r2:/lxnchan-r2-bucket-main/install.sh" to be canonical "r2:lxnchan-r2-bucket-main/install.sh"
2026/07/17 16:45:55 DEBUG : install.sh: Need to transfer - File not found at Destination
2026/07/17 16:45:55 ERROR : install.sh: Failed to copy: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 ERROR : Attempt 1/3 failed with 1 errors and: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 DEBUG : install.sh: Need to transfer - File not found at Destination
2026/07/17 16:45:55 ERROR : install.sh: Failed to copy: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 ERROR : Attempt 2/3 failed with 1 errors and: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 DEBUG : install.sh: Need to transfer - File not found at Destination
2026/07/17 16:45:55 ERROR : install.sh: Failed to copy: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 ERROR : Attempt 3/3 failed with 1 errors and: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied
2026/07/17 16:45:55 INFO :
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.4s

2026/07/17 16:45:55 DEBUG : 5 go routines active
2026/07/17 16:45:55 NOTICE: Failed to copy: failed to prepare upload: operation error S3: CreateBucket, https response error StatusCode: 403, RequestID: , HostID: , api error AccessDenied: Access Denied

解决方法的话也很简单,每次上传前添加--s3-no-check-bucket参数或修改配置文件添加:

1
no_check_bucket = true

常用命令

  • 查看桶内对象
    1
    2
    rclone ls r2:lxnchan-r2-bucket-main
    rclone lsl r2:lxnchan-r2-bucket-main/path
  • 查看桶或目录大小
    1
    rclone size r2:lxnchan-r2-bucket-main/path
  • 查看目录结构
    1
    rclone tree r2:lxnchan-r2-bucket-main
  • 上传单个文件到桶根目录
    1
    rclone copy install.sh r2:lxnchan-r2-bucket-main -P
  • 上传到指定目录
    1
    rclone copy ./dist r2:lxnchan-r2-bucket-main/releases -P
  • 上传到精确的对象路径
    1
    rclone copyto install.sh r2:lxnchan-r2-bucket-main/install.sh -P
  • 下载文件
    1
    rclone copyto r2:lxnchan-r2-bucket-main/install.sh ./install.sh -P
  • 下载目录
    1
    rclone copy r2:lxnchan-r2-bucket-main/releases ./releases -P
  • 移动文件或目录
    1
    rclone move ./dist r2:lxnchan-r2-bucket-main/releases -P
  • 删除指定路径下的对象
    1
    rclone delete r2:lxnchan-r2-bucket-main/releases
  • 删除单个对象
    1
    rclone deletefile r2:lxnchan-r2-bucket-main/install.sh
  • 删除整个目录前缀
    1
    rclone purge r2:lxnchan-r2-bucket-main/releases
    purge 会删除路径下的全部对象,使用前建议先测试:
    1
    rclone purge r2:lxnchan-r2-bucket-main/releases --dry-run
  • 本地同步到 R2
    1
    rclone sync ./dist r2:lxnchan-r2-bucket-main/releases --dry-run -P
  • 确认无误后执行
    1
    rclone sync ./dist r2:lxnchan-r2-bucket-main/releases -P
    注意:sync 会删除目标端多余的文件。生产环境建议始终先使用 –dry-run。
  • 比较本地和远程
    1
    rclone check ./dist r2:lxnchan-r2-bucket-main/releases
  • 显示进度
    1
    -P
  • 详细日志
    1
    -vv

 简单说两句



联系站长 | 服务状态 | 友情链接

备案号:辽ICP备19013963号

津公网安备12011602300394号

中国互联网违法和不良信息举报中心

架构版本号:8.2.2 | 本站已全面支持IPv6

正在载入运行数据(1/2)请稍后...
正在载入运行数据(2/2)请稍后...

O to die advancing on!

Copyright 2024 LingXuanNing, All rights reserved.