Created
October 1, 2018 14:09
-
-
Save 798886844/871bdd20947511e9d058aa5c6a86bb39 to your computer and use it in GitHub Desktop.
VPS搭建Aria2+AriaNG+Rclone挂载Onedrive实现离线下载到网盘
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 2018.5.29 23:55更新:修改安装顺序,避免出现bug;修改autoupload.sh内容,实现上传+删除本地文件同时管理。 | |
研究了接近三个月的离线下载,网上的教程或多或少有一些或者几乎全部都是错的,不知道是过期了还是怎么了。还好,至少给了我一个大方向,经过不懈的努力,我最终还是实现了这个离线下载到Onedrive中的功能。 | |
在研究的过程中无意发现了Rclone自带的sync功能,因此,本篇文章将用两种方法实现自动上传,并做对比。 | |
搭建环境:Docker环境,镜像: | |
[rastasheep/ubuntu-sshd](https://hub.docker.com/r/rastasheep/ubuntu-sshd/) | |
其中,该镜像的环境是 | |
```c# | |
ubuntu-sshd-910292714-kpnx7 4.4.0-72-generic | |
用户名、密码均为:root | |
``` | |
需要开放的端口包括:22、80、6800,但不限于以上端口。 | |
### 安装AriaNG | |
本文采用的是Apache网络服务器安装。 | |
打开Shell终端,连接VPS: | |
安装依赖: | |
```C | |
apt-get update | |
apt-get install -y vim unzip screen fuse | |
``` | |
#### 下载并安装[Apache2.0](https://blog.csdn.net/StepTimeNatural/article/details/78153740): | |
```C | |
apt-get -y install apache2 | |
/etc/init.d/apache2 start | |
``` | |
此时打开VPS的ip应该能看到Apache的默认页面了。 | |
其中Apache2.0的默认网页文件根目录位于`/var/www`,配置文件位于`/etc/apache2/apache2.conf` | |
停止Apache2.0:`/etc/init.d/apache2 stop` | |
#### 下载并[安装AriaNG](https://lala.im/2982.html) | |
```c | |
cd /var/www/html | |
wget https://github.com/mayswind/AriaNg/releases/download/0.4.0/aria-ng-0.4.0.zip | |
unzip aria-ng-0.4.0.zip | |
``` | |
注意,中间有一个index.html提示的提示,选"y"即可。 | |
```c | |
root@ubuntu-sshd-910292714-v1kbc:/var/www/html# unzip aria-ng-0.4.0.zip | |
Archive: aria-ng-0.4.0.zip | |
creating: css/ | |
inflating: css/aria-ng-aed476e868.min.css | |
inflating: css/bootstrap-3.3.7.min.css | |
inflating: css/plugins-a7090b9582.min.css | |
creating: fonts/ | |
inflating: fonts/fontawesome-webfont.eot | |
inflating: fonts/fontawesome-webfont.svg | |
inflating: fonts/fontawesome-webfont.ttf | |
inflating: fonts/fontawesome-webfont.woff | |
inflating: fonts/fontawesome-webfont.woff2 | |
creating: js/ | |
inflating: js/angular-packages-1.6.5.min.js | |
inflating: js/aria-ng-32e6c713b1.min.js | |
inflating: js/bootstrap-3.3.7.min.js | |
inflating: js/echarts-common-3.7.1.min.js | |
inflating: js/jquery-2.2.4.min.js | |
inflating: js/moment-with-locales-2.18.1.min.js | |
inflating: js/plugins-7eed010b9e.min.js | |
creating: langs/ | |
inflating: langs/zh_Hans.txt | |
inflating: langs/zh_Hant.txt | |
inflating: favicon.ico | |
inflating: favicon.png | |
replace index.html? [y]es, [n]o, [A]ll, [N]one, [r]ename: y #选择“y”即可。 | |
inflating: index.html | |
inflating: index.manifest | |
inflating: LICENSE | |
inflating: robots.txt | |
inflating: tileicon.png | |
inflating: touchicon.png | |
``` | |
完成后,浏览器打开你的ip地址,按下`crtl+F5`就可以看到AriaNG面板了,但是我们还没有安装Aria2,因此现在还无法连接。 | |
### 安装并配置[Aria2](https://www.htcp.net/3652.html) | |
#### 安装Aria2 | |
回到Root目录下: | |
`cd /root` | |
一条命令即可: | |
`apt-get -y install aria2` | |
#### 配置Aria2 | |
需要自行新建配置文件: | |
```language | |
mkdir /root/.aria2 | |
touch /root/.aria2/aria2.session | |
touch /root/.aria2/aria2.log | |
touch /root/.aria2/aria2.conf | |
``` | |
其中,aria2.session为下载信息文件,aria2.log为日志文件。这两个文件不用管。 | |
需要编辑的是aria2.conf,这是aria2的配置文件。 | |
`vi /root/.aria2/aria2.conf` | |
按下`i`,写入下列信息: | |
```c | |
## '#'开头为注释内容, 选项都有相应的注释说明, 根据需要修改 ## | |
## 被注释的选项填写的是默认值, 建议在需要修改时再取消注释 ## | |
## 文件保存相关 ## | |
# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置 | |
dir=/root/download/ | |
# 启用磁盘缓存, 0为禁用缓存, 需1.16以上版本, 默认:16M | |
disk-cache=32M | |
# 文件预分配方式, 能有效降低磁盘碎片, 默认:prealloc | |
# 预分配所需时间: none < falloc ? trunc < prealloc | |
# falloc和trunc则需要文件系统和内核支持 | |
# NTFS建议使用falloc, EXT3/4建议trunc, MAC 下需要注释此项 | |
file-allocation=none | |
# 断点续传 | |
continue=true | |
## 下载连接相关 ## | |
# 最大同时下载任务数, 运行时可修改, 默认:5 | |
max-concurrent-downloads=10 | |
# 同一服务器连接数, 添加时可指定, 默认:1 | |
max-connection-per-server=5 | |
# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M | |
# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载 | |
min-split-size=10M | |
# 单个任务最大线程数, 添加时可指定, 默认:5 | |
split=20 | |
# 整体下载速度限制, 运行时可修改, 默认:0 | |
#max-overall-download-limit=0 | |
# 单个任务下载速度限制, 默认:0 | |
#max-download-limit=0 | |
#下载完成后自动执行root目录下的autoupload.sh脚本 | |
on-download-complete=/root/autoupload.sh | |
``` | |
编辑完成后,按下`Esc`,输入`:wq`并按下回车保存并退出编辑。 | |
至此,aria2的配置已经完成,但是我们并不能立即启动aria2,因为还没有配置root目录下的autoupload.sh脚本。 | |
### 自动上传至Onedrive | |
这里,我分了两个方法进行上传,一种是我自己琢磨的,一种是从另一个博客那里扒来的脚本。 | |
二者任选其一都可以实现功能,我在后面会有评测。 | |
#### 我的配置方法 | |
`vi /root/autoupload.sh` | |
输入以下内容: | |
`rclone sync source:path dest:path` | |
或者,换成: | |
`rclone move source:path dest:path` | |
其中: | |
source:path 是你的Aria2下载目录,在这里就是`/root/download` | |
dest:path dest是你用rclone挂载的网盘名称(自定义的名称),path是网盘文件的绝对路径。 | |
`sync`与`move`的区别在于,`sync`同步完成后,本地文件依然存在于下载目录;而`move`同步完成后,本地文件消失不见。同时,如果先删除本地文件再用`sync`,那么云端的文件将会被一起删除;如果删除了本地文件再进行`move`动作,云端文件不会被删除。所以,这里推荐使用`move`。 | |
比如,我想将下载目录(/root/download)里面的文件上传到网盘(名称为grive1)的“VPS”文件夹,这时应该写入: | |
`rclone sync /root/download grive1:/VPS` | |
或者 | |
`rclone move /root/download grive1:/VPS` | |
写入后,给予脚本执行命令的权限: | |
`chmod 777 /root/autoupload.sh` | |
然后,用screen启动aria2: | |
`screen -dmS aria2 aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -c` | |
这样,再打开你的ip地址,就可以成功连接你的aria,并实现下载后自动上传到Onedrive中了。 | |
#### 来自[楚盟网](https://www.5yun.org/16356.html)的某大佬脚本 | |
这里提前说明一下,类似该大佬的脚本网上非常多,但是该大佬的脚本是我用过的最好的脚本,不吹不黑。 | |
在这个方法里面,需要提前[将已经连接的Onedrive映射为本地的一个文件夹](https://www.moerats.com/archives/491/)。 | |
```c | |
#新建本地文件夹,路径自己定,即下面的LocalFolder | |
mkdir /root/OneDrive | |
#挂载为磁盘 | |
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 | |
``` | |
`DriveName`为初始化配置填的`name`,`Folder`为OneDrive里的文件夹,`LocalFolder`为VPS上的本地文件夹。 | |
如果挂载过程中出现`NOTICE: One drive root 'test': poll-interval is not supported by this remote`错误,可以无视该错误。 | |
挂载成功后,输入`df -h`命令查看即可验证! | |
 | |
可能会遇到ssh无响应的情况,这时断开ssh重新连接即可。 | |
然后,同样,编辑autoupload.sh文件: | |
`vi /root/autoupload.sh` | |
写入如下内容: | |
```c | |
#!/bin/bash | |
path=$3 #取原始路径,我的环境下如果是单文件则为/data/demo.png,如果是文件夹则该值为文件夹内某个文件比如/data/a/b/c/d.jpg | |
downloadpath='/root/download' | |
if [ $2 -eq 0 ] | |
then | |
exit 0 | |
fi | |
while true; do #提取下载文件根路径,如把/data/a/b/c/d.jpg变成/data/a | |
filepath=$path | |
path=${path%/*}; | |
if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ] #如果下载的是单个文件 | |
then | |
mv "$filepath" /root/OneDrive/ | |
exit 0 | |
elif [ "$path" = "$downloadpath" ] #文件夹 | |
then | |
mv "$filepath"/ /root/OneDrive/"${filepath##*/}"/ | |
exit 0 | |
fi | |
done | |
``` | |
然后赋予脚本执行权限: | |
`chmod 777 /root/autoupload.sh` | |
然后,用screen启动aria2: | |
`screen -dmS aria2 aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -c` | |
这样,再打开你的ip地址,就可以成功连接你的aria,并实现下载后自动上传到Onedrive中了。 | |
### 关于Rclone | |
Rclone的验证登陆前面的文章已经提到过,在此不再赘述。 | |
注意,请在AriaNG和Aria2配置并启动后再配置Rclone,否则会出现Ariang无法连接的情况。 | |
### 两种自动上传方法的评测 | |
用我的同步法: | |
 | |
 | |
用大佬的移动文件法: | |
 | |
 | |
 | |
上面的图片是我用宝塔面板当探针截取的,仅供参考。 | |
说一下主要的内容: | |
1. 稳定性,这个不用说两种方法相差无几,至于上传时出现流量抖动的情况,这是由于微软的接口不稳定造成的,一般都是开始很快,后来很慢。 | |
2. 上传后本地文件的去向:我的同步法上传后本地文件仍然存在本地下载目录,但是如果删除了本地的文件再同步,会造成云端文件同时丢失的情况。用移动文件法,移动后本地文件直接消失,而会出现在云端。 | |
大概就这么多,写这篇文章花了我一个周末的时间,唉,眼睛疼。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment