如何备份存储一直是痛点,网盘可以完美解决这个问题,而且不用多花钱买存储vps,之前发过一次,但是当时的配置只能支持路径式的s3存储,大多数网站的s3存储都是主机式网址的s3存储的,为了优化这一点,重新调整了所有设置。前提,你有一台服务器,一个Google drive 2T白嫖账号。在服务器上搭建了rclone服务,并且挂载了google drive

一、设置rclone系统服务

1
sudo nano /etc/systemd/system/rclone-s3.service
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[Unit]
Description=Rclone S3 Service for Google Drive
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/rclone serve s3 \
  --addr 0.0.0.0:10000 \
  --auth-key yourAccess key ID,yourSecret Key \
  --etag-hash md5 \
  --force-path-style=false \
  googledrive:
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

主要变量含义

  • Type=simple: 服务类型为简单类型,进程在前台运行
  • User=root: 以 root 用户身份运行服务
  • ExecStart: 服务启动时执行的命令,包含以下 Rclone 参数:
  • /usr/bin/rclone serve s3 googledrive:s3: 使用 Rclone 将 Google Drive 作为 S3 服务提供
  • googledrive: 这是在 Rclone 配置文件中定义的远程存储配置名称,s3是 Google Drive 中的一个文件夹路径
  • addr 0.0.0.0:10000: 监听所有网络接口的 10000 端口
  • auth-key: S3 认证密钥对(Access Key 和 Secret Key)
  • etag-hash md5: 使用 MD5 作为 ETag 哈希算法
  • Restart=on-failure: 服务失败时自动重启
  • RestartSec=10: 重启前等待 10 秒

保存,启动服务,查看服务状态

1
2
3
sudo systemctl daemon-reload
sudo systemctl restart rclone-s3
sudo systemctl status rclone-s3

二、优化反向代理设置

你要设置DNS服务器(cf),1panel反向代理,

1
s3.888888.xyz

*.s3.888888.xyz

全部指向你的服务器IP,并且申请函盖着两个域名的证书, 以1panel为例 修改 /opt/1panel/apps/openresty/openresty/www/sites/s3.888888.xyz/proxy/root.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
location / {
    # 直接反代到 rclone S3 网关
    proxy_pass http://localhost:10000;
    proxy_http_version 1.1;

    # 保留原始 Host 头,保证 S3 签名一致
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    # 上传大文件直传
    proxy_request_buffering off;
    proxy_buffering         off;
    client_max_body_size    500M;
}

三、S3存储桶主要参数

第一步设置存储桶,已经顺利完成。但是仅支持路径式的地址存储桶! 主要参数:

  • Access key ID:配置文件中第一个yourAccess key ID
  • Secret Key:配置文件中第二个yourSecret Key
  • Region:随便,比如us-east-1
  • Endpoint:你的反向代理的指向你的服务器的域名比如 https://s3.xxxx.com
  • Bucket:你设置的谷歌网盘下面的文件夹,每一个文件夹就是一个存储桶