vps使用rclone挂载Google Drive

/ 0评 / 0

一、 安装并配置rclone

首先在vps上一键安装rclone:

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

接下来在本地电脑上下载命令行操作的rclone:

访问rclone下载地址,选择您的操作系统下载相应的zip包并解压。一会需要用得着。

软件准备好中,在vps上开始配置,执行:

rclone config

您应该会看见

2022/05/28 08:56:05 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,新建配置:

此时rclone会要你选择要挂载什么网盘,找到google drive并选择。注意是google drive,不是google cloud或google photos。

选择后rclone会要求输入api token,如果留空会使用rclone默认的api,但是据官方说明官方的目前使用人数过多,由于google本身的限制可能会出现需要等待时间过长的问题,因此推荐自己去申请一个api。

下面是申请的简单步骤:

  1. 首先登录到Google API console,创建一个应用,点击“启用API和服务”,找到Google Drive并启用

2. 点击OAuth同意屏幕,用户类型选择外部,应用名称随便填写,比如“rclone”就可以。用户支持电子邮件和开发者联系邮箱都填写您自己的就可以,点击保存并继续,剩下的参数都是用默认就可以了。

3. 点击凭据,屏幕上方点击创建凭据,选择OAuth 客户端ID

应用类型选择桌面应用。

应用类型选择

名称随便填,点击创建。创建后会向您提供您的客户端ID 和客户端密码,务必记下这些数据,并且填写到rclone中。

最后选择OAuth同意屏幕,选择发布应用。此时应该能看到发布状态变为了正式版。

发布状态

至此Google API就申请完成了,继续返回到rclone中进行配置。

填写Google API后,应该会看到如下显示:

Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 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)

这个可以根据需求选择,比如我要完整的访问权限,就选择1。

接下来

root_folder_id 为空,service_account_file 也为空,直接回车即可。

Edit advanced config 输入 n,不需要进行额外的高级配置。

Use auto config 因为是要在vps上挂载,vps没有桌面环境,因此必须选择 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" "Your Token Code"
Then paste the result.
Enter a value.

注意,接下来要在本地执行,前面下载在本地的rclone压缩包解压后,cmd命令执行rclone authorize “drive”这一行,然后授权、授权成功浏览器会提示success.

此时返回命令行,等待几秒就能看见授权的code了。

复制授权code,输入到rclone中。

接下来rclone会询问是否为团队盘:

Configure this as a Shared Drive (Team Drive)?
 
y) Yes
n) No (default)

如果您要挂载的就是团队盘,那么选择y,不是的话就选择n

此时配置就已经结束了,退出clone,开始挂载。

二、 挂载Google Drive

首先新建一个文件夹用于挂载:

mkdir /google

开始挂载:

rclone mount gdrive: /google --allow-other --allow-non-empty --vfs-cache-mode writes --daemon

其中gdrive是rclone配置时输入的配置名称,/google是挂载目录,–daemon是指后台运行。

此时可能会报错:

Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

这是因为缺少依赖,我们选择安装

centos系使用:

yum install -y fuse 

debian系使用:

apt install -y fuse

再次执行挂载命令,如果没有报错,就是挂载成功了。

检查挂载:

df -h

应该看到:

可以看到/google已经成功挂载了

接下来进入/google进行一些简单的测试

cd /google
ls
mkdir test
rm -rf test

如果能够顺利执行,则说明挂载没有问题。

取消挂载

fusermount -u /google

发表回复

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