谷歌应用

配置Rclone将Google Drive挂载到VPS

黑色 · 4月21日 · 2020年 · 403次已读

Rclone的安装

官方一键安装脚本

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

配置 Rclone连接Google drive

输入 rclone config 命令,会出现以下信息,参照下面的注释进行操作(重要,对照进行)。

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  # 选择n,新建
name> Google  # 输入名称,类似于标签,用于区分不同的网盘。
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 / A stackable unification remote, which can appear to merge the contents of several remotes
   \ "union"
 2 / Alias for a existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Dropbox
   \ "dropbox"
 9 / Encrypt/Decrypt a remote
   \ "crypt"
10 / FTP Connection
   \ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
12 / Google Drive
   \ "drive"
13 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Local Disk
   \ "local"
16 / Mega
   \ "mega"
17 / Microsoft Azure Blob Storage
   \ "azureblob"
18 / Microsoft OneDrive
   \ "onedrive"
19 / OpenDrive
   \ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
21 / Pcloud
   \ "pcloud"
22 / QingCloud Object Storage
   \ "qingstor"
23 / SSH/SFTP Connection
   \ "sftp"
24 / Webdav
   \ "webdav"
25 / Yandex Disk
   \ "yandex"
26 / http Connection
   \ "http"
Storage> 12  # 选择12,Google Drive
** See help for drive backend at: https://rclone.org/drive/ **

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>  # 留空,回车
Google Application Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>  # 留空,回车
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
ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
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
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=XXXXXXXXXXX.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=XXXXXXXXXXXXXXXXXXXX
Log in and authorize rclone for access  # 会弹出浏览器,要求你登录账号进行授权。如果没有弹出,复制上面的链接到浏览器中打开进行授权。
Enter verification code>  # 在这里输入网页上显示的验证码

Configure this as a team drive?
y) Yes
n) No
y/n> y
Fetching team drive list...
No team drives found in your account--------------------
[Google]
type = drive
scope = drive
token = {"access_token":"XXXXXXXXXXXXXXXXXXXXX"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name                 Type
====                 ====
Google               drive
P3TERX               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

Rclone配置完成

挂载Google Drive到VPS

安装 fuse

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

挂载网盘

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

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

网盘名称为配置时填的 name,网盘路径为网盘里的文件夹,留空为整个网盘,本地路径为 VPS 上的本地文件夹。参数可以查看官方文档根据需求进行选择。实际输入时不要有括号,这里只是为了更清楚的区分。–daemon 为进程守护参数,可后台运行

例子:

rclone mount Googledrive:/ /Googledrive --copy-links --allow-other --allow-non-empty --umask 000 --daemon
df -h #然后输入命令查看挂载情况
fusermount -qzu /Googledrive #取消挂载命令

设置开机自动挂载

  • 下载并编辑自启脚本
wget -N git.io/rcloned && nano rcloned
  • 修改内容
NAME="Googledrive" #Rclone配置时填写的name
REMOTE=''  #远程文件夹,网盘里的挂载的一个文件夹,留空为整个网盘
LOCAL='/Googledrive'  #挂载地址,VPS本地挂载目录

保存退出

  • 设置开机自启
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned

# Debian/Ubuntu
update-rc.d -f rcloned defaults 
# CentOS
chkconfig rcloned on
bash /etc/init.d/rcloned start

看到 [信息] rclone 启动成功 ! 即可。

  • 其他管理命令
开始挂载 bash /etc/init.d/rcloned start
停止挂载 bash /etc/init.d/rcloned stop
重新挂载 bash /etc/init.d/rcloned restart
查看日志 tail -f /$HOME/.rclone/rcloned.log
  • 卸载自启挂载
bash /etc/init.d/rcloned stop
update-rc.d -f rcloned remove # Debian/Ubuntu
chkconfig rcloned off # CentOS
rm -f /etc/init.d/rcloned

至此,rclone将Googledrive挂载到vps全部完成。可以在根目录看到Googledrive以目录形式挂载到了vps,直接用文件管理程序或者宝塔面板操作即可。

拓展应用

  • 服务器安装aria2+cloudreve可以实现离线下载到Googledrive,详见:

参考资料

本文整理大部分搬运及参考自:(感谢各大神的应用心得)