利用Rclone挂载Google Drive/OneDrive

关于Rclone

Rclone是一款非常优秀的云盘挂载软件,同时具有很多优秀的功能。他是一个小巧的命令行程序,用于与以下文件同步文件和目录:阿里云OSS、亚马逊S3、Dropbox、Google Drive、onedrive等等。官方主页https://rclone.org/。主要有一下功能特色:

始终检查MD5 / SHA1哈希是否具有文件完整性
文件上保留的时间戳
基于整个文件支持部分同步
复制模式仅复制新的/更改的文件
同步(单向)模式,使目录相同
检查模式以检查文件哈希是否相等
可以与网络同步,例如可以与两个不同的云帐户同步
加密后端
缓存后端
块后端
联合后端
可选的FUSE挂载(rclone挂载)
多线程下载到本地磁盘
可以通过HTTP / WebDav / FTP / SFTP / dlna 提供本地或远程文件
基于实验Web的GUI

《利用Rclone挂载Google Drive/OneDrive》

其实网上有很多文章,写的要比我号,不过由于今天转载被人喷了,所以自己写一篇,记录一下。同时为以后各种挂载和文件备份做个伏笔。

目前利用Rclone挂载网盘主要有两个思路:
1、在电脑上调试好conf文件,直接传到VPS上挂载
2、直接在VPS上调试。
各有优势把,习惯win的小伙伴可以本机调试,后将conf文件传入VPS上,备份也简单。图方便的话直接在SSH上搞更加方便。
以下为各个平台支持版本下载。我这里就不介绍了,我是直接在VPS上搞的。也可以在githup上下载,点击这里,目前最新版本为v1.51.0,我就是用的这个版本。

《利用Rclone挂载Google Drive/OneDrive》

安装Rclone

本人是新手,我用脚本安装的,对环境很熟悉,并且在生产环境下搞的人,建议采用编译安装,避免出现变量冲突等问题

脚本安装

#安装curl,有的可以跳过
yum install curl
#安装个解压程序,有的可以跳过
yum install unzip
#安装代码
curl https://rclone.org/install.sh | sudo bash

如果生产环境有docker的话,建议用docker安装,比较方便管理

#安装镜像
docker pull rclone/rclone:latest #运行镜像 $ docker run --rm rclone/rclone:latest version

配置Rclone

#开始配置
 rclone config
#选择n,新建一个配置文件
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  #输入n
name> googleshikey   #名字随便取
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
.#此处省略N文字
13 / Google Drive
   \ "drive"
#此处省略N文字
Storage>  13    #输入13,本文挂载的是GD
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>      #你知道可以填写,不知道可以直接留空
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret>      #你知道可以填写,不知道可以直接留空 
scope> 1   #建议选1,权限大一点

下面的基本都是默认。到了一下蓝色字体的地方记得选n

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 #这里选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    #这里注意了!!!选择N,表示自行配置,把以下链接复制都浏览器内输入你的GD账户,授权后即可得到code(授权码)
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202786815994.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=2Kj1iuuybkkl8FssdmQ
Log in and authorize rclone for access

《利用Rclone挂载Google Drive/OneDrive》

输入授权码之后,选择下你的GD类型。即可完成配置

《利用Rclone挂载Google Drive/OneDrive》

有以下的提示就代表配置正确并保存了,我刚才配置名称写的是g1s哈,一开始写的googleshikey

《利用Rclone挂载Google Drive/OneDrive》

网盘挂载

完成配置 rclone的配置文件后,需要把网盘挂载到空间目录上。设置开机自启,自动挂载 Google Drive 网盘

#安装下fu
yum -y install fuse
#新建个目录,用于挂载GD,放到home文件夹下便于迁徙。
mkdir -p /home/google
#挂载
nohup rclone mount remote:path/to/files /home/google &
#其中
remote表示你的配置文件名称,例如我上面填写的googleshikey
path/to/files表示你的google drive目录,可以填写个"/"表示根目录
/home/google表示你刚才建立的本机vps上的目录

可以直接忽视nohup的输出,忽略即可,你也可以输出到1.txt之类的

《利用Rclone挂载Google Drive/OneDrive》

输入命令查看下是否挂载成功,那个1.0P的就是google drive空间,你挂载个人的话就是15G。

df -h

《利用Rclone挂载Google Drive/OneDrive》

进去查看下文件,显示正常,到此基本完毕。你也可以在此基础上,用owncloud、nextcloud、cloudreve等程序把这个目录挂载到web,这样就完美了。甚至用nginx或者caddy反带到此目录实现科学下载。

《利用Rclone挂载Google Drive/OneDrive》

开机启动

非必须但是推荐启用。

我这里用的是centos7的系统,所以用systemctl实现,其他系统自行百度即可。

首先新建一个service

#使用vim创建,也可以用记事本创建传上去
vi /usr/lib/systemd/system/rclone.service

内容如下

#这是网上的写法

[Unit]
Description=rclone
    
[Service]
User=root
ExecStart=/usr/bin/rclone mount g1s1:/ /home/google –allow-other –allow-non-empty –vfs-cache-mode writes
Restart=on-abort
    
[Install]
WantedBy=multi-user.target

重载配置

systemctl daemon-reload

测试启动

systemctl start rclone

开机启动

systemctl enable rclone

停止服务

systemctl stop rclone

查看运行状态

systemctl status rclone

其他命令

不喜欢使用命令行的小伙伴,可以看着

Rclone可以提供基于Web的GUI(图形用户界面)。目前,这还处于实验阶段,因此情况可能会发生变化。

在终端中运行此命令,rclone将下载并在Web浏览器中显示GUI。

rclone rcd --rc-web-gui

提示如下即代表运行成功,在浏览器打开你的IP:5572,记得首先要先打开端口

2019/08/25 11:40:14 NOTICE: A new release for gui is present at https://github.com/rclone/rclone-webui-react/releases/download/v0.0.6/currentbuild.zip
2019/08/25 11:40:14 NOTICE: Downloading webgui binary. Please wait. [Size: 3813937, Path :  /home/USER/.cache/rclone/webgui/v0.0.6.zip]
2019/08/25 11:40:16 NOTICE: Unzipping
2019/08/25 11:40:16 NOTICE: Serving remote control on http://127.0.0.1:5572/

具体可以看官方说明:https://rclone.org/gui/

常见问题

rclone常見的幾個報錯&解決方法
1. Error 403: Rate Limit Exceeded, rateLimitExceeded
原因:用戶的使用頻率超出限制,此限制可能為操作頻率過高、超出上傳量限制所導致。
24小時內可以調用ServerSideCopy的檔案大小限制約為750G、一般上傳的流量限制也是750G,若超出限制但未完成的傳輸仍可持續進行到完成。
若傳輸過多小檔案或頻繁進行操作,也可能因操作頻率過高觸發此限制,詳細數據不明。
解決方法:通常等待24小時即可解除此限制

2. Error 403: The download quota for this file has been exceeded., downloadQuotaExceeded
原因:GD有對每個帳號存在每日分享限制(10TB/日),超出會導致無法下載
解決方法:通常等待24小時即可解除此限制,或可以調用ServerSideCopy,即可繞過分享流量限制(但SSC本身仍然有其限制)

3. Error 404: File not found
原因:rclone更新到v1.47後,新增了跨帳號間做ServerSideCopy的功能,但也因此導致了此錯誤的發生。
解決方法:在指令中添加–disable copy,或使用1.46以下之版本

发表回复