使用Azure面板建立私有api,用Rclone连接并挂载OneDrive盘,并解决vfs-cache-mode报错问题
本文最后更新于 503 天前,其中的信息可能已经有所发展或是发生改变。

参考

Microsoft OneDrive (rclone.org)
rclone mount
https://cnboy.org/archives/911
https://cnboy.org/archives/955

起因

做这个的起因是因为彩虹社6期主播Maria Marionette的b站字幕组组长clf找我搞自动录播,他正好联系上了有E5开发者订阅的佬,就没有再去考虑保存本地使用Cloudreve作为前端访问。

5TB的云盘这把想必也得白嫖x

直接把od盘挂载到服务器上,录播直接保存在挂载点上,访问直接用od原先的那个面板,使用链接分享就可以了,方便还稳定。

关于自动录播上传的构建应该还会写一篇简单思路。

olive这个自动录播的项目很不错,项目作者人也很好,咱提出了几个issue都得到了很好的解决。

正文

参照官方文档使用Azure面板自建私有api

以下是Rclone官方文档中关于自建私有api的教程,使用了下Google翻译。

Microsoft OneDrive (rclone.org)

获取您自己的客户端 ID 和密钥

rclone 在与 OneDrive 通信时使用默认客户端 ID,除非client_id在配置中指定了自定义。执行请求时,所有 rclone 用户共享默认的 Client ID 和 Key。

您可以选择创建和使用您自己的客户 ID,以防默认的客户 ID 不适合您。例如,您可能会看到节流。

为 OneDrive Personal 创建客户端 ID

要创建您自己的客户 ID,请按照以下步骤操作:

  1. 打开https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade然后单击New registration
  2. 为您的应用输入一个名称,选择帐户类型Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox),选择Webin Redirect URI,然后输入(不要复制和粘贴)http://localhost:53682/并单击注册。复制并保留Application (client) ID在应用名称下以供以后使用。
  3. manage选择下Certificates & secrets,单击New client secret。输入描述(可以是任何内容)并设置Expires为 24 个月。复制并保留该秘密以供以后使用(之后您将无法看到此值)。
  4. manage选择下API permissions,单击Add a permission并选择,Microsoft Graph然后选择delegated permissions
  5. 搜索并选择以下权限:Files.ReadFiles.ReadWriteFiles.Read.AllFiles.ReadWrite.All、和(如果配置了自定义访问范围,请相应地选择权限)offline_access。选择后点击底部。User.ReadSites.Read.AllAdd permissions

现在申请已经完成。运行rclone config以创建或编辑 OneDrive 远程。分别提供应用 ID 和密码作为 Client ID 和 Secret。rclone 将引导您完成剩余的步骤。

使用 rclone config 命令向导式配置时如果在client_idclient_secret处留空,也是可以正常使用的,但这样是使用的rclone默认的共享api。

因为rclone和OneDrive使用人数庞大,很容易造成微软限制api的使用,导致速度慢等问题,也就是上方提到的

For example, you might see throtting.

所以自建api的目的就是为了更好的上传体验。

那么按照以上的教程照着做就完全可以了,感觉以上不够直观明了可以看

https://cnboy.org/archives/955

保存好client_idclient_secret就可以开始配置远程连接OneDrive了。

使用Rclone连接OneDrive盘

Rclone的安装过程看 Install 就好了,一行命令的事

To install rclone on Linux/macOS/BSD systems, run:

sudo -v ; curl https://rclone.org/install.sh | sudo bash

也可以先看看官方文档

Microsoft OneDrive (rclone.org)

#这个网址Edge总是报不安全,个人觉得没啥问题。感觉和微软不想再让人刷私有api有关系x

以下是我的连接过程,参考 https://cnboy.org/archives/911

#下面会比较长,着重看 # 后面的内容就可可以

root@highsunlightlee:~# rclone config
2022/08/18 00:50:55 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #输入n,新建远程硬盘

Enter name for new remote.
name> DF7F #这里输入给od盘起的名字就行了,这里随便写一个

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, Digital Ocean, Dreamhost, Huawei O, IBM COS, IDrive e2, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS 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 / Hubic
   \ (hubic)
24 / In memory object storage system.
   \ (memory)
25 / Internet Archive
   \ (internetarchive)
26 / Jottacloud
   \ (jottacloud)
27 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
28 / Local Disk
   \ (local)
29 / Mail.ru Cloud
   \ (mailru)
30 / Mega
   \ (mega)
31 / Microsoft Azure Blob Storage
   \ (azureblob)
32 / Microsoft OneDrive
   \ (onedrive)
33 / OpenDrive
   \ (opendrive)
34 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
35 / Pcloud
   \ (pcloud)
36 / Put.io
   \ (putio)
37 / QingCloud Object Storage
   \ (qingstor)
38 / SSH/SFTP
   \ (sftp)
39 / Sia Decentralized Cloud
   \ (sia)
40 / Storj Decentralized Cloud Storage
   \ (storj)
41 / Sugarsync
   \ (sugarsync)
42 / Transparently chunk/split large files
   \ (chunker)
43 / Union merges the contents of several upstream fs
   \ (union)
44 / Uptobox
   \ (uptobox)
45 / WebDAV
   \ (webdav)
46 / Yandex Disk
   \ (yandex)
47 / Zoho
   \ (zoho)
48 / premiumize.me
   \ (premiumizeme)
49 / seafile
   \ (seafile)
Storage> 32 #选32,Microsoft OneDrive。这个序号经常会换,因为Rclone会逐渐支持连接更多种类的盘,所以要观察好。

Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id>  #输入在Azure面板新建私有api的client_id

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret>  #输入在证书与密钥给api新建的client_secret值

Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
 1 / Microsoft Cloud Global
   \ (global)
 2 / Microsoft Cloud for US Government
   \ (us)
 3 / Microsoft Cloud Germany
   \ (de)
 4 / Azure and Office 365 operated by 21Vianet in China
   \ (cn)
region> 1 #选择地区,这里因为服务器在美国就选了global

Edit advanced config?
y) Yes
n) No (default)
y/n> n #输入n,不要高级配置

Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
y/n> n #输入n #输入n,不要自动配置

Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
	rclone authorize "onedrive" "##############################################################"
Then paste the result.
Enter a value.
#翻译下大意
#配置令牌选项
#你需要在一个能运行网页浏览器和rclone的电脑
#寻求帮助和查找替代方法请看https://rclone.org/remote_setup/
#先打开浏览器,再执行下面的命令(这一步推荐使用相同的rclone版本)

#其实就普通的Windows系统电脑就可以轻松解决。去GitHub上下个为Windows用的rclone,解压
#然后在解压下的目录鼠标右键运行命令行也就是cmd,再输入上面给你的命令
#然后浏览器会跳转到微软的登录界面,正常登录要连接的那个OneDrive账号
#然后确认授权,就可以在命令行里看到获取到的令牌了
#这一步也可以看可以看看 https://cnboy.org/archives/955
#获取令牌运行的命令不一样但是殊途同归,我已经测试过了
config_token> #把刚才复制下来的token粘贴下来就可以了,还有token会很长,不要感到奇怪x
Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (onedrive).
 1 / OneDrive Personal or Business
   \ (onedrive)
 2 / Root Sharepoint site
   \ (sharepoint)
   / Sharepoint site name or URL
 3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
   \ (url)
 4 / Search for a Sharepoint site
   \ (search)
 5 / Type in driveID (advanced)
   \ (driveid)
 6 / Type in SiteID (advanced)
   \ (siteid)
   / Sharepoint server-relative path (advanced)
 7 | E.g. /teams/hr
   \ (path)
config_type> 1 # 这里问你要选择的类型,因为是使用 OneDrive ,所以输入 1

Option config_driveid.
Select drive you want to use
Choose a number from below, or type in your own string value.
Press Enter for the default (############################).
 1 / OneDrive (business)
   \ (#############################)
config_driveid> 1 #检测到对应的网盘,输入对应的编号1

Drive OK?

Found drive "root" of type "business"
URL: https://############-my.sharepoint.com/personal/############/Documents

y) Yes (default)
n) No
y/n> y #这里确认是符合自己情况的,输入y

Configuration complete.
Options:
- type: onedrive
- client_id: 
- client_secret: 
- token: 
- drive_type: business
Keep this "DF7F" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y #列出网盘的配置信息,核对正确后输入y

Current remotes:

Name                 Type
====                 ====
DF7F                 onedrive

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 #到这里已经连接完毕,直接输入q退出配置就可以了

至于挂载和开机自动挂载可以看 https://cnboy.org/archives/911 ,咱就不班门弄斧了。

vfs-cache-mode 报错解决

这里写一下我挂载时遇到的问题和解决方法。

挂载中途有报错

2022/08/07 18:44:49 NOTICE: One drive root 'rclone': --vfs-cache-mode writes or full is recommended for this remote as it can't stream

大抵是讲此远程硬盘(即要挂载的OneDrive盘)无法支持流式传输,推荐使用vfs缓存的 writes 或 full 模式。

正好想起刚才看到的Rclone文档 rclone mount 的VFS – Virtual File System部分

以下经过Google翻译插件翻译

VFS – 虚拟文件系统

此命令使用 VFS 层。这将 rclone 使用的云存储对象改编成看起来更像磁盘文件系统的东西。

云存储对象有很多与磁盘文件不同的属性——你不能扩展它们或写入它们的中间,所以 VFS 层必须处理这些。因为没有一种正确的方法可以做到这一点,所以下面解释了各种选项。

VFS 层还实现了目录缓存——这将有关文件和目录(但不包括数据)的信息缓存在内存中。

VFS 文件缓存

这些标志控制 VFS 文件缓存选项。文件缓存对于使 VFS 层看起来与普通文件系统兼容是必要的。可以以牺牲一些兼容性为代价禁用它。

例如,如果要同时读取和写入文件,则需要启用 VFS 缓存。请参阅下面的更多细节。

请注意,VFS 缓存与缓存后端是分开的,您可能会发现需要一个或另一个或两者。

--cache-dir string                   Directory rclone will use for caching.
--vfs-cache-mode CacheMode           Cache mode off|minimal|writes|full (default off)
--vfs-cache-max-age duration         Max age of objects in the cache (default 1h0m0s)
--vfs-cache-max-size SizeSuffix      Max total size of objects in the cache (default off)
--vfs-cache-poll-interval duration   Interval to poll the cache for stale objects (default 1m0s)
--vfs-write-back duration            Time to writeback files after last use when using cache (default 5s)

缓存有 4 种不同的模式选择--vfs-cache-mode。缓存模式越高,rclone 就越兼容,但会以使用磁盘空间为代价。

–vfs-cache-mode writes

在这种模式下,只读打开的文件仍然直接从远程读取,只写和读/写文件首先缓冲到磁盘。

这种模式应该支持所有正常的文件系统操作。

如果上传失败,它将以指数增加的间隔重试,最多 1 分钟。

–vfs-cache-mode full

在这种模式下,所有读取和写入都缓冲到磁盘和从磁盘缓冲。当从远程读取数据时,它也会缓冲到磁盘。

在这种模式下,缓存中的文件将是稀疏文件,rclone 将跟踪它已下载的文件的哪些位。

因此,如果应用程序只读取每个文件的开头,那么 rclone 将只缓冲文件的开头。这些文件将在缓存中显示为它们的完整大小,但它们将是稀疏文件,其中仅存在已下载的数据。

此模式应支持所有正常的文件系统操作,否则与--vfs-cache-mode写入相同。

读取文件时,rclone 会提前读取--buffer-sizeplus --vfs-read-ahead字节。--buffer-size缓冲在内存中,而缓冲--vfs-read-ahead在磁盘上。

使用此模式时,建议--buffer-size不要设置太大,--vfs-read-ahead如果需要设置大。

重要事项并非所有文件系统都支持稀疏文件。特别是 FAT/exFAT 没有。如果缓存目录位于不支持稀疏文件的文件系统上,Rclone 的性能将非常糟糕,如果检测到,它将记录一条错误消息。

根据实际需求,我感觉 –vfs-cache-mode writes 就已经能满足使用了。

https://cnboy.org/archives/911 中老哥给的挂载命令中加一条 –vfs-cache-mode writes 选项就可以了,完美解决。

$ rclone mount DF7F:/rclone /onedrive --vfs-cache-mode writes --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

这里注意一下,挂载成功控制台是不会有输出的,如果有输出基本是报错。

这里如果还想连接上服务器就要重新启动一个SSH连接

然后可以输入一个 df -h 命令看查是否挂载成功

root@highsunlightlee:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 448M 0 448M 0% /dev
tmpfs 99M 12M 87M 12% /run
/dev/vda1 39G 14G 24G 37% /
tmpfs 491M 384K 491M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 491M 0 491M 0% /sys/fs/cgroup
tmpfs 99M 0 99M 0% /run/user/0
DF7F:rclone 5.0T 333G 4.7T 7% /onedrive

看到了上面挂载的名为DF7F的Onedrive盘,这样就成功了

总结

因为好长时间没搞Linux,再加上没接触过rclone和OneDrive相关的东西,其实这个花费了我挺长时间来研究的,包括写这篇博客。

得到的经验就是多查多看多思考,潜心钻研,充满耐心。尤其是要认真读官方文档,再搭配其他的个人博客一起看,从多角度来看一个问题,会使问题变得立体化,更具体,也更容易理解其原理。

这样过程虽慢但毕竟理解了原理,相信会对以后的研究提供帮助罢。

希望这篇博客能给你带来帮助,转载请注明链接。

封面来自すしめかぶ老师的夏のキミ

暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇