关于 rclone

Rclone 是一个用于管理云存储上的文件的命令行程序。被称为“云存储的瑞士军刀”,Rclone可以将任何本地、云或虚拟文件系统挂载为 Windows、macOS、linux 和 FreeBSD 上的磁盘,并且还通过 SFTP、 HTTP、 WebDAV、 FTP和 DLNA为这些文件系统提供服务。配合alist还有许多玩法。

轻量云服务器的硬盘容量都比较低,几十G甚至十几G,因为我的onedrive容量有5x25T,挂载后可以大大缓解容量焦虑。

其次,阿里云,腾讯云等厂商服务器流入服务器的数据是不计入流量消耗的,并且流入数据(下载流量)的带宽一般都很大可以达到千兆,正好可以满足云盘文件的免费高速加载。

下载安装

首先,使用以下命令下载并安装Rclone:

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

初始化配置
安装完成后输入:

rclone config

可以看到:

[root@racknerd ~]# rclone config
Current remotes:

Name                 Type
====                 ====
OneDrive                 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> 

输入 n 新建配置。

name 你可以随意输入,比如"my-onedrive"。(上面显示的名称),

然后会出现挂载的服务类型,如下:

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, ArvanCloud, Ceph, China Mobile, Cloudflare, GCS, DigitalOcean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, IONOS Cloud, Liara, Lyve Cloud, Minio, Netease, Petabox, 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, Blomp Cloud Storage, Memset Memstore, OVH)
   \ (swift)
34 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
35 / Pcloud
   \ (pcloud)
36 / PikPak
   \ (pikpak)
37 / Put.io
   \ (putio)
38 / QingCloud Object Storage
   \ (qingstor)
39 / SMB / CIFS
   \ (smb)
40 / SSH/SFTP
   \ (sftp)
41 / Sia Decentralized Cloud
   \ (sia)
42 / Storj Decentralized Cloud Storage
   \ (storj)
43 / Sugarsync
   \ (sugarsync)
44 / Transparently chunk/split large files
   \ (chunker)
45 / Union merges the contents of several upstream fs
   \ (union)
46 / Uptobox
   \ (uptobox)
47 / WebDAV
   \ (webdav)
48 / Yandex Disk
   \ (yandex)
49 / Zoho
   \ (zoho)
50 / premiumize.me
   \ (premiumizeme)
51 / seafile
   \ (seafile)
Storage> 

然后输入一个名称,

接下来,选择数字对应挂载的服务类型,输入数字 '31' 表示挂载OneDrive。

然后,client_id 和 client_secret 可以直接回车使用默认值。显示如下

Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id> 

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> 

选择OneDrive的区域,输入数字 '1' 表示全球。根据你的账户地区选,会影响网盘资源加载速度

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 Vnet Group in China
   \ (cn)
region> 

翻译

请按Enter键选择默认选项(全球)。
 1 / 微软云 全球
   \ (全球)
 2 / 微软云 美国政府
   \ (美国)
 3 / 微软云 德国
   \ (德国)
 4 / 由中国 Vnet 集团运营的 Azure 和 Office 365
   \ (中国)

接着会询问是否进行高级配置,输入 'n' 不进行高级配置。

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

自动配置选择,如下,输入 n :

Remote config
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

接着选择授权认证方式,由于是vps无图形界面选n,用命令行工具:

Use web browser to automatically authenticate rclone with remote?
 * Say Y if the machine running rclone has a web browser you can use #如果运行rclone的机器有可用的Web浏览器,请输入 Y
 * Say N if running rclone on a (remote) machine without web browser access #如果您在(远程)机器上运行rclone且无法访问Web浏览器,请输入 N
If not sure try Y. If Y failed, try N.

y) Yes (default)
n) No
y/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.
config_token> 

授权码需要在本地电脑上获取,访问 https://rclone.org/downloads/ 根据你的电脑系统版本下载对应的 Rclone。

下载完成后解压,进入存放 Rclone 的目录,以 Win11 为例,打开 Powershell ,我的 Rclone 放在 D:\下载\rclone-v1.55.0-windows-amd64 ,可以输入:

cd D:\下载\rclone-v1.55.0-windows-amd64

或者

Snipaste_2023-08-08_06-16-39.png

在存放 Rclone 的目录可以看到 rclone.exe 的可执行程序,输入:

./rclone authorize "onedrive"

./ 表示在当前目录下查找 rclone 可执行文件并运行它。

浏览器应该会自动打开,如果浏览器没有打开可以根据提示复制地址访问。如果浏览器登录了 OneDrive 的话会直接显示授权确认信息,如果没有登录的话会弹出登录页面,登录 OneDrive 后也会显示授权确认信息,如下:

Snipaste_2023-08-08_06-20-08.png

登陆后显示Success!All done. Please go back to rclone.返回黑框界面,选择 接受 后在本地命令行会显示一串 JSON 格式的授权信息,复制授权信息包括首尾的 {} ,复制箭头内的值粘贴到vps ssh终端

machine --->
adfhd...
<---End paste

接着选择 OneDrive 的类型,如下:

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 账户,如下:

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 (b!doqOBsuYCUyA3u7pVxBdNx0PVjTJsdfzsdMVxWwWIV8odGjdfxgdfeE).
1 / OneDrive (business)
\ (b!doqOBsuYCUyA3u7pVxBdNx0PVxe-UaMVxWwWIV8odGj1RcgdfsnK7EjeE)
config_driveid>

输入1对应账户

接着输入y 再次确认

Drive OK?

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

y) Yes (default)
n) No
y/n> 

显示配置完成,输入y,再次确认ok

Configuration complete.
Options:
- type: onedrive
- token: {"access_token":"eyJ0eXAiOiJnOCJ9LCJ4bXNfdGBZ-2VeoupN4iBI6m1VPldQj07rvVKT7vGQWFWIV8odGj1RZzaqnK7EjeE
- drive_type: business
Keep this "gg" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 

挂载

输入

rclone mount configName:OneDriveLocation dir --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

其中的 configName 就是配置名称,OneDriveLocation 就是要挂载的 OneDrive 目录,dir 就是要挂载到的本地目录

如需创建新文件夹和显示当前目录路径

mkdir new_folder #在当前路径创建新文件夹

pwd   #显示当前目录路径

例如我要把一个名为 OneDrive 的配置挂载到本地的 /OneDrive 目录,可以这样写:

rclone mount OneDrive:/ /OneDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

这里挂载的是整个 OneDrive 网盘,所以我写的是 OneDrive 的根目录 / 。

解释如下:

rclone mount: 这是 rclone 的一个子命令,用于将云存储服务挂载到本地目录。

configName:OneDriveLocation: 这是具体的挂载参数,其中 configName 是指您事先在 rclone
中配置的 OneDrive 的名称,OneDriveLocation 是在 OneDrive 上的路径,表示您要挂载的 OneDrive
的具体位置。

dir: 这是本地目录,表示将 OneDrive 挂载到本地的哪个目录。

以下是命令中使用的选项的解释:

--copy-links: 如果 OneDrive 中存在链接(symlink),则复制链接而不是解析它们。

--no-gzip-encoding: 禁止对文件进行 gzip 编码。

--no-check-certificate: 禁止检查 SSL 证书。

--allow-other: 允许其他用户(非挂载命令的用户)访问和操作挂载的文件系统。

--allow-non-empty: 允许挂载到非空目录。如果您要将 OneDrive 挂载到一个非空目录,需要使用这个选项。

--umask 000: 设置挂载目录的文件权限掩码为 000,意味着挂载的文件和目录对所有用户都具有完全的权限。

挂载完成后不会显示任何内容,可以再开一个终端,输入 df -h 查看系统磁盘空间,如下:

[root@racknerd-7a5ad7 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
devtmpfs        909M     0  909M    0% /dev
tmpfs           919M   16K  919M    1% /dev/shm
tmpfs           919M  104M  816M   12% /run
tmpfs           919M     0  919M    0% /sys/fs/cgroup
/dev/vda1        23G  5.9G   16G   28% /
tmpfs           184M     0  184M    0% /run/user/0
gg:             5.0T   62G  5.0T    2% /onepan #5T容量的硬盘已经挂载到系统

在宝塔面板显示:

Snipaste_2023-08-08_07-12-14.png

挂载完成后进入挂载的目录就可以看到 OneDrive 的文件了,上传文件可以直接拷贝到挂载目录,下载也是直接拷贝到本地目录,相当于系统硬盘。

挂载失败

2023/08/08 06:48:29 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount3": executable file not found in $PATH

这个错误表示 fusermount3 可执行文件没有在系统的可执行文件搜索路径($PATH)中找到。这通常发生在某些系统上,缺少 FUSE(Filesystem in Userspace)工具包。

解决:安装FUSE

对于 Ubuntu/Debian 等基于APT的系统:

sudo apt-get update
sudo apt-get install fuse

对于 CentOS/RHEL 等基于YUM的系统:

sudo yum install fuse

仍然失败

Running transaction
  正在安装    : fuse-2.9.2-11.el7.x86_64                                                                                                                                                                             1/1 
  验证中      : fuse-2.9.2-11.el7.x86_64                                                                                                                                                                             1/1 

已安装:
  fuse.x86_64 0:2.9.2-11.el7                                                                                                                                                                                             

完毕!
[root@racknerd-7a5ad7 ~]# rclone mount gg:/  /onepan --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
2023/08/08 06:55:16 NOTICE: OneDrive root '': --vfs-cache-mode writes or full is recommended for this remote as it can't stream
2023/08/08 06:55:16 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount3": executable file not found in $PATH

可以看到安装fuse后仍然显示"fusermount3"软件缺失,继续安装对应版本即可

对于 CentOS/RHEL 等基于YUM的系统:

sudo yum install fuse3

对于 Ubuntu/Debian 等基于APT的系统:

sudo apt-get install fuse3

加载速度测试

使用 dd 命令来测试读取速度。可以使用如下命令

time dd if=/mnt/source/testfile of=/mnt/destination/testfile bs=1M

解释这个命令:

time: 这是一个 Linux 命令,用于测量命令的执行时间。

dd: 用于复制文件并进行块级别的操作。

if=/mnt/source/testfile1: 要移动的文件的路径testfile1。改为挂载盘的文件为实际的文件路径。如/onepan/vedio/第5季/01.mp4

of=/mnt/destination/testfile2: 移动文件的目标路径并将其命名为testfile2。如/onepan/01.mp4

bs=1M: 指定每次读取/写入的块大小为 1MB。

运行命令后,time 命令会显示执行 dd 命令所花费的时间,以及已读/写入的字节数。
从显示的输出中,您可以计算出移动文件的速度。将已读/写入的字节数除以时间(秒)并转换为 MB/s 即可得到速度。例如:

Speed = (已读/写入的字节数) / (时间秒数) / 1024 / 104 MB/s

实际结果

tmp620E.png

2MB/s还是比较慢的,可能和我的onedrive账户地区有关

我的vps是美国1G带宽的,用speedtest工具测一下速

[root@racknerd-7a5ad7 ~]# speedtest-cli
Retrieving speedtest.net configuration...
Testing from ColoCrossing (192.3.53.177)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Kansas Research and Education Network (Wichita, KS) [43.14 km]: 55.547 ms
Testing download speed................................................................................
Download: 91.48 Mbit/s
Testing upload speed......................................................................................................
Upload: 72.80 Mbit/s

服务器厂商网络没啥问题

应用

大文件管理和直播需求: 我有7x24小时推流直播的需求,需要数量比较多的视频,有的视频可以达到2.3个G,1080p的视频2000k码率的推流直播,实际的推流效果还是可以的,解决了我视频素材没空间放的痛点,直播相关可以翻一翻之前文章

解决文件上传问题: 将大文件上传到远程服务器可能会遇到速度慢和断点问题。通过挂载,您可以避免直接上传大文件,而是通过本地挂载点操作远程文件,这在一定程度上解决了上传的问题。当然挂载alist再上传同样快

数据备份: 可以写个脚本;自动备份数据库,以及网站根目录文件,自动复制到网盘目录,达到自动远程备份的目的,之前有写过关于博客备份脚本的文章,感兴趣的朋友可以自己翻一翻

还有其他的思路玩法欢迎评论留言!

分类: 建站探索 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录