运行环境 Runtime environment
1 | 操作系统: ubuntu18.04 |
背景
想把申请到的googleDriver团队盘挂载到自己的VPS上去,达到扩容的和文件管理的目的。
全文唯一的难点只有Rclone创建remote,只是步骤多一点,但是并不复杂和难。
像我这种浮躁又怕麻烦的人都能搞定,相信很多人都能搞定。
安装Rclone
使用官方的安装脚本文件
curl https://rclone.org/install.sh | bash
输入命令,测试安装是否成功
rclone
1 | Usage: |
出这么一大溜help信息,说明装好了。
配置Rclone
安装完成后,开始添加挂载
输入rclone config来开始设置
首先添加一个新的挂载
rclone config
创建remote
输入 n 回车 ,新建 remote1
2
3
4n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
设置remote名称
配置名称,随便填1
name> googleDriverTeam1
选择remote创建的类型
因为我是对接谷歌团队盘,所以这里选13,
看好是选Google Drive这个选项,
rclone更新以后可能选项的数字会有变化1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77Type 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 / Transparently chunk/split large files
\ "chunker"
32 / Union merges the contents of several remotes
\ "union"
33 / Webdav
\ "webdav"
34 / Yandex Disk
\ "yandex"
35 / http Connection
\ "http"
36 / premiumize.me
\ "premiumizeme"
Storage> 13 # 选择13,看好是选Google Drive这个选项,rclone更新以后可能选项的数字会有变化
** See help for drive backend at: https://rclone.org/drive/ **
填写 Client Id && Client Secret
可以直接回车,使用RCLONE自己的Client Id来生成remote
但是,这是有弊端的。Rclone官方也说了。
因为Client Id和Client Secret使用率太高了,很多人都在用。
谷歌对每一个client应用都是有限流的,一堆人去挤着用,会发生什么呢?自己想象(一天最大流量是750G)
所以,能够自己注册谷歌client是最好的 googleApi。
当然如果觉得麻烦就直接回车,反正以后也是可以修改添加的。1
2
3
4
5
6
7
8
9
10Google 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> # 回车
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> # 回车
选择操作权限
都是自己用的话,直接选1,所有权限1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18Scope 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 # 选1 回车
根目录设置
用不到这个设置,直接回车1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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> # 回车
设置选项
1 | Edit advanced config? (y/n) |
谷歌账号授权
就是用自己谷歌授权给开发者创建的client应用,授权让它能够连接和操作你的谷歌网盘。正常操作,放心。
将https://accounts.google.com/o/oauth2/auth?XXXXX 这一大串地址复制下来,放到网页浏览器里打开
(首先你要翻墙,然后你要有谷歌账号并且登陆),点击允许授权,会出现一个授权码,点击复制,粘贴过来。
1 | Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=322604643123-ru3spb69lmg3nmo1gr1uqf1etb32tbs2.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=tvtLIvwU8axrPSDxWXbIpg |
是否是谷歌团队盘
因为使用的是团队盘,当然选y1
2
3
4
5
6Log in and authorize rclone for access
Enter verification code> 4/0AGPbXQ9thkw4XynGuNP91QxL4g9Mz7Rubv7M_lajOCwd8GqHuTlOzI
Configure this as a team drive?
y) Yes
n) No (default)
y/n> y
选择要挂载的团队盘
团队盘就是谷歌共享盘下的一个文件夹,一个文件夹算一个团队盘。
因为我有两个团队盘,并且命名了ZIO-X,,
所以,这里能看到两个选项,一个remote只能绑定一个团队盘。
以后多创几个remote里挂载这些团队盘就好。
1 | Fetching team drive list... |
信息核实
最后核实一下remote的各项参数,确认就敲个y就行1
2
3
4
5
6
7
8
9
10
11
12
13--------------------
[ZIO-2]
type = drive
client_id = XXX
client_secret = XXX
scope = drive
token = XXX
team_drive = XXX
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
romete列表
会显示当前机器上保存的romete的列表,看看就好,敲q退出1
2
3
4
5
6
7
8
9
10
11
12
13
14Current remotes:
Name Type
==== ====
ZIO-2 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
到这里,rclone 配置完成。
映射谷歌网盘到文件夹
1 | # 找个舒适的位置创建空文件夹,mkdir 命令会用吧?不用教吧? |
将挂载命令输入终端回车以后,很多人以为是卡住了。
其实不是的,这因为挂载程序跑在前台了。
这时候另开一个终端或者ssh输入命令查询是否映射成功
df -h
1 | root@RaXianch:/home# df -h |
就能看到自己挂载的硬盘了,而且大小1PB!
常用命令
1 | ### 文件上传 |
后台运行Rclone挂载网盘
凡是能后台运行的方法都可以
supervisor
supervisor 牛逼坏了,复杂但是强大。
实在嫌麻烦也容易,就两个字 宝塔!
nohup
搜索nphup的用法,满街都是
nohup # 后接填写需要执行的命令,注意前后有空格 &
screen
一般的linux系统都会自带screen,如果没有安装的话,使用
sudo apt-get install screen
或 centos
sudo yum install screen
新建一个名字为zio-1的窗口,并在窗口中执行命令
screen -S zio-1 rclone mount ZIO-2:RXFiles /home/gdDisk/ZIO-2 # 巴拉巴拉后面一堆参数
建议创建一个sh文件来管理screen,这个拓展就不赘述了。
systemctl
新建一个rclone.server文件,
Ubuntu 18.04中:
vim /lib/systemd/system/rclone.service
写入以下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#### https://www.yoursite.cn/2019/11/03/vps-gua-zai-onedrive-deng-wang-pan/
[Unit]
Description=rclone
[Service]
User=root
ExecStart=/usr/bin/rclone mount DriveName:RemoteFolder LocalFolder --allow-other --allow-non-empty --vfs-cache-mode writes --config /home/br/.config/rclone/rclone.conf
Restart=on-abort
[Install]
WantedBy=multi-user.target
注意修改DriveName、RemoteFolder和LocalFolder的值
然后重载daemon,使新的服务生效:
systemctl daemon-reload
设置开机启动
rclone启动:
systemctl start rclone
开机启动:
systemctl enable rclon
总结
上传速度还不错的,本来还想着要要一个大盘鸡的,现在1PB的挂载网盘,好像可以省点钱不用买了。
本来要写短篇博客的,结果rclone创建remote配置信息就一大堆。
不过只是看着多,但都是自动生成的选项,选择一下就好。
步骤多只是为了写得详细些,而是因为太复杂,静下心看就好。