Rat's

在Debian/Ubuntu上使用rclone挂载Google Drive网盘
说明:我们很多人喜欢用VPS做离线下载,不过由于有的服务器硬盘太小了,装不了太多电影资源啥的,我们就需要想办法了,...
扫描右侧二维码阅读全文
17
2018/01

在Debian/Ubuntu上使用rclone挂载Google Drive网盘

说明:我们很多人喜欢用VPS做离线下载,不过由于有的服务器硬盘太小了,装不了太多电影资源啥的,我们就需要想办法了,之前说过可以通过挂载FTP来增大空间,参考:Linux VPS通过安装CurlFtpFS来挂载FTP,这里再说个挂载Google Drive网盘的方法,毕竟Google Drive15G免费的空间,有的也有无限空间,都可以利用上去。

说明

本教程只适用Debian/Ubuntu系统,如果你是CentOS或者其它Linux系统,请使用以下命令安装rclone

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

初始化配置和挂载方法和下面一样,开机自启可参考该教程→传送门

安装

1、安装rclone

wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

2、初始化配置

rclone config

会出现以下信息:

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #配置名称,随便填
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 / 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 / Google Photos
   \ "google photos"
14 / Hubic
   \ "hubic"
15 / JottaCloud
   \ "jottacloud"
16 / Koofr
   \ "koofr"
17 / Local Disk
   \ "local"
18 / Mega
   \ "mega"
19 / Microsoft Azure Blob Storage
   \ "azureblob"
20 / Microsoft OneDrive
   \ "onedrive"
21 / OpenDrive
   \ "opendrive"
22 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
23 / Pcloud
   \ "pcloud"
24 / Put.io
   \ "putio"
25 / QingCloud Object Storage
   \ "qingstor"
26 / SSH/SFTP Connection
   \ "sftp"
27 / Union merges the contents of several remotes
   \ "union"
28 / Webdav
   \ "webdav"
29 / Yandex Disk
   \ "yandex"
30 / http Connection
   \ "http"
31 / premiumize.me
   \ "premiumizeme"
Storage> 12  #选择12,Google Drive,注意该序列号会随时变化,看清楚再填
Google Application Client Id - leave blank normally.
client_id>  #留空 
Google Application Client Secret - leave blank normally.
client_secret>  #留空
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>  #留空
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  #输入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
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/  #打开该地址获取code
Log in and authorize rclone for access
Enter verification code>hjdd  #输入你获取到的code
Configure this as a team drive?
y) Yes
n) No
y/n> n  #输入n
--------------------
[Rats]
type = drive
client_id = 85042871
client_secret = D72gPc
scope = drive
token = {"access_token":"y902Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #输入y
Current remotes:

Name                 Type
====                 ====
Rats                 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  #输入q保存退出

3、挂载为磁盘

#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/GoogleDrive
#挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的nameFolderGoogle Drive里的文件夹,LocalFolderVPS上的本地文件夹。

挂载成功后,输入df -h命令查看即可!
请输入图片描述
4、卸载磁盘

fusermount -qzu LocalFolder

开机自启

先新建systemd配置文件,适用CentOS 7Debian 8+Ubuntu 16+

再使用命令:

#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

开始启动:

systemctl start rclone

设置开机自启:

systemctl enable rclone

其他命令:

重启:systemctl restart rclone
停止:systemctl stop rclone
状态:systemctl status rclone

如果你想挂载多个网盘,那么将systemd配置文件的rclone.service改成rclone1.service即可,重启动什么的同样换成rclone1

相关链接

#解决Rclone挂载Google Drive时上传失败和内存占用高等问题
https://www.moerats.com/archives/877/
Vultr新用户注册送100美元/16个机房按小时计费,支持支付宝,【点击查看】。
最后修改:2020 年 04 月 29 日 01 : 00 PM

发表评论

253 条评论

  1. zzz

    请问为什么我按照这个挂载了之后无法向里面存文件

  2. 1v9

    脚本没问题,不过我把sudo删掉才行,因为我常年root,而且没有sudo命令

    1. Rat's
      @1v9

      debian系统?

      1. 1v9
        @Rat's

        嗯,我也发现了开机无法自启的问题,特意折腾出chkconfig看了下,跟nginx php-fpm ss这些优先级一样,照理说是不应该无效的,我打算试一下systemd了

  3. yy

    我用这个脚本手动bash /etc/init.d/rcloned start可以挂载,但是重启没有自启动,是什么问题呢

    1. Rat's
      @yy

      其它几条命令也运行了?

      1. yy
        @Rat's

        运行 update-rc.d -f rcloned defaults 会有提示吗?我运行了没有任何提示

      2. yy
        @Rat's

        对啊,都是一步步照着来的。。。我单独把挂载的命令加在rc里也自启不了

        1. Rat's
          @yy

          那个没提示,你是什么系统?

          1. yy
            @Rat's

            亚马逊lightsail的机器,自己重装的纯净Debian8 64,刚才换成亚马逊自带的Debian8就OK了,都是同样的步骤。。。算了,不折腾了,就用亚马逊得了

  4. we

    我的 无限网盘打不开api 校方限制

    1. Rat's
      @we

      试试这个:https://www.moerats.com/archives/593/。

  5. backlit

    博主你好,请问一下,我进行到挂载为磁盘时,会出现failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH的报错,Google了一下,安装了fuse后,在进行挂载,回车后迟迟没有返回值,一直卡住不动。使用CentOS7*64

    1. Rat's
      @backlit

      卡住不动的话,可能已经挂上去了,你用df -h看看。

  6. chowvinhau

    博主 自动启动我开不到啊

    1. Rat's
      @chowvinhau

      开不到是啥意思?

      1. chowvinhau
        @Rat's

        不知道是不是我不会用博主自启脚本 手动更改成功了谢谢

      2. chowvinhau
        @Rat's

        就是没有开机启动

        现在还挂载不了了。。。
        mount helper error: fusermount: failed to access mountpoint /www/wwwroot/chowvin*.tk/gdrive: Transport endpoint is not connected
        2018/03/26 18:53:44 Fatal error: failed to mount FUSE fs: fusermount: exit status 1

        1. Rat's
          @chowvinhau

          这个错误提示一般是OVZ架构才提示,工单要求开启FUSE就可以了。如果是KVM,安装FUSE即可。

          1. 页落
            @Rat's

            我也遇到这个错误了,发了工单开了fuse还是无法挂载

            1. Rat's
              @页落

              也是这个提示?

  7. xiaoxuan

    想问博主一个问题,能不能用rclone将gdrive上的特定一个文件下载到vps上去,或者用什么办法可以将单个文件从gdrive下载到vps上

    1. Rat's
      @xiaoxuan

      挂载后,直接复制粘贴就可以了。

      1. xiaoxuan
        @Rat's

        不挂载不可以么

        1. Rat's
          @xiaoxuan

          在网盘分享后,wget试试。