用aria2搭建一台阿里云盘离线下载服务器

oracle cloud的免费服务器,大家都知道的吧,我之前注册了三个账号,申请了三台arm的服务器,4c24g,4GB共享带宽,除了一台平时拿来google一下,另外的服务器都处于闲置状态,放在那儿实在可惜,正好最近又申请了阿里的云盘,有了1T的云盘,不拿来放点小姐姐实在是浪费呀,综合以上信息,我想着弄一个BT下载服务器,将下载好的小姐姐放到阿里云盘里扩充库存,于是有了后续折腾

折腾准备

工具

一台服务器,系统基于Linux的任何发行版本都行
远程登录软件,推荐finalshell,win,mac都可以用

建议各位最好限制下22端口的访问权限,或者换成SSH Key登录服务器,密码真的不安全,个人建议哈

使用到的软件:

  1. Docker
  2. webdav-aliyundriver
  3. rclone
  4. Aria2-Pro 中文官网
  5. Aria2 for Chrome

前戏

1、咋登录服务器我就不写了,都会的吧,会的吧
2、我折腾都喜欢用docker,这样可以避免宿主机安装各种软件(小洁癖),不玩了直接容器一删,宿主机还跟新的一样。所以第一步,我们安装docker,安装流程参考官方文档即可。

如果你是debain,可能会遇到command not found: sudo的问题,这个时候,你可以选择安装sudo,也可以选择复制官方命令,删除sudo,前提你是root用户登录的

3、给docker配置一个network,方便等会儿为各个容器指定ip,方便配置nginx

docker network create --subnet 172.88.0.0/16 fan

fan是network的名字,subnet是子网网段,自己斟酌修改

4、创建文件目录

mkdir -p /opt/aria2/config

挂载阿里云盘

阿里云盘最近很火呀,不限速,爽歪歪,还有各种第三方支持,很有玩头
本次的思路是:借助第三方工具,开启阿里云盘的webdav支持,再通过rclone将webdav挂载到服务器上
为什么不直接用三方工具挂载阿里云盘,因为不稳定,不能共享,还容易掉呀。

1、开启阿里云盘webdav支持

开启webdav使用的是开源项目webdav-aliyundriver,有疑问的可以直接翻看作者文档
我这儿用的是作者提供的镜像
启动脚本创建命令如下:

cat < /opt/aria2/start-webdav.sh
#!/bin/bash
docker rm -f webdav
docker run -d \
        -p 9876:8080 \
        --name=webdav \
        --restart=always \
        --log-opt max-size=1m \
        -v /etc/localtime:/etc/localtime \
        -v /opt/aliyun-driver/:/etc/aliyun-driver/ \
        -e ALIYUNDRIVE_REFRESH_TOKEN="阿里云的刷新token,看上面文档获取" \
        -e ALIYUNDRIVE_AUTH_PASSWORD="webdav的认证密码" \
        -e ALIYUNDRIVE_AUTH_USER-NAME="webdav的用户名" \
        -e JAVA_OPTS="-Xms8G -Xmx8G -Xmn4G" \
        -e TZ="Asia/Shanghai" \
        --ip 172.88.0.11 \
        --network fan \
        zx5253/webdav-aliyundriver
EOF

-p 9876:8080:9876是容器对外提供服务的端口,可以根据喜好修改
--name: 容器名,自己写
-v /etc/localtime:/etc/localtime-e TZ="Asia/Shanghai":这两个是为了解决容器时间不对, 不用修改
/opt/aliyun-driver/:这个是存储配置的目录,可以配置自己喜欢的目录
--ip 172.88.0.11--network fan:这个是给容器配置IP和网络的,用的准备里新建的网络

启动服务

sh /opt/aria2/start-webdav.sh 

检查服务,看下status字段是不是up状态

docker ps -a
服务查看

2、安装rclone

  1. 参照官网一键搞定
curl https://rclone.org/install.sh | bash
  1. 配置rclone
rclone config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>

选新建,输入:n

name>

为这个webdav取个名字,自己随喜好

Option Storage.
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
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Better checksums for other remotes
   \ "hasher"
 7 / Box
   \ "box"
 8 / Cache a remote
   \ "cache"
 9 / Citrix Sharefile
   \ "sharefile"
10 / Compress a remote
   \ "compress"
11 / Dropbox
   \ "dropbox"
12 / Encrypt/Decrypt a remote
   \ "crypt"
13 / Enterprise File Fabric
   \ "filefabric"
14 / FTP Connection
   \ "ftp"
15 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
16 / Google Drive
   \ "drive"
17 / Google Photos
   \ "google photos"
18 / Hadoop distributed file system
   \ "hdfs"
19 / Hubic
   \ "hubic"
20 / In memory object storage system.
   \ "memory"
21 / Jottacloud
   \ "jottacloud"
22 / Koofr
   \ "koofr"
23 / Local Disk
   \ "local"
24 / Mail.ru Cloud
   \ "mailru"
25 / Mega
   \ "mega"
26 / Microsoft Azure Blob Storage
   \ "azureblob"
27 / Microsoft OneDrive
   \ "onedrive"
28 / OpenDrive
   \ "opendrive"
29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
30 / Pcloud
   \ "pcloud"
31 / Put.io
   \ "putio"
32 / QingCloud Object Storage
   \ "qingstor"
33 / SSH/SFTP Connection
   \ "sftp"
34 / Sia Decentralized Cloud
   \ "sia"
35 / Sugarsync
   \ "sugarsync"
36 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
37 / Transparently chunk/split large files
   \ "chunker"
38 / Union merges the contents of several upstream fs
   \ "union"
39 / Uptobox
   \ "uptobox"
40 / Webdav
   \ "webdav"
41 / Yandex Disk
   \ "yandex"
42 / Zoho
   \ "zoho"
43 / http Connection
   \ "http"
44 / premiumize.me
   \ "premiumizeme"
45 / seafile
   \ "seafile"
Storage>

选择连接方式,输入:webdav

Option url.
URL of http host to connect to.
E.g. https://example.com.
Enter a string value. Press Enter for the default ("").
url>

配置链接地址:输入:http://172.88.0.11:8080
这个ip就是上面webdav启动时配置的ip,8080是容器内服务的端口,外部服务器要访问这个webdav,需要使用配置中映射的那个端口和宿主机的ip访问

Option vendor.
Name of the Webdav site/service/software you are using.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
 1 / Nextcloud
   \ "nextcloud"
 2 / Owncloud
   \ "owncloud"
 3 / Sharepoint Online, authenticated by Microsoft account
   \ "sharepoint"
 4 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
   \ "sharepoint-ntlm"
 5 / Other site/service or software
   \ "other"
vendor>

输入:other

Option user.
User name.
In case NTLM authentication is used, the username should be in the format 'Domain\User'.
Enter a string value. Press Enter for the default ("").
user>

webdav的登录名,这个根据上步创建时的设定填写

Option pass.
Password.
Choose an alternative below. Press Enter for the default (n).
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank (default)
y/g/n>

输入:y

Enter the password:
password:

输入密码,这里不会有任何显示,自己敲完密码回车即可,密码根据上步创建时的设定填写

Confirm the password:
password:

再次输入密码,这里不会有任何显示,自己敲完密码回车即可,密码根据上步创建时的设定填写

Option bearer_token.
Bearer token instead of user/pass (e.g. a Macaroon).
Enter a string value. Press Enter for the default ("").
bearer_token> 
Edit advanced config?
y) Yes
n) No (default)
y/n>

输入:n

--------------------
[test]
type = webdav
url = http://172.88.0.11:8080
vendor = other
user = test
pass = *** ENCRYPTED ***
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>

输入:y

Current remotes:

Name                 Type
====                 ====
test                 webdav

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就配置好了,创建的配置文件保存在~/.config/rclone/目录下

  1. 配置rclone启动任务
    下面的命令第一行command需要修改,勿直接复制使用,修改点如下两行
    test:/:冒号前面对应的是上面rclone设置的name,冒号后面是你要挂载的网盘目录,/表示根目录
    /mnt/cloud:这是是你服务器的目录地址
    上面两个配置的完整意思为,把test这个网盘的根目录挂载到/mnt/cloud上
command="mount test:/ /mnt/cloud --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty"
cat > /etc/systemd/system/rclone.service <
  1. rclone启动与自启设置
systemctl daemon-reload
# 设置自启 
systemctl enable rclone
# 启动服务
systemctl start rclone
# 查看运行状态
systemctl status rclone

如下图则为启动成功


image.png

接下来就可以进入挂载目录查看网盘上的文件了,跟使用本地目录一样的体验

安装下载工具

市面上的下载工具千千万万,但是之前我用习惯了aria2,所以这次下载还是选择aria2。
这货支持各种常见的下载,也支持BT,PT,还能配合插件接管chrome的下载,可以说是比较全能了,而且像百度云的各种三方下载工具,里面也是这货,所以不用不合适呀。
但是aria2的配置项很多,配置好坏对于下载的速度也会产生影响,所以在网上搜索了一下推荐配置,最后找到了一个github的开源项目Aria2-Pro,而且该项目也提供已经封装好的Docker镜像,就更方便了。

  1. 编写启动脚本
cat < /opt/aria2/start-aria2.sh
#/bin/bash
cd `dirname $0`
docker rm -f aria2-pro
docker run -d \
    --name aria2-pro \
    --restart unless-stopped \
    --log-opt max-size=1m \
    -p 6888:6888/udp \
    -p 6888:6888/tcp \
    --ip 172.88.0.9 \
    --network fan \
    -e PUID=$UID \
    -e PGID=$GID \
    -e RPC_PORT=6800 \
    -e LISTEN_PORT=6888 \
    -e DISK_CACHE=4096M \
    -e RPC_SECRET=123456789 \
    -e SPECIAL_MODE=rclone \
    -v $PWD/downloads:/downloads \
    -v $PWD/config:/config \
    p3terx/aria2-pro
EOF

--name:容器名,根据喜好来
--ip 172.88.0.9--network fan:网络设置,具体的根据挂载阿里云的说明
其他属性自己去aria2-pro的作者官网看看吧

  1. 添加rclone的配置文件
    挂载网盘那步我们执行完rclone config后会有一个配置文件~/.config/rclone/rclone.conf,我们将该配置文件复制给aria2的容器
cp ~/.config/rclone/rclone.conf /opt/aria2/config
  1. 启动容器
# 启动容器
sh /opt/aria2/start-aria2.sh
# 查看容器状态是否正常
docker ps -a
  1. 修改aria2-pro的配置
    接下来,我们还需要修改一下/opt/aria2/config目录下的script.conf配置
    drive-name:网盘名称,就是前面配置rclone时设置的name
    drive-dir:网盘目录,你想将文件放到网盘哪个目录就配置哪个
  2. 重启下aria2-pro容器
docker restart aria2-pro

aria2-pro:需要重启的容器名,根据启动脚本name配置

aria2的管理推荐chrome的扩展Aria2 for Chrome

结语

到这儿,当你用aria2下载完小姐姐后,数据会直接上传到阿里云盘你指定的目录下,就可以直接使用阿里云盘客户端观看下载的内容啦,一台离线下载服务器就此完成,BT,PT,HTTP,FTP资源都能支持。
扩展的话可以安装filebrower和nginx,通过nginx为所有服务提供统一的出入口,通过filebrower实现网页管理和浏览相关文件
这两个工具的安装和配置有时间再写了

你可能感兴趣的:(用aria2搭建一台阿里云盘离线下载服务器)