Rclone怎么挂载?Rclone挂载谷歌团队共享云盘远程同步

            文章目录

  • 1 如何安装Rclone?
  • 2 如何配置Rclone?
    • 2.1 如何选择远程Remote创建的类型?
    • 2.2 填写谷歌 Client Id & Client Secret
    • 2.3 如何选择操作权限?
    • 2.4 根目录如何设置?
    • 2.5 谷歌账号如何授权?
    • 2.6 是否配置谷歌团队共享云盘?
    • 2.7 如何选择要挂载的谷歌团队共享云端硬盘?
    • 2.8 核实remote配置信息
  • 3 如何将 Google 磁盘映射到文件夹?
  • 4 挂载谷歌网盘
    • 4.1 手动挂载
  • 5 Rclone挂载如何后台运行谷歌云端团队网盘?
  • 6 rclone如何开机自启动?
    • 6.1 设置rclone开机启动
  • 7 结语

如何把申请到的Google Driver团队盘挂载到自己的VPS服务器上,达到扩容和文件管理的目的?

Rclone怎么挂载?Rclone挂载谷歌团队共享云盘远程同步

全文唯一的难点就是Rclone创建远程,其中步骤多一点,但并不复杂和困难。

例如那些浮躁怕麻烦的人,表示都能应付,相信很多人都能驾驭。

如何安装Rclone?

使用官方安装脚本文件 ▼

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

输入命令测试是否安装成功 ▼

rclone
  • 显示的help信息,说明安装成功。

如何配置Rclone?

安装完成后,开始配置添加新的挂载开始▼

rclone config

如何选择远程Remote创建的类型?

看清楚后,选择 Google Drive 的选项。

不过,rclone更新后,可能选项数字会有变化。

因为连接的是谷歌团队云盘,所以这里选择13 ▼

Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / JottaCloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Transparently chunk/split large files
   \ "chunker"
32 / Union merges the contents of several remotes
   \ "union"
33 / Webdav
   \ "webdav"
34 / Yandex Disk
   \ "yandex"
35 / http Connection
   \ "http"
36 / premiumize.me
   \ "premiumizeme"
Storage> 13 # 选择13,看好是选Google Drive这个选项,rclone更新以后可能选项的数字会有变化
** See help for drive backend at: https://rclone.org/drive/ **

填写谷歌 Client Id & Client Secret

当然,如果觉得麻烦,可以直接按 Enter 并使用 RCLONE 自己的 Client Id 生成 remote配置。

然而,这有缺点,Rclone官方也表示。

因为ClientId和Client Secret使用率太高,很多人都在用。

Google 对每个客户端应用程序都有一个有限的流量,当一群人挤在一起使用它时会发生什么? 自己想象一下(每天最大流量750G)。

  • 所以,最好是自己注册谷歌客户端Google Api。
  • 接回车就行了,而且以后可以修改添加。

你先需要进入到Google  API中心创建一个项目获取一个API,应用类型就选择“桌面应用” ▼

你先需要进入到Google  API中心创建一个项目获取一个API,类型就选择“桌面应用” 第2张

Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> # 回车
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> # 回车

建议设置你自己的 Google 应用程序客户端 ID ▼

如何选择操作权限?

如果自己用的话,直接选1,获取所有权限 ▼

Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1 # 选1 回车

根目录如何设置?

不使用这个设置,直接回车 ▼

ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
root_folder_id> # 回车
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file> # 回车

Edit advanced config? (y/n)
y) Yes
n) No
y/n> 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
n) No
y/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 "drive" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Then paste the result.
Enter a value.
config_token>

这里的“config_token”,需要先在本地电脑上下载安装 Rclone 的方式获取 ▼

以Windows为例,解压后进入rclone.exe所在文件夹,在资源管理器地址栏中输入 cmd 回车,即可在当前路径打开命令提示符。

替换以下命令中的Client_IDClient_secret 并执行 ▼

rclone authorize "gdrive" "Client_ID" "Client_secret"
  • (此方式仅适合使用自己的 Client Id 生成 remote配置)

接下来会弹出一个浏览器,要求你登录你的帐户进行授权。

谷歌账号如何授权?

 

VPS如何使用rclone备份?CentOS使用GDrive自动同步教程 第4张

  1. 如果你在中国大陆,首先你要绕过X墙,然后需要有谷歌账号并登录。
  2. 若是出现“此应用未经谷歌验证”,请点击“高级”。
  3. 然后,点击允许授权。

授权后,命令提示符窗口中会出现以下消息:

If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxxxxxxxxxxxxxxxx","expiry":"2024-05-15T21:18:39.5036298+08:00"}
<---End paste
  • {"access_token":"xxxxxxxxxxxxxxxxxx","expiry":"2024-05-15T21:18:39.5036298+08:00"}这段全部内容(包括括号)是token,复制并保存。
  • 然后,将token粘贴到刚才上面要求输入 config_token> 的地方。

是否配置谷歌团队共享云盘?

因为使用的是谷歌团队共享云盘,当然选y ▼

Log in and authorize rclone for access
Enter verification code> 4/0AGPbXQ9thkw4XynGuNP91QxL4g9Mz7Rubv7M_lajOCwd8GqHuTlOzI
Configure this as a team drive?
y) Yes
n) No (default)
y/n> y

如何选择要挂载的谷歌团队共享云端硬盘?

谷歌团队共享云端硬盘就是一个文件夹,一个文件夹算一个团队盘。

因为我有两张团队盘,名为CWL-X,

所以,这里可以看到两个选项,一个remote配置只能绑定一个团队盘。

以后可多做几个remote,挂载这些团队盘。

Fetching team drive list...
Choose a number from below, or type in your own value
 1 / CWL-1
 \ "xxxx"
 2 / CWL-2
 \ "xxxx"
Enter a Team Drive ID> # 每个人都不一样,根据自己需求选择要绑定哪一个团队盘

核实remote配置信息

最后核实一下remote配置的各项参数,确认就敲个y就行 ▼

--------------------
[CWL-2]
type = drive
client_id = XXX
client_secret = XXX
scope = drive
token = XXX
team_drive = XXX
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

会显示当前机器上保存的romete列表,随便看看,按q退出 ▼

Current remotes:

Name                 Type
====                 ====
CWL-2                drive

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
  • 至此,Rclone配置完成。

在本地电脑配置好之后,直接把本地电脑的rclone.conf配置文件里的内容,复制到Linux服务器上rclone.conf配置文件。

分别在本地电脑和服务器上,输入以下命令可查看Rclone配置文件位置命令 ▼

rclone config file

查询Rclone配置文件,获取到的结果如下 ▼

rclone config file
Configuration file is stored at:
/root/.config/rclone/rclone.conf
  • 只需把本地电脑的配置文件rclone.conf里的内容,复制到Linux服务器上rclone.conf配置文件,就能够解决Rclone配置问题了。

如何将 Google 磁盘映射到文件夹?

Rclone 是一个命令行工具,支持在不同的对象存储和网盘之间同步、上传和下载数据。

并且通过一些设置,可以实现离线下载、服务器备份等非常实用的功能。

使用 Rclone 的方法有很多,挂载就是其中之一。

注意事项:挂载操作不是必须的。 作为一个实验性功能,它有很多限制和问题。 挂载后不能作为真正的磁盘使用。 进行文件操作时,使用本地磁盘进行缓存,即占用本地磁盘空间。

使用不当也可能造成磁盘满、VPS卡死等问题。在谷歌上搜索“Rclone”,最相关的关键词是“挂载”,这在一定程度上误导了很多新朋友。为稳定上传、下载、同步等操作,建议使用Rclone的原生命令功能。

挂载需要安装 fuse,根据自己的系统来选择安装命令:

# Debian/Ubantu
apt-get update && apt-get install -y fuse
# CentOS
yum install -y fuse

挂载谷歌网盘

挂载网盘分为手动挂载和开机自动挂载,根据自己的需求来选择。

手动挂载

#挂载
rclone mount <网盘名称:网盘路径> <本地路径> [参数] --daemon

#取消挂载
fusermount -qzu <本地路径>

找个舒适的位置创建空文件夹,mkdir 命令会用吧?不用教吧?

新建本地文件夹,路径自己定,即下面的LocalFolder ▼

mkdir /home/gdDisk/

# 挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding

# 例如:
rclone mount gdrive:VPS /home/gdDisk \
--no-check-certificate \
--no-gzip-encoding \
--copy-links \
--umask 0000 \
--default-permissions \
--allow-non-empty \
--allow-other \
--transfers 1 \
--buffer-size 64M \
--low-level-retries 200 \
--dir-cache-time 12h \
--vfs-read-chunk-size 32M \
--vfs-read-chunk-size-limit 1G


# 对部分参数解释一下
DriveName:就是之前用rclone创建remote的名称
Folder:自己定,也可以不改。凡是rclone上传的文件都会在该谷歌团队盘的下一个名为“Folder”的文件夹里
LocalFolder:本地的绝对路径 比如 /home/gdDisk

# 如果涉及到读取使用,比如使用H5等在线播放,就在后面多加上以下三条参数
--dir-cache-time 12h
--vfs-read-chunk-size 32M
--vfs-read-chunk-size-limit 1G

# 优化参数
--transfers:该参数是最大同时传输任务数量,如果经常传输大文件,或CPU性能不佳,建议设置为单线程,也就是设置为“1”
--buffer-size:该参数为读取每个文件时的内存缓冲区大小,控制rclone上传和挂载的时候的内存占用
--low-level-retries:该参数为传输文件没速度的时候重试次数,没速度的时候,单个会自动睡眠10ms起,然后再重试
-n = --dry-run - 测试运行,用来查看 rclone 在实际运行中会进行哪些操作。
-P = --progress - 显示实时传输进度,500mS 刷新一次,否则默认 1 分钟刷新一次。
--cache-chunk-size SizeSuffi - 块的大小,默认5M,理论上是越大上传速度越快,同时占用内存也越多。如果设置得太大,可能会导致进程中断。
--cache-chunk-total-size SizeSuffix - 块可以在本地磁盘上占用的总大小,默认10G。
--transfers=N - 并行文件数,默认为4。在比较小的内存的VPS上建议调小这个参数,比如128M的小鸡上使用建议设置为1。
--config string - 指定配置文件路径,string为配置文件路径。
--ignore-errors - 跳过错误。比如 OneDrive 在传了某些特殊文件后会提示Failed to copy: failed to open source object: malwareDetected: Malware detected,这会导致后续的传输任务被终止掉,此时就可以加上这个参数跳过错误。但需要注意 RCLONE 的退出状态码不会为0。

在终端输入mount命令并回车后,很多人以为卡住了。

其实并不是因为挂载程序是在前台运行的。

这时候再打开一个终端或者ssh输入命令查看映射是否成功 ▼

df -h

就可以看到你挂载的谷歌云端硬盘,大小为1PB ▼

### 文件上传
rclone copy /home/backup gdrive:backup  # 本地路径 配置名字:网盘文件夹路径
### 文件下载
rclone copy gdrive:backup /home/backup  # 配置名字:网盘文件夹路径 本地路径
### 新建文件夹
rclone mkdir gdrive:backup              # 配置名字:网盘文件夹路径
### 获取文件夹大小
rclone size gdrive:backup               # 配置名字:网盘文件夹路径

### 列表
rclone ls gdrive:backup
rclone lsl gdrive:backup # 比上面多一个显示上传时间
rclone lsd gdrive:backup # 只显示文件夹
### 挂载
rclone mount gdrive:mm /root/mm &
### 卸载
fusermount -u  /root/mm

#### 其他 ####
rclone config - 以控制会话的形式添加rclone的配置,配置保存在.rclone.conf文件中。
rclone copy - 将文件从源复制到目的地址,跳过已复制完成的。
rclone sync - 将源数据同步到目的地址,只更新目的地址的数据。   –dry-run标志来检查要复制、删除的数据
rclone move - 将源数据移动到目的地址,如果要在移动后删除空源目录,请加上 --delete-empty-src-d
rclone delete - 删除指定路径下的文件内容。
rclone purge - 清空指定路径下所有文件数据。
rclone mkdir - 创建一个新目录。
rclone rmdir - 删除空目录。
rclone rmdirs - 删除指定灵境下的空目录。如果加上 --leave-root 参数,则不会删除根目录。
rclone check - 检查源和目的地址数据是否匹配。
rclone ls - 列出指定路径下所有的文件以及文件大小和路径。
rclone lsd - 列出指定路径下所有的目录/容器/桶。
rclone lsl - 列出指定路径下所有文件以及修改时间、文件大小和路径。
rclone lsf - 列出指定路径下所有文件和目录
rclone md5sum - 为指定路径下的所有文件产生一个md5sum文件。
rclone sha1sum - 为指定路径下的所有文件产生一个sha1sum文件。
rclone size - 获取指定路径下,文件内容的总大小。.
rclone version - 查看当前版本。
rclone cleanup - 清空remote。
rclone dedupe - 交互式查找重复文件,进行删除/重命名操作。
fusermount -qzu 挂载网盘的文件夹绝对路径 - 取消挂载网盘,不用了以后一定要取消哦。

Rclone挂载如何后台运行谷歌云端团队网盘?

挂载为磁盘,加&保持后台运行 ▼

rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &
  • 说明一下:rclone mount 你之前填写的谷歌团队云盘的名称:团队盘里任意存在的目录名 /root/Gdrive 指的是刚才新建的本地挂载目录的路径,--则是挂载方式, &是后台运行

supervisor

  • 任何可以后台运行的方法都可以做到。
supervisor
  • 好棒,复杂但是功能强大。

nohup

  • 搜索nphup的用法,满大街都是。
nohup
  • 后面是要执行的命令,注意&前后的空格。

screen

一般linux系统都会自带screen,如果没有安装,使以下命令 ▼

sudo apt-get install screen

或者 CentOS 的命令▼

sudo yum install screen

新建一个名为CWL-1的窗口,在窗口中执行命令 ▼

screen -S CWL-1 rclone mount CWL-2:RXFiles /home/ gdDisk/CWL-2
  • 后面有一堆参数。
  • 建议创建一个sh文件来管理screen,这个扩展名就不再赘述了。

卸载 ▼

fusermount-qzu LocalFolder
  • 此处示例为fusermount -qzu /root/Gdrive

rclone如何开机自启动?

systemctl

新建一个rclone.server文件,Linux系统中:

vim /lib/systemd/system/rclone.service

写入以下内容:

#### https://www.chenweiliang.com/cwl-1966.html
[Unit]
Description=rclone

[Service]
User=root
ExecStart=/usr/bin/rclone mount DriveName:RemoteFolder LocalFolder --allow-other --allow-non-empty --vfs-cache-mode writes --config /home/br/.config/rclone/rclone.conf
Restart=on-abort

[Install]
WantedBy=multi-user.target
  • 注意修改DriveName、RemoteFolder和LocalFolder的值。

然后重载daemon,使新的服务生效 ▼

systemctl daemon-reload

设置rclone开机启动

开机自启动rclone ▼

systemctl enable rclone

启动rclone ▼

systemctl start rclone

重启rclone ▼

systemctl restart rclone

停止rclone ▼

systemctl stop rclone

查询rclone状态 ▼

systemctl status rclone

结语

Rclone挂载谷歌团队共享云盘非常方便,尤其是在同步备份上,可以轻松同步网站的数据。

而且如果你有多个谷歌谷歌团队共享云盘,你也可以使用Rclone相互复制文件。

  • Rclone 支持挂载基本上是国外的网盘。
  • Rclone 的 SFTP 挂载也可以用作备份工具。
  • 如果有中国大陆VPS想用,可以用SFTP、FTP、HTTP挂载,整合不同的服务器存储。
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注

×
订阅图标按钮