Linux 下aria2 下载神器使用详解

简介

aria2 是一个轻量级的多协议命令行下载实用工具。它支持各种协议,如HTTP, HTTPS, FTP, SFTP, BitTorrent和Metalink。它以使用多个连接同时从多个来源下载文件的能力而闻名,从而提高了下载速度。

安装

  • Debian/Ubuntu
shell 复制代码
sudo apt update
sudo apt install aria2
  • CentOS/RHEL
shell 复制代码
sudo yum install aria2
  • Fedora
shell 复制代码
sudo dnf install aria2

示例用法

下载单个文件

shell 复制代码
aria2c http://example.com/file.zip

下载多个文件

shell 复制代码
aria2c http://example.com/file1.zip http://example.com/file2.zip

使用恢复支持下载文件

-c:可以恢复之前中断的下载

shell 复制代码
aria2c -c http://example.com/largefile.zip

使用多个连接下载文件

默认情况下,aria2 仅使用一个连接来下载文件。要使用多个连接(也称为多线程下载),使用 -x 选项,后跟连接数。

shell 复制代码
aria2c -x 4 http://example.com/largefile.zip

Metalink 是一种提供文件镜像和校验和列表的格式

shell 复制代码
aria2c metalink://example.com/file.metalink

从 Torrent 文件下载

使用 aria2 通过 BitTorrent 下载文件

shell 复制代码
aria2c example.torrent

使用磁力链接下载

shell 复制代码
aria2c "magnet:?xt=urn:btih:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

设置下载速度限制

shell 复制代码
aria2c --max-download-limit=500K http://example.com/file.zip

下载到特定目录

shell 复制代码
aria2c -d /path/to/directory http://example.com/file.zip

后台下载(守护进程模式)

shell 复制代码
aria2c --daemon http://example.com/file.zip

aria2 配置文件

可以使用配置文件来设置 aria2 的默认参数。配置文件通常位于 ~/.aria2/aria2.conf

shell 复制代码
# aria2.conf
continue=true
max-connection-per-server=4
dir=/path/to/downloads
max-download-limit=1M

使用配置文件运行 aria2

shell 复制代码
aria2c --conf-path=/path/to/aria2.conf http://example.com/file.zip

将 aria2 与 JSON-RPC 结合使用

aria2 支持通过 JSON-RPC 进行远程控制,可以通过编程方式或远程方式与程序进行交互

启动 aria2c RPC 服务器

shell 复制代码
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all --rpc-listen-port=6800
  • --enable-rpc:启用 RPC 模式

  • --rpc-listen-all=true:允许来自任何 IP 的连接

  • --rpc-allow-origin-all:允许跨源请求

  • --rpc-listen-port=6800:监听端口 6800

显示下载进度

shell 复制代码
aria2c -q --show-console-readout=false http://example.com/file.zip
  • -q:安静模式(抑制控制台输出)

  • --show-console-readout=false:禁用控制台读数以获得更清晰的显示

检查下载速度

可以通过指定 -j(最大并发下载数量)来获取当前下载速度

shell 复制代码
aria2c -j 4 http://example.com/file.zip

检查文件完整性(哈希检查)

通过检查校验和

shell 复制代码
aria2c --check-integrity http://example.com/file.zip

使用 Cron 自动进行每日下载

shell 复制代码
0 3 * * * /usr/bin/aria2c -d /path/to/directory http://example.com/dailyfile.zip
相关推荐
心灵宝贝21 分钟前
CentOS 7 安装 unzip-6.0-21.el7.x86_64.rpm 步骤详解(附安装包)
linux·服务器·centos
q***133422 分钟前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
Starry_hello world26 分钟前
Linux 文件缓冲区
linux
牢七1 小时前
操作系统。
linux
SongYuLong的博客1 小时前
openwrt源码编译环境搭建-安装Luci
linux·嵌入式硬件
熙客1 小时前
Linux:监控命令
linux·运维
飞鱼&1 小时前
Linux 常用命令
linux·运维·服务器
偶像你挑的噻2 小时前
4-Linux驱动开发-字符设备驱动
linux·运维·驱动开发
遇见火星2 小时前
Linux 网络性能测试实战:用 iperf3 精准测出真实带宽与丢包率
linux·网络·php·iperf3
赖small强2 小时前
【Linux驱动开发】Linux块设备驱动开发详解
linux·驱动开发·块设备·字符设备