https://rclone.org/
关于授权| 驱动REST API | Google Developers
https://developers.google.com/drive/api/v3/about-auth
登陆
https://console.developers.google.com/
启用【Google Drive API】
创建【OAuth 客户端 ID】
得到【客户端 ID】【客户端密钥】
=== 安装依赖 ===
apt-get install fuse curl -y
=== 安装rclone ===
curl https://rclone.org/install.sh | sudo bash
# 进入目录,下载解压后里面的可执行文件rclone就是我们需要的,可以直接在当前目录使用也可以将其拷贝到/usr/local/bin
=== 配置rclone ===
./rclone config # 当前目录下执行
rclone config # 系统目录下执行
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #新建
name> gd #名称随意例如gd
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 / 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
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 #这里选择1
client_id> *********************************.apps.googleusercontent.com
# 填入申请到的【客户端 ID】
client_secret> *****GTF_5dX4*********kB9wpi
# 填入申请到的【客户端 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
# scope选择1,之后的选项全部默认,直到
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
# 如果你是本机挂载则选择y,是VPS服务器的话选择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=202264815644.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=34e2987e7d777e38342a7e3680df3c1d
Log in and authorize rclone for access
Enter verification code>**************
# 复制链接地址在浏览器中打开并允许,将得到并复制代码到【Enter verification code】中
Configure this as a team drive?
y) Yes
n) No
y/n> y
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
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> q
=== 挂载gdrive ===
现在我们已经配置好了rclone,只需要通过对应的服务名字来挂载盘就行了.如果忘记了配置时输入的名字可以再次通过rclone config命令来查看:
# 先新建一个目录,用于挂载
mkdir -p /mnt/gd
# 挂载命令
rclone mount gd: /mnt/gd --allow-other --allow-non-empty --vfs-cache-mode writes &
现在通过df -h查看就能够看到刚才挂载的目录了.
===配置开机自动挂载Google Drive云端硬盘==
先把rclone的可执行文件复制到/usr/bin
新建一个rclone.service文件:
vi /usr/lib/systemd/system/rclone.service
写入:
[Unit]
Description=rclone
[Service]
User=root
ExecStart=/usr/bin/rclone mount gdrive: /gdrive/disk --allow-other --allow-non-empty --vfs-cache-mode writes
Restart=on-abort
[Install]
WantedBy=multi-user.target
重载daemon,让新的服务文件生效:
systemctl daemon-reload
现在就可以用systemctl来启动rclone了:
systemctl start rclone
设置开机启动:
systemctl enable rclone
停止、查看状态可以用:
systemctl stop rclone
systemctl status rclone
重启你的VPS,然后查看一下rclone的服务起来没,接着查看一下盘子挂上去没:
reboot
systemctl status rclone
df -h
使用rclone挂载OneDrive网盘
客户端授权
在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/。
然后解压出来,比如我解压到D盘,文件夹命名rclone,此时点击Win+R,然后输入cmd,确定。再输入以下命令:
cd /d d:\rclone
rclone authorize "onedrive"
这时会自动打开浏览器按提示登陆授权,当网页显示
Success!
All done. Please go back to rclone.
#回到CMD界面
C:\Users\Users>cd /d d:\rclone
d:\rclone>rclone authorize "onedrive"
2018/12/24 19:14:35 NOTICE: Config file "C:\\Users\\Users\\.config\\rclone\\rclone.conf" not found - using defaults
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":"EwBwA8l6BxxxxxxxxxxxxacbtK!VgGItbS7sxc","expiry":"2018-12-24T20:15:31.0560991+08:00"}
#红字部分就是VPS挂载所需要的
<---End paste
d:\rclone>
===#rclone挂载Microsoft OneDrive===
root@MonstrousPointed-VM:~# rclone config
Current remotes:
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> od100 #名字自定义
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> 18 #Microsoft OneDrive
** See help for onedrive backend at: https://rclone.org/onedrive/ **
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
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
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> {"access_token":"EwBwA8l6BAAURxxxxxxxxxxxxxxxxxxxxxxxxxxxCMszTZEI27EacbtK!VgGItbS7sxc","expiry":"2018-12-24T20:15:31.0560991+08:00"}
2018/12/24 06:39:03 ERROR : Failed to save new token in config file: section 'od100' 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
Found 1 drives, please select the one you want to use:
0: (personal) id=xxxxxxxxxxxxxx
Chose drive to use:> 0 #0: 这里输入0
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=e164800991cb8f79
Is that okay?
y) Yes
n) No
y/n> y
--------------------
[od100]
type = onedrive
token = {"access_token":"EwBwA8l6BAAURxxxxxxxxxxxxxxxxxxxxxxxxxxxCMszTZEI27EacbtK!VgGItbS7sxc","expiry":"2018-12-24T20:15:31.0560991+08:00"}
drive_id = xxxxxxxxxxxxxx
drive_type = personal #personal个人版,Business挂载方法类似。
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
od100 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
# 退出
要注意挂载在你VPS上的谷歌硬盘,你往里面存数据是要双向流量,也就是你先传到你的VPS,你的VPS再传到G DRIVE,所以流量是一进一出双向,如果你的服务器流量有限,而且是双向计算,那就要小心了



0 评论