Rclone实现GoogleDrive等多网盘挂载给vps变相扩容!搭配FileBrowser更香哦~
科技玩家LAzySheep
2022年04月19日 12:15

背景:最近沉迷于网盘学习,无法自拔。暂时没有研究羊毛的东西,各位玩家不要喷我。在学习搭建Filebrowser的过程中,了解到了Rclone这个工具,可以实现多网盘挂载。然后通过FileBrowser就能完美实现多网盘聚合分享!感觉特别Cool,立马上手体验了。简单记录一下自己的搭建过程。

Rclone简单介绍

官方文档:https://rclone.org/ 项目地址:https://github.com/rclone/rclone

Rclone 是一个命令行程序,用于管理云存储上的文件,可以通过 HTTP、WebDAV、FTP、SFTP 或 DLNA 服务本地或远程文件。支持多平台网盘同步、上传/下载、网盘互传等功能。

功能性

  • 挂载/同步不同云盘数据;

  • 不同云盘之间数据传递等;

支持性:

  • 支持Windows、Mac、Linux安装;

  • 支持主流网盘GoogleDrive、OneDrive、Dropbox等;

我只是根据常用场景重点列出几个,更多功能见官方文档。接下来开始认真码字。

解题思路

安装Rclone👉配置Rclone👉搭配FileBowser

准备工作:1、服务器;2、已有GoogleDrive、OneDrive等云盘

我的运行环境:甲骨文Linux系统(Arm)+宝塔+Docker

服务器安装好宝塔和Docker。

安装Rclone

ssh工具链接服务器,切换root身份sudo -i使用官方一键安装命令。稍等一会儿,直到提示安装成功。

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

配置Rclone

配置命令rclone config,进入配置流程。具体可见官方文档,这里暂时演示挂载GoogleDriveOneDrive后面补。

配置GoogleDrive

初次配置会生成一个配置文件在/config/rclone.conf。请留意注释部分,是需要手动抉择的时候!

一、授权链接GoogleDrive

  1. rclone config

  2. 2022/01/23 20:50:11 NOTICE: Config file "/config/rclone.conf" not found - using defaults

  3. No remotes found - make a new one

  4. n) New remote

  5. s) Set configuration password

  6. q) Quit config

  7. n/s/q> n #输入n,创建一个新的。

  8. name> GDrive #给新盘创建一个名称

当你看到教程的时候,Rclone可能已经更新,选择项目序号可能发生变化,请不要无脑照抄哦。

  1. Option Storage.

  2. Type of storage to configure.

  3. Enter a string value. Press Enter for the default ("").

  4. Choose a number from below, or type in your own value.

  5. 1 / 1Fichier

  6. \ "fichier"

  7. 2 / Alias for an existing remote

  8. \ "alias"

  9. 3 / Amazon Drive

  10. \ "amazon cloud drive"

  11. 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS

  12. \ "s3"

  13. 5 / Backblaze B2

  14. \ "b2"

  15. 6 / Better checksums for other remotes

  16. \ "hasher"

  17. 7 / Box

  18. \ "box"

  19. 8 / Cache a remote

  20. \ "cache"

  21. 9 / Citrix Sharefile

  22. \ "sharefile"

  23. 10 / Compress a remote

  24. \ "compress"

  25. 11 / Dropbox

  26. \ "dropbox"

  27. 12 / Encrypt/Decrypt a remote

  28. \ "crypt"

  29. 13 / Enterprise File Fabric

  30. \ "filefabric"

  31. 14 / FTP Connection

  32. \ "ftp"

  33. 15 / Google Cloud Storage (this is not Google Drive)

  34. \ "google cloud storage"

  35. 16 / Google Drive

  36. \ "drive"

  37. 17 / Google Photos

  38. \ "google photos"

  39. 18 / Hadoop distributed file system

  40. \ "hdfs"

  41. 19 / Hubic

  42. \ "hubic"

  43. 20 / In memory object storage system.

  44. \ "memory"

  45. 21 / Jottacloud

  46. \ "jottacloud"

  47. 22 / Koofr

  48. \ "koofr"

  49. 23 / Local Disk

  50. \ "local"

  51. 24 / Mail.ru Cloud

  52. \ "mailru"

  53. 25 / Mega

  54. \ "mega"

  55. 26 / Microsoft Azure Blob Storage

  56. \ "azureblob"

  57. 27 / Microsoft OneDrive

  58. \ "onedrive"

  59. 28 / OpenDrive

  60. \ "opendrive"

  61. 29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)

  62. \ "swift"

  63. 30 / Pcloud

  64. \ "pcloud"

  65. 31 / Put.io

  66. \ "putio"

  67. 32 / QingCloud Object Storage

  68. \ "qingstor"

  69. 33 / SSH/SFTP Connection

  70. \ "sftp"

  71. 34 / Sia Decentralized Cloud

  72. \ "sia"

  73. 35 / Sugarsync

  74. \ "sugarsync"

  75. 36 / Tardigrade Decentralized Cloud Storage

  76. \ "tardigrade"

  77. 37 / Transparently chunk/split large files

  78. \ "chunker"

  79. 38 / Union merges the contents of several upstream fs

  80. \ "union"

  81. 39 / Uptobox

  82. \ "uptobox"

  83. 40 / Webdav

  84. \ "webdav"

  85. 41 / Yandex Disk

  86. \ "yandex"

  87. 42 / Zoho

  88. \ "zoho"

  89. 43 / http Connection

  90. \ "http"

  91. 44 / premiumize.me

  92. \ "premiumizeme"

  93. 45 / seafile

  94. \ "seafile"

  95. Storage> 16 #选择16,GoogleDrive

  96. Option client_id.

  97. Google application Client Id

  98. Setting your own is recommended.

  99. See https://rclone.org/drive/#making-your-own-client-id for how to create your own.

  100. If you leave this blank, it will use an internal key which is low performance.

  101. Enter a string value. Press Enter for the default ("").

  102. client_id> #留空,按键盘Enter(解决卡顿内存高的问题,可以添加自己网盘的id)

  103. Option client_secret.

  104. OAuth Client Secret.

  105. Leave blank normally.

  106. Enter a string value. Press Enter for the default ("").

  107. client_secret> #留空,按键盘Enter(解决卡顿内存高的问题,可以添加自己网盘的密钥)

给足权限

  1. Option scope.

  2. Scope that rclone should use when requesting access from drive.

  3. Enter a string value. Press Enter for the default ("").

  4. Choose a number from below, or type in your own value.

  5. 1 / Full access all files, excluding application Data Folder.

  6. \ "drive"

  7. 2 / Read-only access to file metadata and file contents.

  8. \ "drive.readonly"

  9. / Access to files created by rclone only.

  10. 3 | These are visible in the drive website.

  11. | File authorization is revoked when the user deauthorizes the app.

  12. \ "drive.file"

  13. / Allows read and write access to the application Data folder.

  14. 4 | This is not visible in the drive website.

  15. \ "drive.appfolder"

  16. / Allows read-only access to file metadata but

  17. 5 | does not allow any access to read or download file content.

  18. \ "drive.metadata.readonly"

  19. scope> 1 #选择1,让Rclone具有对网盘的完全访问权限

  1. Option root_folder_id.

  2. ID of the root folder.

  3. Leave blank normally.

  4. Fill in to access "Computers" folders (see docs), or for rclone to use

  5. a non root folder as its starting point.

  6. Enter a string value. Press Enter for the default ("").

  7. root_folder_id> #留空,按键盘Enter

  8. Option service_account_file.

  9. Service Account Credentials JSON file path.

  10. Leave blank normally.

  11. Needed only if you want use SA instead of interactive login.

  12. Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.

  13. Enter a string value. Press Enter for the default ("").

  14. service_account_file>

  15. Edit advanced config?

  16. y) Yes

  17. n) No (default)

  18. y/n> n #输入n,不修改高级配置

  19. Use auto config?

  20. * Say Y if not sure

  21. * Say N if you are working on a remote or headless machine

  22. y) Yes (default)

  23. n) No

  24. y/n> n #输入n,不使用自动配置

1)复制验证链接到浏览器打开

  1. Option config_verification_code.

  2. Verification code

  3. Go to this URL, authenticate then paste the code here.

  4. https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=XXX #复制弹出的链接到浏览器打开

  5. Enter a string value. Press Enter for the default ("").

  6. config_verification_code> 4/1AX4h73NYyHQBAJOnhgDXF9FiuIY #输入授权后得到的验证码

2)最后一些设置

马上就结束了,坚持一下!✊

  1. Configure this as a Shared Drive (Team Drive)?

  2. y) Yes

  3. n) No (default)

  4. y/n> y #输入y,根据自己是否需要配置为团队盘来确定

  5. No Shared Drives found in your account

  6. --------------------

  7. [Gdrive]

  8. type = drive

  9. scope = drive

  10. token = {"access_token":"...XXXXXXX...","token_type":"Bearer","refresh_token":"...XXXXXXX...","expiry":"2022-01-23T23:15:56.27044459+08:00"}

  11. --------------------

  12. y) Yes this is OK (default)

  13. e) Edit this remote

  14. d) Delete this remote

  15. y/e/d> y #输入y,确认配置信息

  16. Current remotes:

  17. Name Type

  18. ==== ====

  19. GDrive drive

  20. e) Edit existing remote

  21. n) New remote

  22. d) Delete remote

  23. r) Rename remote

  24. c) Copy remote

  25. s) Set configuration password

  26. q) Quit config

  27. e/n/d/r/c/s/q> q #最后退出配置

二、挂载GoogleDrive

  1. #CentOS

  2. yum install -y fuse

  3. # Debian或者Ubantu

  4. apt-get update && apt-get install -y fuse

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

  • 网盘名称:这是你在配置的时候自己设置的名称,比如我设置的是GDrive

  • 网盘路径:这是指你的云盘路径,如果留空则代表云盘根目录

  • 本地路径:这是你想挂载的服务器本地路径,比如我直接挂载了FileBrowser根目录

具体的参数配置,见官方文档

  1. #我的挂载示例

  2. rclone mount GDrive:/ /www/wwwroot/kejiwanjia/GDrive --copy-links --allow-other --allow-non-empty --umask 000 --daemon #

  3. #取消挂载

  4. fusermount -qzu <本地路径>

这里我直接挂载了FileBrowser目录,这样可以直接在FileBrowser进行文件操作和分享,真的非常方便,强烈推荐!

如果你还不会FileBrowser部署,可以参考下面👇进行学习,真的好巴适!如果挂载后FileBrowser没有显示GDrive里面的文件,建议重启容器试试,可能就有啦。

开机自启

挂载最重要的当然是稳,不然动不动掉线岂不是很令人捉急?这里通过systemctl方式来实现。

一、编辑系统服务文件

一整条命令一把梭哈。

  1. cat > /etc/systemd/system/rclone.service <<EOF

  2. [Unit]

  3. Description=Rclone

  4. AssertPathIsDirectory=LocalFolder

  5. After=network-online.target

  6. [Service]

  7. Type=simple

  8. ExecStart=rclone mount GDrive:/ /www/wwwroot/kejiwanjia/GDrive --allow-other --allow-non-empty --vfs-cache-mode full --vfs-cache-max-age 48h --vfs-cache-max-size 5G --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit 1G --buffer-size 128M

  9. ExecStop=fusermount -u LocalFolder

  10. Restart=on-abort

  11. User=root

  12. [Install]

  13. WantedBy=default.target

  14. EOF

二、启用

  1. #开始启动

  2. systemctl start rclone

  3. #设置开机自启

  4. systemctl enable rclone

  5. #其他使用

  6. systemctl restart rclone #重启

  7. systemctl stop rclone #停止

  8. systemctl status rclone #状态

好了,Rclone的基础搭建已经学完了。下一节,我会带来更多高级的玩法哦!