rclone是一款可以将多种网盘部署到服务器上的程序,常见的都是rclone挂载到一个文件夹中,再将这个网盘软链接到第三方网盘/目录程序中。事实上rclone已自带目录程序,不再需要caddy/nginx。

部署

部署的方法都一样,我这里参考了轻风伴梦Rat's的部署过程。
(这一步还不叫挂载)

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/
然后解压出来,就解压到c盘的下载文件夹都行,进入文件夹,按住shift,点击鼠标右键,选择在此处打开Powershell窗口
运行CMD,输入

rclone authorize "onedrive"

会出现一堆信息,之后浏览器会自动打开,登入onedrive进行授权,浏览器提示Success!,返回cmd
会显示:

Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容,后面需要用到
<---End paste

在Windows,CMD生成的token是有回车的,需要将回车删除

安装rclone

使用

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

在centos/debian系统内安装rclone

安装完成后,运行

rclone config

开始配置

n) New remote
s) Set configuration password
q) Quit config
n/s/q> `n`
name> `onedrive`
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
19 / Microsoft OneDrive
   \ "onedrive"
Storage> `19`
** 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> `直接回车`
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":""}  #输入之前在客户端授权的内容
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
Your choice> `1`
Found 1 drives, please select the one you want to use:
0:  (personal) id=aba1021fbca78159
Chose drive to use:> `0`
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=aba1021fbca78159
Is that okay?
y) Yes
n) No
y/n> `y`
--------------------
[onedrive]
type = onedrive
token = {"access_token":"xxx"}
drive_id = aba1021fbca78159
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> `y`
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`

验证rclone访问onedrive

大部分教程都忽略了这一步,但其实是蛮有必要的。
使用rclone ls/lsf命令访问onedrive,确认输出结果正确:

[root@NJ ~]# rclone lsf onedrive:
docker命令
eve-online.rules
onedrive/
工具/
新建文本文档 (2).txt
[root@NJ ~]# rclone ls onedrive:
      523 docker命令
     3890 eve-online.rules
     2096 新建文本文档 (2).txt
7652521984 工具/C4D/C4D R17 Win_Mac安装包.iso
...

创建http服务

其实我更建议查看官方wiki,wiki讲的比我更详细。

如果你觉得看英文发晕就看下我的步骤吧
执行:

rclone serve http onedrive:/onedrive --addr 127.0.0.1:8080


这样再通过nginx反代(使用--addr :8080的话直接访问ip:8080就行)后访问即可。
显示的页面虽然简陋但也够用,这也就不需要第三方的程序了。
list.png
不完全懂参数就别瞎复制粘贴参数了,默认的参数完全足够,实测下来除了cpu偶尔有波动以外,本地硬盘占用几乎为0,缓存都跑内存里了

如果需要优化建议访问官方wiki:

https://rclone.org/commands/rclone_serve_http/
https://rclone.org/flags/

自行调试。(我是自己调了半天发现还不如官方的默认配置)

开机启动

再次建议使用Systemctl配置开机启动,现在CentOS 7、Debian 8+、Ubuntu 16+都支持这个了。
过程:

#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="serve http onedrive:/onedrive --addr 127.0.0.1:8080"
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

然后运行下面的代码。从上到下的含义分别是:加载脚本,使systemctl载入脚本|运行程序|开机运行程序

systemctl daemon-reload
systemctl start rclone
systemctl enable rclone

重启服务器,再就直接ip+端口/nginx反代配好后访问。


参考:
使用rclone挂载OneDrive/GoogleDrive网盘
在Debian/Ubuntu上使用rclone挂载OneDrive网盘

最后修改:2019 年 12 月 23 日
如果觉得我的文章对你有用,请随意赞赏