简介
aria2 是一个轻量级、多协议、多线程的命令行下载工具。纯 C 编写,内存占用极小,支持 HTTP(S)、FTP、SFTP、BitTorrent、Metalink 等多种协议。
核心优势: 多线程并行下载,把一个文件切成多块同时拉取,充分利用带宽。单线程跑 50KB/s,开 16 线程合起来就是 800KB/s。
一、安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| sudo apt install -y aria2
sudo dnf install -y aria2 sudo yum install -y aria2
brew install aria2
sudo pacman -S aria2
aria2c --version
|
二、基本用法
命令是 aria2c(末尾的 c 代表 client)。
单文件下载
1 2 3 4 5 6 7 8
| aria2c https://example.com/file.zip
aria2c -o myfile.zip https://example.com/file.zip
aria2c -d /path/to/dir https://example.com/file.zip
|
多线程加速(核心功能)
1 2 3 4
|
aria2c -x 16 -s 16 https://example.com/large_file.iso
|
参数说明:
| 参数 |
含义 |
建议值 |
-x N |
对同一服务器的最大连接数 |
16 |
-s N |
文件分片数 |
与 -x 保持一致 |
注意: -x 不能高于 -s。实际效果取决于服务器是否支持 Range 请求(多线程分段下载的前提)。
断点续传
1 2 3 4 5
| aria2c -c https://example.com/file.zip
aria2c -c -x 16 -s 16 https://example.com/file.zip
|
批量下载
1 2 3 4 5
| aria2c https://a.com/1.zip https://b.com/2.zip https://c.com/3.zip
aria2c -i urls.txt
|
urls.txt 示例:
1 2 3 4 5 6
| https: dir=/path/to/save out=renamed1.iso https: dir=/path/to/save out=renamed2.iso
|
三、进阶用法
限速
1 2 3 4 5
| aria2c --max-download-limit=1M https://example.com/file.zip
aria2c --max-overall-download-limit=5M https://example.com/file.zip
|
设置代理
1 2 3 4 5
| aria2c --all-proxy="http://127.0.0.1:7890" https://example.com/file.zip
aria2c --http-proxy="http://127.0.0.1:7890" https://example.com/file.zip
|
最大并发任务数
1 2
| aria2c -j 10 https://a.com/1.zip https://b.com/2.zip ...
|
BT / 磁力链接下载
1 2 3 4 5 6 7 8 9 10 11
| aria2c example.torrent
aria2c "magnet:?xt=urn:btih:XXXX..."
aria2c --select-file=1,3 example.torrent
aria2c --seed-time=0 example.torrent
|
安静模式 / 控制台输出
1 2 3 4 5 6 7 8
| aria2c -q https://example.com/file.zip
aria2c --quiet https://example.com/file.zip
aria2c --log-level=debug https://example.com/file.zip
|
校验下载
1 2 3 4 5
| aria2c --checksum=sha-256=abc123... https://example.com/file.zip
echo "abc123... file.zip" | sha256sum -c
|
四、配置文件
aria2 支持配置文件,避免每次输入一堆参数。默认路径:
- Linux:
~/.aria2/aria2.conf
- macOS:
~/.aria2/aria2.conf
常用配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
dir=/home/user/Downloads
max-connection-per-server=16
split=16
continue=true
max-concurrent-downloads=5
max-overall-download-limit=0
quiet=false
save-session=~/.aria2/aria2.session save-session-interval=30
bt-max-peers=128 seed-time=0 enable-dht=true bt-enable-lpd=true
|
使用配置文件
1 2 3 4 5
| aria2c https://example.com/file.zip
aria2c --conf-path=/path/to/custom.conf https://example.com/file.zip
|
五、RPC 模式(远程控制)
aria2 可以以后台守护进程模式运行,通过 JSON-RPC 接口接收下载任务。配合 WebUI(如 AriaNg)可实现图形化远程管理。
启动 RPC 模式
1 2 3 4 5
| aria2c --enable-rpc --rpc-listen-all --rpc-allow-origin-all
aria2c --enable-rpc --rpc-secret=mypassword --rpc-listen-port=6801
|
用 curl 调用 RPC
1 2 3 4 5 6 7
| curl "http://localhost:6800/jsonrpc" \ -d '{"jsonrpc":"2.0","id":"1","method":"aria2.addUri","params":["token:mypassword",["https://example.com/file.zip"]]}'
curl "http://localhost:6800/jsonrpc" \ -d '{"jsonrpc":"2.0","id":"2","method":"aria2.tellActive","params":["token:mypassword"]}'
|
作为 systemd 服务运行
1 2 3 4 5 6 7 8 9 10 11
| [Unit] Description=aria2 RPC Daemon After=network.target
[Service] ExecStart=/usr/bin/aria2c --conf-path=%h/.aria2/aria2.conf Restart=on-failure
[Install] WantedBy=default.target
|
1
| systemctl --user enable --now aria2
|
六、实战场景
场景一:下载国内网络慢的大文件(如 kubectl、minikube)
1 2
| aria2c -x 16 -s 16 -o kubectl \ "https://dl.k8s.io/release/v1.36.2/bin/linux/amd64/kubectl"
|
单线程 50KB/s → 多线程 800KB/s,56MB 文件约 1 分钟搞定。
场景二:下载 GitHub Release 文件(国内直连慢)
1 2
| aria2c -x 16 -s 16 \ "https://github.com/user/repo/releases/download/v1.0/archive.zip"
|
场景三:配合镜像站批量下载
1 2
| aria2c -x 8 -s 8 -i urls.txt
|
场景四:断网后断点续传
1 2
| aria2c -c -x 16 -s 16 https://example.com/huge_file.iso
|
七、常用命令速查
| 场景 |
命令 |
| 快速下载 |
aria2c <URL> |
| 多线程加速 |
aria2c -x 16 -s 16 <URL> |
| 指定文件名 |
aria2c -o name.zip <URL> |
| 指定目录 |
aria2c -d /path <URL> |
| 断点续传 |
aria2c -c <URL> |
| 终极组合 |
aria2c -c -x 16 -s 16 -o name <URL> |
| 批量下载 |
aria2c -i urls.txt |
| 磁力链接 |
aria2c "magnet:?xt=urn:btih:..." |
| 种子文件 |
aria2c file.torrent |
| 限速 1MB/s |
aria2c --max-download-limit=1M <URL> |
| 代理下载 |
aria2c --all-proxy="http://127.0.0.1:7890" <URL> |
八、对比其他工具
| 工具 |
多线程 |
断点续传 |
BT/磁力 |
轻量 |
命令行 |
| aria2 |
✅ |
✅ |
✅ |
✅ |
✅ |
| curl |
❌ |
✅ (-C) |
❌ |
✅ |
✅ |
| wget |
❌ |
✅ (-c) |
❌ |
✅ |
✅ |
| axel |
✅ |
✅ |
❌ |
✅ |
✅ |
| uGet |
✅ |
✅ |
❌ |
❌ |
❌ |
aria2 几乎是命令行下载工具中最全能的,既轻量又支持多协议多线程。