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. H-moe

    [root@host04 ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    devtmpfs 990M 0 990M 0% /dev
    tmpfs 1000M 0 1000M 0% /dev/shm
    tmpfs 1000M 8.5M 992M 1% /run
    tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
    /dev/vda1 18G 3.1G 14G 19% /
    tmpfs 200M 0 200M 0% /run/user/0
    GoogleDrive: 1.0P 19G 1.0P 1% /data/rclone/GoogleDrive
    [root@host04 ~]#
    已经挂载了。为什么文件夹还是空的。

    1. Rat's
      @H-moe

      这个信息给的有点少,所以不太清楚,你可以检查下操作之类的。

  2. 黑色

    大佬我在输入code是出现这个是什么意思Failed to configure token: failed to get token: Post https://oauth2.googleapis.com/token: read tcp ip:38670->ip:443: read: connection reset by peer

    1. Rat's
      @黑色

      链接被重置了,是国内服务器么?

      1. 黑色
        @Rat's

        是的

        1. Rat's
          @黑色

          挂载只适用国外服务器,需要能访问谷歌才行

  3. 我如风

    您好,按照您的设置一步一步来,在AriaNg安装成功那一步,设置好RPC,仍然未连接。想问一下有可能是什么原因呢,

  4. 左右为男

    rclone挂载目录中的文件不占用VPS本地空间是吧?

    1. Rat's
      @左右为男

      不占用。

  5. 左右为男

    请问rclone上传完文件后,这个脚本会自动删除rclone挂载目录中的文件吗?还是说需要手动删除?

    1. Rat's
      @左右为男

      Aria2自动上传?一般都是自带上传就删除的。

  6. lanxin

    Failed to create file system for "DriveName:Folder": didn't find section in config file
    这是什么问题

    1. Rat's
      @lanxin

      修改参数DriveName:Folder,不要照搬就行了。这些是需要改成自己的

  7. an

    root@Angus:~# mv rcloned /etc/init.d/rcloned
    root@Angus:~# chmod +x /etc/init.d/rcloned
    root@Angus:~# update-rc.d -f rcloned defaults
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:

    LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF-8" are supported and installed on your system.

    perl: warning: Falling back to the standard locale ("C").

    1. Rat's
      @an

      试试设置下变量,echo "export LC_ALL=C" >> ~/.bashrc && source ~/.bashrc

  8. sixbottles

    博主,我执行这个命令rclone mount gd:/ /root/GoogleDrive --umask 0000 --default-permissions --allow-non-empty --allow-other --buffer-size 32M --dir-cache-time 12h --vfs-read-chunk-size 64M --vfs-read-chunk-size-limit 1G挂载,用df -h看是有挂载上的,但是查看文件夹的时候就报错了ls: reading directory .: Input/output error

  9. 才不是呢
    That’s an error.

    Error: invalid_client

    The OAuth client was not found.

    Request Details
    access_type=offline
    client_id=202264815644.apps.googleusercontent.com
    redirect_uri=urn:ietf:wg:oauth:2.0:oob
    response_type=code
    scope=https://www.googleapis.com/auth/drive
    state=ae823d3b47bab5804d4af4386e89db01

    1. Rat's
      @才不是呢

      说你 OAuth client不存在,你直接enter使用默认就好。

  10. bbii

    博主,请问rclone mount d网盘之后,用一会儿,会断载。是因为系统不稳定吗?
    rclone mount Gdrive-W:/video /mnt/rclone \
    --umask 0000 \
    --default-permissions \
    --allow-non-empty \
    --allow-other \
    --transfers 4 \
    --buffer-size 4G \
    --low-level-retries 200 \
    --dir-cache-time 12h \
    --vfs-read-chunk-size 16M \
    --vfs-read-chunk-size-limit 256M
    我用的这参数。

    1. Rat's
      @bbii

      看是不是内存啥问题搞的爆了。

      1. bbii
        @Rat's

        看日志上确实提示有提示out of memory usage. 这plex加rclone有点吃内存啊,我都8内存了都不够它霍霍嘛。我去给他再加8G swap试试。

        1. Rat's
          @bbii

          是的,我之前都是10G swap起步。

      2. bbii
        @Rat's

        整个好用的plex-vps服务器真是不容易,各种问题都遇到,国内国外论坛一顿翻阅,都解决了个遍,感觉要无敌了。

        1. Rat's
          @bbii

          够折腾