OBS 网盘搭建教程

用过百度、阿里、坚果云,要不就是存储空间流量不够,要不就是速度存在限制。自己摸索出来一个比较好用的个人云盘方案:OBS对象存储+Rclone同步文件(支持PC全平台)+BucketAnywhere 获取文件(安卓)。这个方案不需要你有自己的服务器,只需要买云厂商提供的对象存储即可使用,目前华为云 OBS 40G 一年的存储价格只需要 9 块钱(流量另外计费,我自己日常使用下来流量费一个月1-2元),都快去给我薅羊毛!!

如果你有自己的服务器,推荐使用 owncloud, nextcloud 或者 seafile 搭建私有云,可以自动同步+网页端文件修改,之后有机会出一期私有云的搭建教程。下面就来具体聊聊怎么用OBS+Rclone搭建个人云盘。

OBS 购买

华为云 OBS 计费说明,购买标准存储单AZ存储包(9元 特价资源包,过期后可再次购买),在控制台创建桶(选择靠近的区域,单AZ,标准,私有,不加密)。

obs create guide

购买完成之后在总览页面获取密钥,注意密钥只能获取一次,请自行记录。此外还需要获取Endpoint的网址,点击桶列表下创建的桶即可看到。至此已经完成了购买与配置,之后不需要登录网站了。

(华东-上海一的 Endpoint: obs.cn-east-3.myhuaweicloud.com)

obs aksk obs endpoint

Rclone 使用

下载 Rclone

官方链接,选择自己对应的平台,有 Windows, Linux, macOS。Rclone是命令行的形式来使用的,可以加入环境变量以方便使用。

配置 Rclone

$ rclone config
Current remotes:

Name                 Type
====                 ====


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 (新建 remote)

Enter name for new remote.
name> mycloud

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
    (fichier)
 2 / Akamai NetStorage
    (netstorage)
 3 / Alias for an existing remote
    (alias)
 4 / Amazon Drive
    (amazon cloud drive)
 5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, China Mobile, Cloudflare, ArvanCloud, DigitalOcean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, IONOS Cloud, Liara, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS, Qiniu and Wasabi
    (s3)
 6 / Backblaze B2
    (b2)
 7 / Better checksums for other remotes
    (hasher)
 8 / Box
    (box)
 9 / Cache a remote
    (cache)
10 / Citrix Sharefile
    (sharefile)
11 / Combine several remotes into one
    (combine)
12 / Compress a remote
    (compress)
13 / Dropbox
    (dropbox)
14 / Encrypt/Decrypt a remote
    (crypt)
15 / Enterprise File Fabric
    (filefabric)
16 / FTP
    (ftp)
17 / Google Cloud Storage (this is not Google Drive)
    (google cloud storage)
18 / Google Drive
    (drive)
19 / Google Photos
    (google photos)
20 / HTTP
    (http)
21 / Hadoop distributed file system
    (hdfs)
22 / HiDrive
    (hidrive)
23 / In memory object storage system.
    (memory)
24 / Internet Archive
    (internetarchive)
25 / Jottacloud
    (jottacloud)
26 / Koofr, Digi Storage and other Koofr-compatible storage providers
    (koofr)
27 / Local Disk
    (local)
28 / Mail.ru Cloud
    (mailru)
29 / Mega
    (mega)
30 / Microsoft Azure Blob Storage
    (azureblob)
31 / Microsoft OneDrive
    (onedrive)
32 / OpenDrive
    (opendrive)
33 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
    (swift)
34 / Oracle Cloud Infrastructure Object Storage
    (oracleobjectstorage)
35 / Pcloud
    (pcloud)
36 / Put.io
    (putio)
37 / QingCloud Object Storage
    (qingstor)
38 / SMB / CIFS
    (smb)
39 / SSH/SFTP
    (sftp)
40 / Sia Decentralized Cloud
    (sia)
41 / Storj Decentralized Cloud Storage
    (storj)
42 / Sugarsync
    (sugarsync)
43 / Transparently chunk/split large files
    (chunker)
44 / Union merges the contents of several upstream fs
    (union)
45 / Uptobox
    (uptobox)
46 / WebDAV
    (webdav)
47 / Yandex Disk
    (yandex)
48 / Zoho
    (zoho)
49 / premiumize.me
    (premiumizeme)
50 / seafile
    (seafile)
Storage> s3

Option provider.
Choose your S3 provider.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / Amazon Web Services (AWS) S3
    (AWS)
 2 / Alibaba Cloud Object Storage System (OSS) formerly Aliyun
    (Alibaba)
 3 / Ceph Object Storage
    (Ceph)
 4 / China Mobile Ecloud Elastic Object Storage (EOS)
    (ChinaMobile)
 5 / Cloudflare R2 Storage
    (Cloudflare)
 6 / Arvan Cloud Object Storage (AOS)
    (ArvanCloud)
 7 / DigitalOcean Spaces
    (DigitalOcean)
 8 / Dreamhost DreamObjects
    (Dreamhost)
 9 / Huawei Object Storage Service
    (HuaweiOBS)
10 / IBM COS S3
    (IBMCOS)
11 / IDrive e2
    (IDrive)
12 / IONOS Cloud
    (IONOS)
13 / Seagate Lyve Cloud
    (LyveCloud)
14 / Liara Object Storage
    (Liara)
15 / Minio Object Storage
    (Minio)
16 / Netease Object Storage (NOS)
    (Netease)
17 / RackCorp Object Storage
    (RackCorp)
18 / Scaleway Object Storage
    (Scaleway)
19 / SeaweedFS S3
    (SeaweedFS)
20 / StackPath Object Storage
    (StackPath)
21 / Storj (S3 Compatible Gateway)
    (Storj)
22 / Tencent Cloud Object Storage (COS)
    (TencentCOS)
23 / Wasabi Object Storage
    (Wasabi)
24 / Qiniu Object Storage (Kodo)
    (Qiniu)
25 / Any other S3 compatible provider
    (Other)
provider> 9

Option env_auth.
Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).
Only applies if access_key_id and secret_access_key is blank.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
 1 / Enter AWS credentials in the next step.
    (false)
 2 / Get AWS credentials from the environment (env vars or IAM).
    (true)
env_auth> false


Option access_key_id.
AWS Access Key ID.
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
access_key_id> xxxxxxx

Option secret_access_key.
AWS Secret Access Key (password).
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
secret_access_key> xxxxxxxxx


Option region.
Region to connect to. - the location where your bucket will be created and your data stored. Need bo be same with your endpoint.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / AF-Johannesburg
    (af-south-1)
 2 / AP-Bangkok
    (ap-southeast-2)
 3 / AP-Singapore
    (ap-southeast-3)
 4 / CN East-Shanghai1
    (cn-east-3)
 5 / CN East-Shanghai2
    (cn-east-2)
 6 / CN North-Beijing1
    (cn-north-1)
 7 / CN North-Beijing4
    (cn-north-4)
 8 / CN South-Guangzhou
    (cn-south-1)
 9 / CN-Hong Kong
    (ap-southeast-1)
10 / LA-Buenos Aires1
    (sa-argentina-1)
11 / LA-Lima1
    (sa-peru-1)
12 / LA-Mexico City1
    (na-mexico-1)
13 / LA-Santiago2
    (sa-chile-1)
14 / LA-Sao Paulo1
    (sa-brazil-1)
15 / RU-Moscow2
    (ru-northwest-2)
region> 4

Option endpoint.
Endpoint for OBS API.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / AF-Johannesburg
    (obs.af-south-1.myhuaweicloud.com)
 2 / AP-Bangkok
    (obs.ap-southeast-2.myhuaweicloud.com)
 3 / AP-Singapore
    (obs.ap-southeast-3.myhuaweicloud.com)
 4 / CN East-Shanghai1
    (obs.cn-east-3.myhuaweicloud.com)
 5 / CN East-Shanghai2
    (obs.cn-east-2.myhuaweicloud.com)
 6 / CN North-Beijing1
    (obs.cn-north-1.myhuaweicloud.com)
 7 / CN North-Beijing4
    (obs.cn-north-4.myhuaweicloud.com)
 8 / CN South-Guangzhou
    (obs.cn-south-1.myhuaweicloud.com)
 9 / CN-Hong Kong
    (obs.ap-southeast-1.myhuaweicloud.com)
10 / LA-Buenos Aires1
    (obs.sa-argentina-1.myhuaweicloud.com)
11 / LA-Lima1
    (obs.sa-peru-1.myhuaweicloud.com)
12 / LA-Mexico City1
    (obs.na-mexico-1.myhuaweicloud.com)
13 / LA-Santiago2
    (obs.sa-chile-1.myhuaweicloud.com)
14 / LA-Sao Paulo1
    (obs.sa-brazil-1.myhuaweicloud.com)
15 / RU-Moscow2
    (obs.ru-northwest-2.myhuaweicloud.com)
endpoint> 4


Option acl.
Canned ACL used when creating buckets and storing or copying objects.
This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.
For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Note that this ACL is applied when server-side copying objects as S3
doesn't copy the ACL from the source but rather writes a fresh one.
If the acl is an empty string then no X-Amz-Acl: header is added and
the default (private) will be used.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
   / Owner gets FULL_CONTROL.
 1 | No one else has access rights (default).
    (private)
   / Owner gets FULL_CONTROL.
 2 | The AllUsers group gets READ access.
    (public-read)
   / Owner gets FULL_CONTROL.
 3 | The AllUsers group gets READ and WRITE access.
   | Granting this on a bucket is generally not recommended.
    (public-read-write)
   / Owner gets FULL_CONTROL.
 4 | The AuthenticatedUsers group gets READ access.
    (authenticated-read)
   / Object owner gets FULL_CONTROL.
 5 | Bucket owner gets READ access.
   | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
    (bucket-owner-read)
   / Both the object owner and the bucket owner get FULL_CONTROL over the object.
 6 | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
    (bucket-owner-full-control)
acl>

Edit advanced config?
y) Yes
n) No (default)
y/n> n

Configuration complete.
Options:
- type: s3
- provider: HuaweiOBS
- access_key_id: xxxxxxx
- secret_access_key: xxxxxxx
- region: cn-east-3
- endpoint: obs.cn-east-3.myhuaweicloud.com
Keep this "mycloud" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>

Current remotes:

Name                 Type
====                 ====
mycloud              s3


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> q

除了上述交互式的配置,也可以直接写入配置文件,如下:

[mycloud]
type = s3
provider = HuaweiOBS
access_key_id = xxxxxxx
secret_access_key = xxxxxxxx
region = cn-east-3
endpoint = obs.cn-east-3.myhuaweicloud.com

不同平台上Rclone 的配置相同,不需要修改,所以交互式配置好后,可以直接复制配置文件到其他电脑上使用,配置完成之后测试是否能够使用 Rclone,如果输出你的文件夹即配置成功:

$ rclone lsd mycloud:
          -1 2023-02-26 19:06:35        -1 YourBucketName

同步文件

接下来就可以愉快的同步文件了,首先准备好你想要同步的文件,放在一个文件夹中(这里用 _YourFolderName_ 代替文件夹的名称,和创建的桶的名称最好保持一致)。因为有40G的空间,所以基本上常用的文件都能够放下。准备好文件后执行上传命令(上传流量是不计费的):

rclone sync -P YourFolderName YourBucketName
例: rclone sync -P awacloud mycloud:awacloud

等待上传成功,OBS基本上能跑满你的上行下行带宽,晚上放在那边跑就好。因为 Rclone 会计算文件的大小、修改时间或者哈希值,进而增量上传,所以之后你修改文件再上传只用传修改的文件。

其他设备的同步:因为OBS下载流量是计费的,所以推荐首先使用移动硬盘或者U盘,将文件拷贝到其他设备,之后再用Rclone实现同步。Rclone也能在电脑和移动硬盘中使用,相当于是两个本地的文件夹的同步。

一台设备上传文件到OBS后,另一台设备就能同步OBS中的文件了:

rclone sync -P YourBucketName YourFolderName
rclone sync -i YourBucketName YourFolderName 
最好用 -i 交互式同步检查文件是否需要同步
例(上面指令调换文件夹顺序): rclone sync -i mycloud:awacloud awacloud

Rclone因为是手动同步的,和一些云服务自动同步不太一样,所以每次在一个地方修改好文件之后一定要记得上传,然后另一个设备使用的时候要记得手动同步一下。手动同步的好处就是更加灵活,自己想同步就同步,带宽占用小,还能防止使用文件时同步带来的冲突。

其他设备在同步之前,我一般都会执行指令来看看什么文件被修改了,这样防止其它设备有文件修改被同步覆盖掉:

rclone check --size-only YourBucketName YourFolderName
例:
rclone check --size-only D:requentFiles mycloud:awacloud/frequentFiles
2023/04/21 10:23:55 NOTICE: S3 bucket awacloud path frequentFiles: 0 differences found
2023/04/21 10:23:55 NOTICE: S3 bucket awacloud path frequentFiles: 8087 matching files

挂载盘符

mount 是 Rclone 比较强大的功能之一,可以直接把云存储挂载到本地盘符,使用起来和本地文件没太大区别。不过需要注意的是Rclone挂载的时候,不要在其他设备上上传文件,Rclone 一般不会在挂载的设备上同步这些文件。

Windows 挂载

安装 WinFsp,创建缓存文件夹 `_cache_dir_`,用以下指令挂载:

rclone mount YourBucketName * --buffer-size 100M --cache-dir cache_dir --vfs-cache-mode full
例:rclone mount mycloud:awacloud/ * --buffer-size 100M --cache-dir G:cache --vfs-cache-mode full
rclone mount mycloud:awacloud/ * --network-mode --buffer-size 100M --cache-dir G:cache --vfs-cache-mode full

缓存文件夹是必须的,没有的话写入文件会报错。其他系统挂载方式也比较类似,Linux 不需要安装额外软件,可以指定文件夹挂载,具体请参考官方文档

安卓设备

使用 BucketAnywhere 下载需要的文件。配置非常简单。

结语

和平时使用的云服务不同,Rclone有更强大的文件同步能力,除了同步 S3,它还能同步很多服务(50种,包括Sftp等)。但是因其是一个命令行工具,使用上没有公有云盘提供的可视化客户端来的方便,不过可以自己写一些脚本来方便每次的同步,下面放一些我平时使用的比较多的指令,具体使用方法请参考官方文档

rclone config
rclone check --size-only
rclone sync -i
rclone sync -P
rclone copy -i
rclone copy -P
rclone mount *