侧边栏壁纸
博主头像
v林羽博主等级

行动起来,活在当下

  • 累计撰写 171 篇文章
  • 累计创建 34 个标签
  • 累计收到 12 条评论

目 录CONTENT

文章目录

【Linux使用】之--rclone挂载OneDrive配合aria2打造一台大空间网盘下载服务器

v林羽
2022-06-16 / 0 评论 / 0 点赞 / 2187 阅读 / 12201 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2023-11-01,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

【Linux使用】之–rclone挂载OneDrive配合aria2打造一台大空间网盘下载服务器

#Linux #教程 #工具 #OneDrive #系统 #Ubuntu

本文使用rclone实现OneDrive挂在到本地,作为本地磁盘使用。同时配合Aria2下载直接上传到OneDrive,打造一台完美的下载服务器。

提示:有些云服务器提供商是不允许p2p下载的,且下载影视剧还会存在版权问题,容易被封控。

挂载OneDrive

获取OneDrive Token

Windows系统下,登录rclone官网,下载对应版本的rclone

解压下载的文件,打开windows PowerShell或cmd进入含有rclone.exe文件夹,运行下列命令,自动打开浏览器登录微软账号,授权后获取OneDrive Token

rclone.exe authorize "onedrive"

例如:

C:\Users\wzl\Downloads\rclone-v1.58.1-windows-amd64>rclone.exe authorize "onedrive"

获取很长的OneDrive Token字符串,如下

{"access_token":"eXAiOiJKV1xxxxxxxxxx(此处省略N个字符)Rpw","expiry":"2022-04-20T18:16:18.5766008+08:00"}

rclone安装与配置

登录Linux系统,安装rclone

使用root用户,方便操作

sudo -i

更新安装所需软件git,wget,curl,fuse,如果已安装可以忽略

apt update && apt install git wget curl fuse -y
curl https://rclone.org/install.sh | sudo bash

新建rclone配置文件

rclone config

按照如下提示一步一步配置

root@ubt:~# rclone config
2022/04/20 08:53:31 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> od      # 名字od,也可以自己取名字,后面作相应修改
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon Drive
   \ (amazon cloud drive)
 5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Lyve Cloud, Minio, RackCorp, SeaweedFS, and Tencent COS
   \ (s3)
 6 / Backblaze B2
   \ (b2)
 7 / Better checksums for other remotes
   \ (hasher)
 8 / Box
   \ (box)
 9 / Cache a remote
   \ (cache)
10 / Citrix Sharefile
   \ (sharefile)
11 / Compress a remote
   \ (compress)
12 / Dropbox
   \ (dropbox)
13 / Encrypt/Decrypt a remote
   \ (crypt)
14 / Enterprise File Fabric
   \ (filefabric)
15 / FTP Connection
   \ (ftp)
16 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
17 / Google Drive
   \ (drive)
18 / Google Photos
   \ (google photos)
19 / Hadoop distributed file system
   \ (hdfs)
20 / Hubic
   \ (hubic)
21 / In memory object storage system.
   \ (memory)
22 / Jottacloud
   \ (jottacloud)
23 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
24 / Local Disk
   \ (local)
25 / Mail.ru Cloud
   \ (mailru)
26 / Mega
   \ (mega)
27 / Microsoft Azure Blob Storage
   \ (azureblob)
28 / Microsoft OneDrive
   \ (onedrive)
29 / OpenDrive
   \ (opendrive)
30 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
31 / Pcloud
   \ (pcloud)
32 / Put.io
   \ (putio)
33 / QingCloud Object Storage
   \ (qingstor)
34 / SSH/SFTP Connection
   \ (sftp)
35 / Sia Decentralized Cloud
   \ (sia)
36 / Storj Decentralized Cloud Storage
   \ (storj)
37 / Sugarsync
   \ (sugarsync)
38 / Transparently chunk/split large files
   \ (chunker)
39 / Union merges the contents of several upstream fs
   \ (union)
40 / Uptobox
   \ (uptobox)
41 / Webdav
   \ (webdav)
42 / Yandex Disk
   \ (yandex)
43 / Zoho
   \ (zoho)
44 / http Connection
   \ (http)
45 / premiumize.me
   \ (premiumizeme)
46 / seafile
   \ (seafile)
Storage> 28     # 选择28 / Microsoft OneDrive
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id>      # 不用填,直接回车
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret>  # 不用填,直接回车
Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
 1 / Microsoft Cloud Global
   \ (global)
 2 / Microsoft Cloud for US Government
   \ (us)
 3 / Microsoft Cloud Germany
   \ (de)
 4 / Azure and Office 365 operated by 21Vianet in China
   \ (cn)
region> 1      # 选 1 / Microsoft Cloud Global全球,依据自己的情况来定
Edit advanced config?
y) Yes
n) No (default)
y/n> n         # 高级设置不需要
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         # 自己设置
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive"
Then paste the result.
Enter a value.
config_token>          # 填入获取的OneDrive Token
{"access_token":"eXAiOiJKV1xxxxxxxxxx(此处省略N个字符)Rpw","expiry":"2022-04-20T18:16:18.5766008+08:00"}
Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (onedrive).
 1 / OneDrive Personal or Business
   \ (onedrive)
 2 / Root Sharepoint site
   \ (sharepoint)
   / Sharepoint site name or URL
 3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
   \ (url)
 4 / Search for a Sharepoint site
   \ (search)
 5 / Type in driveID (advanced)
   \ (driveid)
 6 / Type in SiteID (advanced)
   \ (siteid)
   / Sharepoint server-relative path (advanced)
 7 | E.g. /teams/hr
   \ (path)
config_type> 1     # 选 1 / OneDrive Personal or Business
Drive OK?

Found drive "root" of type "business"
URL: https://zylvt-my.sharepoint.com/personal/alongle_zylvt_onmicrosoft_com/Documents

y) Yes (default)
n) No
y/n> y             # 使用获取的默认设置
--------------------
[od]
type = onedrive
token = 
{"access_token":"eXAiOiJKV1xxxxxxxxxx(此处省略N个字符)Rpw","expiry":"2022-04-20T18:16:18.5766008+08:00"}
drive_id = b!XqBSqnPmj06ysrTEjqra6-7pdEqzcnVNlC0vu-5VZHCDi_Ove7VrTJX_h_i5jJrg
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y           # 确认
Current remotes:

Name                 Type
====                 ====
od                   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   # 设置完毕退出

查看配置文件

root@ubuntu:~# more ./.config/rclone/rclone.conf
[od]
type = onedrive
token = {"access_token":"eXAiOiJKV1xxxxxxxxxx(此处省略N个字符)Rpw","expiry":"2022-04-20T18:16:18.5766008+08:00"}
drive_id = b!XqBSqnPmj06ysrTEjqra6-7pdEqzcnVNlC0vu-5VZHCDi_Ove7VrTJX_h_i5jJrg
drive_type = business

创建本地挂载文件夹

mkdir /home/onedrive

挂载onedrive

command="mount od:/ /home/onedrive --allow-other --attr-timeout 5m --vfs-cache-mode full --vfs-cache-max-age 24h --vfs-cache-max-size 20G --vfs-read-chunk-size-limit 100M --buffer-size 100M --umask 000"

参数说明:

  • od:/file:od 为配置好的 onedrive,od:/file 是 onedrive 路径
  • /home/onedrive:本地文件夹路径
  • –allow-other:允许非当前 rclone 用户外其它用户进行访问
  • –attr-timeout 5m:文件属性缓存,(大小,修改时间等)的时间。如果 VPS 配置比较低,建议适当提高这个值,避免过多内核交互,降低资源占用。
  • -vfs-cache-mode full:开启 VFS 文件缓存,可减少 rclone 与 API 交互,同时可提高文件读写效率
  • –vfs-cache-max-age 24h:VFS 文件缓存时间,这里设置 24 小时,如果文件很少更改,建议设置更长时间
  • –vfs-cache-max-size 20G:VFS文件缓存上限大小,建议不超过当前空余磁盘的50%
  • vfs-read-chunk-size-limit 100M:分块读取大小,这里设置的是100M,可提高文件读的效率,比如1G的文件,大致分为10个块进行读取,但与此同时API请求次数也会增多
  • –buffer-size 100M:内存缓存,如果您内存比较小,可降低此值,如果内存比较大,可适当提高

设置rclone开机自启服务

创建rclone.service启动服务

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 daemon-reload

rclone服务开启开机自启

systemctl enable rclone

启动rclone服务

systemctl start rclone

显示磁盘空间信息,查看是否挂载成功

df -h
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            9.8G     0  9.8G   0% /dev
tmpfs           2.0G  1.3M  2.0G   1% /run
/dev/sda2        46G  6.9G   36G  16% /
tmpfs           9.8G     0  9.8G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           9.8G     0  9.8G   0% /sys/fs/cgroup
/dev/sda1       512M  3.7M  509M   1% /boot/efi
overlay          46G  6.9G   36G  16% 
tmpfs           2.0G     0  2.0G   0% /run/user/1000
od:             5.0T   45G  5.0T   1% /home/onedrive  # 挂载成功

取消挂载的相关操作

fusermount -qzu od # 取消挂载名为od的磁盘
systemctl stop rclone # 停止rclone服务
systemctl disable rclone # 关闭rclone服务开机自启
rclone mount od:/ /home/onedrive --allow-other --attr-timeout 5m --vfs-cache-mode full --vfs-cache-max-age 24h --vfs-cache-max-size 10G --vfs-read-chunk-size-limit 100M --buffer-size 100M --daemon # rclone临时挂载,重启服务器后失效

aria2安装与配置

下载aria2一键安装脚本

wget -N git.io/aria2.sh && chmod +x aria2.sh

执行安装脚本

./aria2.sh

 Aria2 一键安装管理脚本 增强版 [v2.7.4] by P3TERX.COM

  0. 升级脚本
 ———————————————————————
  1. 安装 Aria2
  2. 更新 Aria2
  3. 卸载 Aria2
 ———————————————————————
  4. 启动 Aria2
  5. 停止 Aria2
  6. 重启 Aria2
 ———————————————————————
  7. 修改 配置
  8. 查看 配置
  9. 查看 日志
 10. 清空 日志
 ———————————————————————
 11. 手动更新 BT-Tracker
 12. 自动更新 BT-Tracker
 ———————————————————————

 Aria2 状态: 已安装 | 已启动

 自动更新 BT-Tracker: 未开启

 请输入数字 [0-12]:

设置aria2下载路径为onerive挂载到服务器的路径/home/onedrive/Downloads

搭建完成后,就可以打开浏览器输入地址登录aria2N下载文件了。

上面的AriaNg链接使用脚本作者(P3TERX · GitHub)提供的服务器。下面我们本地搭建一个,这样速度更快。

登录AriaNg作者的GitHub,下载AriaNg-1.2.4-AllInOne.zip。解压后会得到一个index.html,直接用浏览器打开配置一下。

重新加载后,提示已连接就可以使用了。

优化bt下载

通过Aria2.sh可以设置自动更新BT-Tracker,也可使用下列方法更新(推荐)。

访问GitHub项目:GitHub - XIU2/TrackersListCollection

找到对应的用法

选择第一个链接,打开后会获取最优的服务器,把里面内容复制到aria2N下

文件通过aria2下载完毕后,再上传至onedrive,上传完毕后再清理掉本地文件,所需要注意下载文件的大小;如上面设置了缓存大小为20G,那么当前所有下载任务最大限制就是20G,当下载文件超过缓存就会停止并报错。

0

评论区