aria2下载工具

anonymous_vhacker
anonymous_vhacker
发布于 2023-03-10 / 20 阅读
0
0

aria2下载工具

简介

一款下载神器。相较于IDM、迅雷等,它是命令行版本的,可在Linux中执行。相较于curl、wget等命令行下载工具,它能下的格式更加多。

安装

sudo apt install aria2

使用

RPC配置

配置文件法

参考:https://www.cnblogs.com/zhuxiaoxi/p/7714457.html

新建配置文件/usr/local/aria2.conf

新建session文件/usr/local/aria2.session

aria2.conf如下:

## 进度保存相关 ##

# 从会话文件中读取下载任务
input-file=/usr/local/aria2/aria2.session
# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件
save-session=/usr/local/aria2/aria2.session
# 定时保存会话, 0为退出时才保存, 需1.16.1以上版本, 默认:0
#save-session-interval=60

## 文件保存相关 ##

# 文件的保存路径, 默认: 当前启动位置
dir=/usr/local/aria2/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=5
# 同一服务器连接数, 添加时可指定, 默认:1
max-connection-per-server=5
# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M
# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载
min-split-size=20M
# 单个任务最大线程数, 添加时可指定, 默认:5
#split=5
# 整体下载速度限制, 运行时可修改, 默认:0
#max-overall-download-limit=0
# 单个任务下载速度限制, 默认:0
#max-download-limit=0
# 整体上传速度限制, 运行时可修改, 默认:0
#max-overall-upload-limit=0
# 单个任务上传速度限制, 默认:0
#max-upload-limit=0
# 禁用IPv6, 默认:false
#disable-ipv6=true
# 连接超时时间, 默认:60
#timeout=60
# 最大重试次数, 设置为0表示不限制重试次数, 默认:5
max-tries=30
# 设置重试等待的秒数, 默认:0
retry-wait=20

## RPC相关设置 ##

# 启用RPC, 默认:false
enable-rpc=true
# 允许所有来源, 默认:false
rpc-allow-origin-all=true
# 允许非外部访问, 默认:false
rpc-listen-all=false
# 事件轮询方式, 取值:[epoll, kqueue, port, poll, select], 不同系统默认值不同
#event-poll=select
# RPC监听端口, 端口被占用时可以修改, 默认:6800
#rpc-listen-port=6800
# 设置的RPC授权令牌, v1.18.4新增功能, 取代 --rpc-user 和 --rpc-passwd 选项
rpc-secret=<token>
# 设置的RPC访问用户名, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-user=<USER>
# 设置的RPC访问密码, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-passwd=<PASSWD>
# 是否启用 RPC 服务的 SSL/TLS 加密,
# 启用加密后 RPC 服务需要使用 https 或者 wss 协议连接
#rpc-secure=true
# 在 RPC 服务中启用 SSL/TLS 加密时的证书文件,
# 使用 PEM 格式时,您必须通过 --rpc-private-key 指定私钥
#rpc-certificate=/path/to/certificate.pem
# 在 RPC 服务中启用 SSL/TLS 加密时的私钥文件
#rpc-private-key=/path/to/certificate.key

## BT/PT下载相关 ##

# 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务, 默认:true
#follow-torrent=true
# BT监听端口, 当端口被屏蔽时使用, 默认:6881-6999
listen-port=6881-6999
# 单个种子最大连接数, 默认:55
#bt-max-peers=55
# 打开DHT功能, PT需要禁用, 默认:true
enable-dht=true
# 打开IPv6 DHT功能, PT需要禁用
#enable-dht6=false
# DHT数据存放文件
dht-file-path=/usr/local/aria2/dht.dat
# IPv6 DHT数据存放文件
#dht-file-path6=
# DHT网络监听端口, 默认:6881-6999
dht-listen-port=6881-6999
# 本地节点查找, PT需要禁用, 默认:false
#bt-enable-lpd=false
# 种子交换, PT需要禁用, 默认:true
enable-peer-exchange=true
# 每个种子限速, 对少种的PT很有用, 默认:50K
#bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0
#seed-ratio=0
# 强制保存会话, 即使任务已经完成, 默认:false
# 较新的版本开启后会在任务完成后依然保留.aria2文件
#force-save=false
# BT校验相关, 默认:true
#bt-hash-check-seed=true
# 继续之前的BT任务时, 无需再次校验, 默认:false
bt-seed-unverified=true
# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false
bt-save-metadata=true

接着编写服务文件aria2-rpc.service放到/lib/systemd/system目录中。

[Unit]
Description=Aria2 JSON-RPC service
After=network.target syslog.target multi-user.target
Wants=network.target

[Service]
Type=simple
ExecStart=/usr/bin/aria2c --conf-path=/usr/local/aria2/aria2.conf
Restart=always
RestartSec=6s
KillMode=process

[Install]
WantedBy=multi-user.target

管理服务:

systemctl start aira2-rpc.service #运行服务
systemctl stop aira2-rpc.service #停止服务
systemctl enable aira2-rpc.service #服务自启动
systemctl disable aira2-rpc.service #服务取消自启动

官方帮助文档

用aria2c -h#rpc命令获得

Usage: aria2c [OPTIONS] [URI | MAGNET | TORRENT_FILE | METALINK_FILE]...
Printing options tagged with '#rpc'.
See 'aria2c -h#help' to know all available tags.
Options:
 --enable-rpc[=true|false]    Enable JSON-RPC/XML-RPC server.
                              It is strongly recommended to set secret
                              authorization token using --rpc-secret option.
                              See also --rpc-listen-port option.

                              Possible Values: true, false
                              Default: false
                              Tags: #rpc

 --rpc-listen-port=PORT       Specify a port number for JSON-RPC/XML-RPC server
                              to listen to.

                              Possible Values: 1024-65535
                              Default: 6800
                              Tags: #rpc

 --rpc-user=USER              Set JSON-RPC/XML-RPC user. This option will be
                              deprecated in the future release. Migrate to
                              --rpc-secret option as soon as possible.

                              Tags: #rpc, #deprecated

 --rpc-passwd=PASSWD          Set JSON-RPC/XML-RPC password. This option will
                              be deprecated in the future release. Migrate to
                              --rpc-secret option as soon as possible.

                              Tags: #rpc, #deprecated

 --rpc-max-request-size=SIZE  Set max size of JSON-RPC/XML-RPC request. If aria2
                              detects the request is more than SIZE bytes, it
                              drops connection.

                              Possible Values: 0-*
                              Default: 2M
                              Tags: #rpc

 --rpc-listen-all[=true|false] Listen incoming JSON-RPC/XML-RPC requests on all
                              network interfaces. If false is given, listen only
                              on local loopback interface.

                              Possible Values: true, false
                              Default: false
                              Tags: #rpc

 --rpc-allow-origin-all[=true|false] Add Access-Control-Allow-Origin header
                              field with value '*' to the RPC response.

                              Possible Values: true, false
                              Default: false
                              Tags: #rpc

 --rpc-certificate=FILE       Use the certificate in FILE for RPC server.
                              The certificate must be in PEM format.
                              Use --rpc-private-key option to specify the
                              private key. Use --rpc-secure option to enable
                              encryption.

                              Possible Values: /path/to/file
                              Tags: #rpc

 --rpc-private-key=FILE       Use the private key in FILE for RPC server.
                              The private key must be decrypted and in PEM
                              format. Use --rpc-secure option to enable
                              encryption. See also --rpc-certificate option.

                              Possible Values: /path/to/file
                              Tags: #rpc

 --rpc-secure[=true|false]    RPC transport will be encrypted by SSL/TLS.
                              The RPC clients must use https scheme to access
                              the server. For WebSocket client, use wss
                              scheme. Use --rpc-certificate and
                              --rpc-private-key options to specify the
                              server certificate and private key.

                              Possible Values: true, false
                              Default: false
                              Tags: #rpc

 --rpc-save-upload-metadata[=true|false] Save the uploaded torrent or
                              metalink metadata in the directory specified
                              by --dir option. The filename consists of
                              SHA-1 hash hex string of metadata plus
                              extension. For torrent, the extension is
                              '.torrent'. For metalink, it is '.meta4'.
                              If false is given to this option, the
                              downloads added by aria2.addTorrent or
                              aria2.addMetalink will not be saved by
                              --save-session option.

                              Possible Values: true, false
                              Default: true
                              Tags: #rpc

 --pause[=true|false]         Pause download after added. This option is
                              effective only when --enable-rpc=true is given.

                              Possible Values: true, false
                              Default: false
                              Tags: #advanced, #rpc

 --rpc-secret=TOKEN           Set RPC secret authorization token.

                              Tags: #rpc

 --pause-metadata[=true|false]
                              Pause downloads created as a result of metadata
                              download. There are 3 types of metadata
                              downloads in aria2: (1) downloading .torrent
                              file. (2) downloading torrent metadata using
                              magnet link. (3) downloading metalink file.
                              These metadata downloads will generate downloads
                              using their metadata. This option pauses these
                              subsequent downloads. This option is effective
                              only when --enable-rpc=true is given.

                              Possible Values: true, false
                              Default: false
                              Tags: #advanced, #rpc

Refer to man page for more information.

Aria2 Web 控制台

简易版web控制台

访问:https://aria2c.com/

在设置里输入JSON-RPC Path即可访问aria2的rpc服务。

进阶版web控制台

仓库地址:https://github.com/mayswind/AriaNg


评论