Liunx中使用Rclone挂载GoogleDrive和Onedrive

1、安装Rclone

使用官方提供的一键安装命令:

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

2、连接到网盘

提示:因为Rclone会时不时进行更新,当您看到这篇教程时菜单选项可能已经发生了略微的位移,但大致思路不会变,不要无脑照搬操作。

折叠内容,点击展开

输入 rclone config 创建新的连接

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/s/q> n
name> gd
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 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / Jottacloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
32 / Transparently chunk/split large files
   \ "chunker"
33 / Union merges the contents of several upstream fs
   \ "union"
34 / Webdav
   \ "webdav"
35 / Yandex Disk
   \ "yandex"
36 / http Connection
   \ "http"
37 / premiumize.me
   \ "premiumizeme"
38 / seafile
   \ "seafile"
Storage> 13 
//GoogleDrive是13选择时需要注意是否改变位置
 
** See help for drive backend at: https://rclone.org/drive/ **
 
Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> 
//如果知道怎么获取自己的id的可以填入自己的id,不填就默认使用Rclone官方的id
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> 
//如果知道怎么获取自己的id的可以填入自己的id,不填就默认使用Rclone官方的id
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), or for rclone to use
a non root folder as its starting point.
 
Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.
 
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 (default)
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
y) Yes (default)
n) No
y/n> n
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202266615644.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=luG8a-c_XXjSVSgPiz48NQ
Log in and authorize rclone for access
Enter verification code>4/2gGEMC0umCjeLQvMnue4dlA3v4NuP8sHL8hrW_jeLQvMnue4dP8sHL8hrWY8g  
//打开上面的网站获取授权码输入到这里
Configure this as a team drive?
y) Yes
n) No (default)
y/n> y 
//如果要连接到团队盘就填Y,连接到个人空间填N
 
//如果填N就没有下面这个内容
Fetching team drive list...
Choose a number from below, or type in your own value
 1 / TD1
   \ "0AA1xTiezizmILA9PVA"
Enter a Team Drive ID> 1
//选择你要连接的团队盘
--------------------
[gd]
type = drive
scope = drive
token = {"access_token":"ya29.a0AfH6SMCyxNJqJQRyVlT0C-lr7mXWYnmEWINUIlxs-xOG7wmzO_hTgucZr2Oe_f5tBu3UxrJaI6Ans3TPT0uk0CSKouWgUwwYNSsHWYnmEWINUIlxsdf0fewXIv5JPfCjpZP7JidOKTzC6Ruu-VW-T0uk0CSKouWgU","token_type":"Bearer","refresh_token":"1//0ewdGEOo7VQXlC1P0HhpjzQlCgYIL9gamTyHngulj0h1P0HhpjzQlCgYISNj0h1P0vlGNK49etHze4TmLHhpjzl8k","expiry":"2999-00-00T00:00:00.965446949+08:00"}
team_drive = 0AA1xTiezizmILA9PVA
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
//确认信息无误就输入Y
Name                 Type
====                 ====
gd                   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>

至此我们已经成功的连接到GoogleDrvie

 

折叠内容,点击展开
在本地Windows电脑上下载rclone,然后解压出来,解压后进入文件夹,在资源管理器地址栏输入cmd,回车就会在当前路径打开命令变量。输入以下命令:

If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxxxxxx"}  # 注意!复制{xxxxxxxx}整个内容,并保存好,后面需要用到

在服务器中输入 rclone config 创建新的连接

 

Name                 Type
====                 ====
 
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
name> od
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 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / Jottacloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
32 / Transparently chunk/split large files
   \ "chunker"
33 / Union merges the contents of several upstream fs
   \ "union"
34 / Webdav
   \ "webdav"
35 / Yandex Disk
   \ "yandex"
36 / http Connection
   \ "http"
37 / premiumize.me
   \ "premiumizeme"
38 / seafile
   \ "seafile"
Storage> 23
Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>   # 留空,回车
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>   # 留空,回车
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
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"XXXXXXXX"}  # 上面保存的token复制到这里
2018/10/31 19:54:06 ERROR : Failed to save new token in config file: section 'P3TERX' not found
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1  # 这里问你要选择的类型,选1
Found 1 drives, please select the one you want to use:
0: OneDrive (business)
Chose drive to use:> 0  # 程序找到网盘,这里编号是0,就选择0
Found drive 'root' of type 'business', URL: https://xxxxxx-my.sharepoint.com/personal/xxxxxxx/Documents
Is that okay?
y) Yes
n) No
y/n> y  # 选y
--------------------
[P3TERX]
type = onedrive
token = {"XXXXXXXX"}
drive_id = XXXXXXXXX
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  # 选y
Current remotes:
Name                 Type
====                 ====
od                      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  # 选q,退出

在服务器中输入 rclone config 创建新的连接

3、挂载网盘

创建挂载的文件夹

mkdir -p /disk/GoogleDrive

挂载网盘

rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &
    • DriveName为初始化配置填的name
    • Folder为网盘里的文件夹
    • LocalFolder为VPS上的本地文件夹

    挂载后可以用 df -h 查看是否挂载成功

    卸载网盘

    fusermount -qzu LocalFolder

    LocalFolder为VPS上的本地文件夹

    4、设置开机自启

    新建一个rclone.service文件

    vi /usr/lib/systemd/system/rclone.service

    在文本中插入以下内容

    [Unit]
    Description = rclone
    
    [Service]
    User = root
    ExecStart = /usr/bin/rclone mount mydriver:share /data/GoogleDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    Restart = on-abort
    
    [Install]
    WantedBy = multi-user.target

    注意:以上ExecStart的内容"mydriver:share /data/GoogleDrive"要结合你挂载的情况来定。

    #重载daemon,让新的服务文件生效
    systemctl daemon-reload
    #启动rclone
    systemctl start rclone
    #设置开机启动:
    systemctl enable rclone

    重启你的VPS,然后查看一下rclone的服务是否运行,接着查看一下网盘挂上去没

    #重启
    reboot
    #查看状态
    systemctl status rclone
    #查看磁盘挂载情况
    df -h
    #如果需要可以通过下面的命令关闭rclone
    systemctl stop rclone

    5、常见问题

    Ⅰ、如果遇到了executable file not found in $PATH 这个错误

    Centos解决办法:

    yum install fuse

    Debian/Ubuntu解决办法:

    apt-get install fuse

     

    版权声明:
    作者:一叶甘棠
    链接:https://www.tangshuwu.com/tutorials/63.html
    来源:棠树小屋
    文章版权归作者所有,未经允许请勿转载。

    THE END
    分享
    二维码
    < <上一篇
    下一篇>>
    文章目录
    关闭
    目 录