Centos6/7 使用rclone挂载OneDrive搭建离线下载

一、安装 ARIA2

安装前先安装 unzip 解压工具包和 wget 下载工具

yum install zip unzip
yum -y install wget

创建目录

mkdir /home/Download

拉取aria,赋予权限

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/aria2.sh
chmod +x aria2.sh

安装完后运行

./aria2.sh

配置 自动更新 BT-Tracker服务器
更改下载目录为 /home/Download

二、安装 rclone

首先需要在本地电脑也下载 rclone (用于获取 OneDrive 登录 TOKEN , 因为过程当中会打开网页,登录 OneDrive 由于 SSH 配置是无法看到网页的)

下载地址:https://rclone.org/downloads/ 然后解压出来,比如我解压到 D 盘,文件夹命名 rclone,此时点击 Win+R,然后输入 cmd,确定。再输入以下命令:

D:
cd d:\rclone
rclone authorize "onedrive"

会出现以下信息:

c:\rclone&gt;<span class="hljs-built_in">cd</span> /c:\rclone

c:\rclone&gt;rclone authorize <span class="hljs-string">"onedrive"</span>
Choose OneDrive account <span class="hljs-built_in">type</span>?
* Say b <span class="hljs-keyword">for</span> a OneDrive business account
* Say p <span class="hljs-keyword">for</span> a personal OneDrive account
b) Business
p) Personal
b/p&gt; b &lt;== (这里 个人账号选 p 工作账号选 b 因为我是 OneDrive Business)
If your browser doesn<span class="hljs-string">'t open automatically go to the following link: http://127.
0.0.1:53682/auth &lt;== (这里会打开网页 登录你的 OneDrive 账号即可)
Log in and authorize rclone for access
Waiting for code...
Got code &lt;== (这里是返回你的 TOKEN)
Paste the following into your remote machine ---&gt;
`{"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImlCakwxUmNxemhpeTR
mcHhJeGRacW9oTTJZayIsImtpZCI6ImlCakwxUmNxemhpeTRmcHhJeGRacW9oTTJZayJ9.eyJhdWQiOi
JodHRwczovL2FwaS5vZmZpY2UuY29tL2Rpc2NvdmVyeS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3
dzLm5ldC8zOWE2Y2E2MS05OGRjLTRkY2MtYjU5Mi1kM2JhYzYxNDkzOTQvIiwiaWF0IjoxNTI1Mjc2OD
...
98JnWA_VvhIUeW98RvBSAA","expiry":"2018-05-03T01:04:55.9347103+08:00"}`
&lt;---End paste</span>

 

我们所需要的就是下面红色区域中间的内容{“access_token”:” …. “expiry”:”2018-08-18T01:04:55.9347103+08:00″}粘贴文本到新建的记事本保存好。

三、vps 安装和配置 rclone

1.安装命令

yum -y update
yum -y install fuse
curl https://rclone.org/install.sh | sudo bash

2.安装完成开始配置 rclone

配置 rclone 命令:

rclone config

会出现以下信息:

[root@MeiamOS ~]# rclone config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> OneDrive           <== (这里输入挂在项目的名字)
Type of storage to configure.
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 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 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Koofr
   \ "koofr"
16 / Local Disk
   \ "local"
17 / Mega
   \ "mega"
18 / Microsoft Azure Blob Storage
   \ "azureblob"
19 / Microsoft OneDrive
   \ "onedrive"
20 / OpenDrive
   \ "opendrive"
21 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
22 / Pcloud
   \ "pcloud"
23 / QingCloud Object Storage
   \ "qingstor"
24 / SSH/SFTP Connection
   \ "sftp"
25 / Webdav
   \ "webdav"
26 / Yandex Disk
   \ "yandex"
27 / http Connection
   \ "http"
Storage> 19         <== (这里选择 所需要挂在类型的 ID 上面是可以挂在网盘的列表)
** See help for onedrive backend at: https://rclone.org/onedrive/ **
Microsoft App Client Id - leave blank normally.
client_id>                        <== (回车留空)
Microsoft App Client Secret - leave blank normally.
client_secret>                  <== (回车留空)
Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> b                      <== (我的账号是 OneDrive Business 账号所以选择 b)
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> {"access_token":"","expiry":""}   <== (这里贴入刚才获取 TOKEN)
--------------------
[OneDrive]
type = onedrive
client_id =
client_secret =
token = {"access_token":"","expiry":"2018-08-18T22:56:29.794396289-04:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y                <== (这里选择 Y 确定保存 TOKEN )
Current remotes:

Name                 Type
====                 ====
OneDrive             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 退出配置 )

继续输入命令进行挂载

#安装 fuse 
yum -y install fuse #创建挂载目录 
mkdir -p /home/onedrive #挂载 
rclone mount remote:/files /home/onedrive #如果需要后台保持运行,使用下面的命令 
nohup rclone mount remote:/files /home/onedrive &

解释下上面的参数:
remote:远程名,之前我们设置的是 onedrive
/files:远程文件路径(也就是 Onedrive 路径),可设置为/
/home/onedrive:本地磁盘路径
不出问题的情况下,输入df -h就可以看到 Onedrive 成功挂载。

四、设置自启动挂载脚本

1、下载 RCLOAD 自启动挂载脚本:

wget -N --no-check-certificate https://raw.githubusercontent.com/x91270/Centos/master/rcloned 
vim rcloned

2、修改 RCLOAD 自启动脚本关联目录

NAME=”” #rclone name 名,及配置时输入的 Name
REMOTE=” #远程文件夹,OneDrive 网盘里的挂载的一个文件夹 留空则显示全部文件夹
LOCAL=” #挂载地址,VPS 本地挂载目录,使用绝对路径

3、设置 RCLOAD 自动启动

mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
chkconfig rcloned on
bash /etc/init.d/rcloned start

4、给 ARIA2 添加下载完成移动到网盘脚本

cd /root/.aria2/
wget -N --no-check-certificate https://raw.githubusercontent.com/x91270/Centos/master/move.sh
chmod +x move.sh
echo "on-download-complete=/root/.aria2/move.sh" >>aria2.conf

注意:如果你的目录和教程中不一样请在 move.sh 中设定

RCLOAD 启动停止命令

bash /etc/init.d/rcloned start
bash /etc/init.d/rcloned stop

查看挂载磁盘

df -h

如果出现硬盘,就大功告成啦!

点赞