メインコンテンツへスキップ

aria2 Complete Documentation

aria2 ドキュメント:インストール・設定・自動化

aria2 は C++ で書かれた無料・オープンソースのマルチプロトコル対応 CLI ダウンロードツールで、HTTP、HTTPS、FTP、SFTP、BitTorrent、Metalink をサポートしています。最大 16 本の並列接続を同時に開くことで、接続ごとの速度が制限されたサーバーでは wget や curl より数倍高速にダウンロードしながら、メモリ使用量はわずか 4–9 MiB に抑えられます。Windows、macOS、Linux、Android に対応し、GUI は不要です。

このドキュメントでは、Windows、Linux、macOS へのインストール方法、高度なプロトコルエンジンの設定、aria2 を独自の自動化パイプラインに組み込む方法を習得できます。

bash
# 1. Install dependencies (Debian/Ubuntu) $sudo apt install libgnutls28-dev nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config # 2. Clone and Build $git clone https://github.com/aria2/aria2.git $cd aria2 $autoreconf -i $./configure $make # OPTIONAL: Build a single static binary for portability $./configure ARIA2_STATIC=yes

クロスコンパイル: aria2 は mingw-config と android-config ラッパーを使い、MinGW および NDK ツールチェーンでそれぞれ Windows(.exe)用と Android 用のバイナリを生成します。

基本的な HTTP・FTP 設定

aria2 は通常の HTTP/FTP ダウンロードをそのまま優れた性能で処理しますが、真の強みは プロトコルのハイブリッド化にあります。HTTP/FTP/SFTP と BitTorrent からファイルを 同時にダウンロードし、直接取得したデータを BitTorrent スウォームにアップロードすることで効率を最大化できます。

注意: aria2 は純粋なコマンドラインプログラムおよび RPC バックエンドです。-x 16 で 16 接続を開くと、一部のサーバーでは IP が一時的にレート制限される場合があります。同時接続数の上限は責任を持って調整してください。

cli
# Standard execution $aria2c http://example.org/mylinux.iso # Pull from 16 connections simultaneously, splitting the file into 16 chunks $aria2c -x 16 -s 16 http://example.org/mylinux.iso # Parameterized URI: Download file01.iso through file05.iso in one go $aria2c "http://example.org/file{01,02,03,04,05}.iso" # Set custom User-Agent and Referer headers $aria2c --user-agent="MyBrowser/1.0" --referer="http://google.com" http://file.com/d.zip

バッチ自動化

スクレイピング、ミラーの同期、バッチ処理では、数千件の URL を記載したテキストファイルをそのまま aria2 に読み込ませることができます。-i(input) パラメーターを使うことで、これらを並列に高速ダウンロードします。

cli
# Read all targets from a formatted text document $aria2c -i huge_list.txt --max-concurrent-downloads=5 # Parameterized bash expansion downloading $aria2c -Z -P "http://host/image[000-100].png"

BitTorrent 詳細解説

aria2 はコアエンジンに統合された本格的な BitTorrent クライアント機能を備えています。DHT ルーティングテーブル、Local Peer Discovery(LPD)、Magnet URI の解決にネイティブ対応しています。

注意: aria2 は BitTorrent の WebSeeding をネイティブサポートする数少ないクライアントの一つです。通常の HTTP ミラーを P2P スウォームに同時に安全に組み込むことができます!

cli
# Download via .torrent file using 55 max peers $aria2c --bt-max-peers=55 ubuntu.torrent # Download via Magnet URI cleanly $aria2c "magnet:?xt=urn:btih:248D0A1CD...&dn=ubuntu" # Stop seeding automatically when ratio hits 1.5 $aria2c --seed-ratio=1.5 ubuntu.torrent

認証とクラウドのバイパス(Cookie)

最近の多くのミラーサイトでは、プレミアム回線やプライベートな帯域制限を利用するためにログインセッションが必要です。Google Chrome や Firefox から cookies.txt ファイルを直接エクスポートして aria2 に渡すことで、ヘッドレスダウンロードを即座に認証できます。

cli
# Impersonate your active browser session directly $aria2c --load-cookies=cookies.txt https://host/premium-file.rar # Standard HTTP Basic Auth $aria2c --http-user="admin" --http-passwd="password" http://...

再開と復旧

wget とは異なり、aria2 は非常に堅牢なファイル復旧機能を備えています。大容量ファイルの転送中にインターネットが切断されたり電源が落ちたりしても、-c / --continue フラグでデータ検証をシームレスに再開できます。

cli
# Resume a broken download $aria2c -c http://example.org/mylinux.iso

-c を使わずに同名ファイルが既に存在する場合、aria2 は誤って上書きしないよう、新しいダウンロードを既定で mylinux.1.iso に自動リネームします。

帯域制限(スロットリング)

バックグラウンドでダウンロードする際に aria2 が家庭内ネットワークを占有しないよう、厳密な制限値を設定しましょう。制限はデーモン全体にグローバルに適用することも、タスクごとに個別に適用することもできます。

cli
# Restrict the entire aria2 daemon to 2 megabytes per second $aria2c --max-overall-download-limit=2M -i urls.txt # Restrict EACH specific task to 500 kilobytes per second $aria2c --max-download-limit=500K http://example.org/hq.mp4

ディスク割り当てと高速 I/O

16 分割の並列接続で 50GB を超えるような巨大ファイルをダウンロードすると、メカニカル HDD(や普及帯の SSD)ではファイルシステムの断片化が激しくなり、速度低下を招きます。

aria2 の falloc エンジンは、ダウンロード開始前にカーネルレベルでブロック割り当てを事前に確保するよう OS に直接指示します。

cli
# Pre-allocate blocks (Supported on Ext4, XFS, Btrfs, and NTFS) $aria2c --file-allocation=falloc http://example.org/50G.iso

チェックサムと完全性

転送中または転送後にハッシュ値の検証を強制することで、ダウンロードファイルの破損や改ざんを確実に検出できます。

cli
# Verify MD5/SHA-256 hash immediately upon completion $aria2c --checksum=sha-256=HASH_STRING http://example.org/file.zip # Deep repair: Check existing file pieces and only download the broken ones $aria2c --check-integrity=true ubuntu.torrent

高度なネットワーク設定と IPv6

マルチホームサーバーや VPN 構成で特に役立つ、aria2 がローカルのハードウェアインターフェースにバインドする方法を微調整できます。

cli
# Disable IPv6 if your network/ISP doesn't support it $aria2c --disable-ipv6=true http://example.org/file # Bind all traffic to a specific local interface (e.g., eth1) $aria2c --interface=eth1 http://example.org/file # Happy Eyeballs: Optimized IPv6/IPv4 fallback algorithm is used by default.

プロキシ設定

aria2 は HTTP プロキシ(HTTPS は CONNECT 経由)、SSL 検証の上書き、明示的な IPv6 バインドに対応しています。SOCKS プロキシには対応していないため、SOCKS5 トンネルしかない場合は privoxy や gost などの HTTP→SOCKS 変換プロキシを使ってください。

cli
# Route downloads through an HTTP proxy (aria2 has no SOCKS support) $aria2c --all-proxy="http://127.0.0.1:8080" http://example.org/ # Bypass untrusted SSL server certificate halts natively $aria2c --check-certificate=false https://raw-server.net/

セキュリティと暗号化

BitTorrent 転送では暗号化を強制して ISP によるのぞき見や帯域制限を回避できます。また、安全な HTTP 接続のために厳密な SSL 証明書要件を定義することもできます。

cli
# Require BitTorrent encryption (refuse non-encrypted peers) $aria2c --bt-require-crypto=true ubuntu.torrent # Use a specific CA certificate to verify the server $aria2c --ca-certificate=/path/to/ca.pem https://secure-server.com/

デーモンサービス

aria2 をバックグラウンドで完全に分離して実行します。VPS、Seedbox、ヘッドレスサーバー環境の構築に不可欠です。

cli
# Run as a background daemon process $aria2c --daemon=true --enable-rpc=true --conf-path=/etc/aria2.conf

ヒント: デーモンサービスを使わずにバックグラウンドダウンロードを対話的に管理したい場合は、デタッチした tmux セッション内で aria2c を実行できます。

RPC サブシステム(リモートコントロール)

JSON-RPC インターフェースを使うと、リモートサーバー、モバイルアプリ、AriaNg のような Web GUI から aria2 にコマンドを送信できます。

cli
# Start the RPC Server securely on port 6800 $aria2c --enable-rpc --rpc-listen-all --rpc-secret=mySecretToken # Simple curl call to add a download via RPC $curl -X POST -d '{"jsonrpc":"2.0","id":"q","method":"aria2.addUri","params":["token:mySecretToken",["URL"]]}' http://localhost:6800/jsonrpc
メソッド 説明
aria2.addUri 新しい HTTP/FTP/SFTP ダウンロードを追加します。
aria2.addTorrent .torrent ファイルをアップロードして BitTorrent ダウンロードを追加します。
aria2.tellStatus 指定した GID の進捗・状態を返します。
aria2.pauseAll 実行中のすべてのダウンロードを即座に一時停止します。
aria2.getOption 指定した GID の設定フラグを取得します。

イベントフックとスクリプト連携

Aria2 内蔵のイベントリスナーを使って自動タスクを起動できます。ファイルパスや GID などの変数を外部の bash 環境に渡せます。

cli
# Trigger "unzip.sh" immediately upon successful 100% completion $aria2c --on-download-complete=/opt/scripts/unzip.sh http://...

完璧な aria2.conf

手動フラグの指定を省くため、静的な設定ファイル(通常は ~/.aria2/aria2.conf)でエンジンの動作をしっかり定義しましょう。

~/.aria2/aria2.conf
# --- Performance Tuning --- max-connection-per-server=16 split=16 file-allocation=falloc # --- RPC Server --- enable-rpc=true rpc-secret=YOUR_KEY # --- State --- save-session=~/.aria2/aria2.session input-file=~/.aria2/aria2.session

環境変数

aria2 は端末プロファイルから OS 標準のプロキシ変数をネイティブに読み取ります。

変数 説明
http_proxy HTTP リクエスト用の既定プロキシ。
https_proxy HTTPS リクエスト用の既定プロキシ。
all_proxy グローバルプロキシサーバー。
no_proxy プロキシ経由をバイパスするドメイン。

コンソールの進捗表示を理解する

コンソールエンジンが提供するリアルタイムのスナップショット文字列です。

cli
[#GID 123MB/456MB(27%) CN:16 DL:5.2MB UL:12KB ETA:1m45s]

  • GID: タスクの一意識別子。
  • CN: アクティブな接続数。
  • DL / UL: 現在のダウンロード・アップロード速度。
  • ETA: 推定残り時間。

技術ファイルと形式

内部で使用されるバイナリレイアウトと状態ファイルです。

ファイル 用途
dht.dat DHT ルーティングテーブルを格納します(バイナリ)。
.netrc HTTP/FTP の自動認証情報。
aria2.session 一時停止・再開用のセッション状態。
*.aria2 v1 バイナリ制御ファイル(ビッグエンディアン)。

tips
Netrc 形式: machine example.com login user password password

終了ステータスコード

スクリプト内で $? を解析して、失敗を適切に処理しましょう。

コード 意味
0 成功
1 不明なエラー
3 404 Not Found
9 ディスク容量不足

パワーユーザー向けのヒントと単位

tips
単位: - K/M: 10進数(1000) - Ki/Mi: 2進数(1024)

無制限値: 無制限には - または 0 を使います。

開発者向け連携(libaria2)

モダンな C++11 ライブラリインターフェースです。

cpp
#include <aria2/aria2.h> aria2::libraryInit(); aria2::sessionNew(aria2::KeyVals(), config);