aria2
來自 aria2 主頁:
- aria2 是一個輕量級多協議多源命令行下載工具,支持 HTTP/HTTPS, FTP,BitTorrent 和 Metalink。用户可以通過內置的 JSON-RPC 和 XML-RPC 接口操作 aria2。
安裝[編輯 | 編輯原始碼]
要以守護進程運行 aria2,你可以寫一個 systemd 用户單元。
配置[編輯 | 編輯原始碼]
aria2.conf[編輯 | 編輯原始碼]
aria2 默認從 $XDG_CONFIG_HOME/aria2/aria2.conf
中尋找全局配置,該行為可以通過 --conf-path
選項改變:
- 下面的示例用配置文件
/file/aria2.rapidshare
中的選項下載aria2.example.rar
:
$ aria2c --conf-path=/file/aria2.rapidshare http://rapidshare.com/files/12345678/aria2.example.rar
如果存在 $XDG_CONFIG_HOME/aria2/aria2.conf
,但希望使用 /file/aria2.rapidshare
中的選項,需要在命令中加入 --no-conf
選項:
- 若不使用默認的配置文件,只使用
/file/aria2.rapidshare
中的選項下載aria2.example.rar
:
$ aria2c --no-conf --conf-path=/file/aria2.rapidshare http://rapidshare.com/files/12345678/aria2.example.rar
如果不存在 $XDG_CONFIG_HOME/aria2/aria2.conf
,並且你想要簡化配置管理:
$ touch $XDG_CONFIG_HOME/aria2/aria2.conf
示例 aria2.conf[編輯 | 編輯原始碼]
continue dir=${HOME}/Desktop file-allocation=none input-file=${HOME}/.aria2/input.conf log-level=warn max-connection-per-server=4 min-split-size=5M on-download-complete=exit
這與執行下面的命令等價:
$ aria2c --dir=${HOME}/Desktop --file-allocation=none --input-file=${HOME}/.aria2/input.conf --on-download-complete=exit --log-level=warn FILE
選項細節[編輯 | 編輯原始碼]
continue
: 如果存在下載任務對應的控制文件,自動繼續未完成的下載任務。dir=${HOME}/Desktop
: 在~/Desktop
中存儲下載文件。file-allocation=none
: 不要在下載開始前預分配磁盤空間(默認值:prealloc1input-file=${HOME}/.aria2/input.conf
: 從~/.aria2/input.conf
中的 URI 下載文件,URI 以 TAB 分割。log-level=warn
: 設置日誌級別,只輸出警吿和錯誤。(默認值:debug)max-connection-per-server=4
: 設置每個伺服器的最大連結數為 4。(默認值:1)min-split-size=5M
: 只在文件大小超過 2*5MB = 10MB 時分割文件。(默認值: 20M)on-download-complete=exit
: 當下載任務完成時,運行exit
命令並退出 shell。
示例輸入文件 #1[編輯 | 編輯原始碼]
從兩個分別的地址下載 aria2-1.10.0.tar.bz2
到 ~/Desktop
,並合併為 aria2-1.10.0.tar.bz2
http://aria2.net/files/stable/aria2-1.10.0/aria2-1.10.0.tar.bz2 http://sourceforge.net/projects/aria2/files/stable/aria2-1.10.0/aria2-1.10.0.tar.bz2
示例輸入文件 #2[編輯 | 編輯原始碼]
下載 aria2-1.9.5.tar.bz2
,命名為 aria2.old.tar.bz2
,保存到 /file/old
http://aria2.net/files/stable/aria2-1.9.5/aria2-1.9.5.tar.bz2 dir=/file/old out=aria2.old.tar.bz2
下載 aria2-1.10.0.tar.bz2
,命名為 aria2.new.tar.bz2
,保存到 ~/Desktop
http://aria2.net/files/stable/aria2-1.10.0/aria2-1.10.0.tar.bz2 out=aria2.new.tar.bz2
備註[編輯 | 編輯原始碼]
1 --file-allocation=falloc
: 推薦在新的文件系統,比如 ext4 (具有 extents 支持的)、btrfs 或者 XFS 上,使用這個選項,因為它們幾乎可以瞬間分配 GB 級別的大文件。不要在傳統的文件系統,比如 ext3 上,使用 falloc,因為預分配會消耗與正常分配相同的時間,還會阻塞 aria2 下載。
aria2c --help=#all
和 aria2c(1) § OPTIONS。[編輯 | 編輯原始碼]
http-user=USER_NAME http-passwd=PASSWORD allow-overwrite=true dir=/file/Downloads file-allocation=falloc enable-http-pipelining=true input-file=/file/input.rapidshare log-level=error max-connection-per-server=2 summary-interval=120
選項細節[編輯 | 編輯原始碼]
http-user=USER_NAME
: 設置 HTTP 用户名為 USER_NAME。這會影響所有的 URI。http-passwd=PASSWORD
: 設置 HTTP 密碼為 PASSWORD。這會影響所有的 URI。allow-overwrite=true
: 如果控制文件不存在,重新下載。(默認值:false)dir=/file/Downloads
: 存儲下載文件到/file/Downloads
。file-allocation=falloc
: 在下載開始前,調用 posix_fallocate(3) 分配磁盤空間。(默認值:prealloc)enable-http-pipelining=true
: 啟用 HTTP/1.1 流水線來降低網絡延遲的影響,並減少數據用量。(默認值:false)input-file=/file/input.rapidshare
: 從/file/input.rapidshare
中的 URI 下載文件,URI 以 TAB 分割。log-level=error
: 設置日誌級別,只輸出錯誤。(默認值:debug)max-connection-per-server=2
: 設置每台伺服器每個文件的最大連結數為 2。(默認值:1)summary-interval=120
: 每 120 秒輸出下載進度匯總。(默認值:60)2
備註[編輯 | 編輯原始碼]
- 因為
aria2.rapidshare
包含用户名和密碼,建議將該文件權限設置為 600 或類似的權限。
$ cd /file $ chmod 600 /file/aria2.rapidshare $ ls -l total 128M -rw------- 1 arch users 167 Aug 20 00:00 aria2.rapidshare
2 summary-interval=0
: 不顯示下載進度匯總,可以提高總體性能。日誌仍然會按照 log-level
選項的配置輸出。
示例 aria2.bittorrent[編輯 | 編輯原始碼]
bt-seed-unverified max-overall-upload-limit=1M max-upload-limit=128K seed-ratio=5.0 seed-time=240
選項細節[編輯 | 編輯原始碼]
bt-seed-unverified=false
: 在做種前不檢查文件哈希。(默認值:true)max-overall-upload-limit=1M
: 設置全局最大上傳速度為 1MB/sec。(默認值:0)max-upload-limit=128K
: 設置每個種子的最大上傳速度為 128K/sec。(默認值:0)seed-ratio=5.0
: 下載完成後持續做種直到分享率達到 5.0。(默認值:1.0)seed-time=240
: 下載完成後做種 240 分鐘。
seed-ratio
和 seed-time
,當至少一個條件滿足時就會停止做種。示例 aria2.daemon[編輯 | 編輯原始碼]
這個配置可以用於以服務啟動的 aria2。可以與下面的前端一起使用。注意 rpc-user 與 rpc-pass 選項已經被棄用,但許多前端還不支持新的認證系統。記得修改用户名、密碼和下載目錄。
continue daemon=true dir=/home/aria2/Downloads file-allocation=falloc log-level=warn max-connection-per-server=4 max-concurrent-downloads=3 max-overall-download-limit=0 min-split-size=5M enable-http-pipelining=true enable-rpc=true rpc-listen-all=true rpc-user=rpcuser rpc-passwd=rpcpass
前端[編輯 | 編輯原始碼]
aria2
本身的配置,不確定不同的前端是否會在提供了自定義配置時,復用 aria2
的配置。用户應當確認選擇的工具能效實現,並能持久保存配置。(比如 uGet 提供了自己的 aria2
命令行,並且會在重啟間保存配置)。Web UIs[編輯 | 編輯原始碼]
aria2c
以 --enable-rpc
選項啟動。它們應該在你本地的設備,而不是遠程伺服器上運行。- WebUI — Aria2 的 HTML 前端。
- aria2rpc — 用於連接遠程
aria2c
實例的命令行工具。如果安裝了aria2c
,該程序可以在/usr/share/doc/aria2/xmlrpc/aria2rpc
下找到。
- AriaNg — 純 HTML & JavaScript 實現的aria2前端,也提供桌面客户端。
其他 UIs[編輯 | 編輯原始碼]
aria2c
以 --enable-rpc
選項啟動。- aria2fe — 一個命令行下載工具 aria2 的 GUI。
- Persepolis — Aria2 下載管理器的圖形前端,具有許多功能,支持 HTTP 和 FTP。
- uGet — 功能豐富的 GTK/CLI 下載管理器,可以通過內置的插件,使用 aria2 作為後端。
- Motrix — 基於 aria2 的全功能下載管理器,支持 HTTP、FTP、BitTorrent 和 Magnet。
提示與技巧[編輯 | 編輯原始碼]
下載但不安裝軟件包[編輯 | 編輯原始碼]
只需要用下面的命令:
# pacman -Sp packages | aria2c -i -
pacman -Sp
在標準輸出裡打印軟件包的 URL,而不是下載它們,然後用 |
管道傳給下一個命令。最後,aria2c -i -
裡的 -i
意味着下載文件的 URL 應該從文件裡指定。但如果傳入了 -
,就從 stdin 裡讀取 URL。
pacman XferCommand[編輯 | 編輯原始碼]
改變 User Agent[編輯 | 編輯原始碼]
一些站點會根據你的 User Agent 過濾請求,由於 aria2 並不出名,使用主流下載器或瀏覽器的 User Agent 可能會更好。只需要像這樣使用 -U
選項:
$ aria2c -UWget http://some-url-to-download/file.xyz
你可以任意指定 User Agent,比如 -UMozilla/5.0 等。
在 makepkg 中使用 aria2[編輯 | 編輯原始碼]
你可以使用 aria2 代替 curl包 來下載源文件,只需要像下面一樣更改 DLAGENTS
變量:
/etc/makepkg.conf
[...] DLAGENTS=('ftp::/usr/bin/aria2c -UWget -s4 -x4 %u -o %o' 'http::/usr/bin/aria2c -UWget -s4 -x4 %u -o %o' 'https::/usr/bin/aria2c -UWget -s4 -x4 %u -o %o' 'rsync::/usr/bin/rsync --no-motd -z %u %o' 'scp::/usr/bin/scp -C %u %o') [...]
-UWget
選項改變 user agent 為 Wget,可以防止下載文件時,站點根據不同的 user agent 提供不同的響應。由於 aria2 不是著名的下載器,可能會被站點識別為瀏覽器而不是下載器,所以使用 Wget 的 user agent 可以在大多數情況下解決問題。作為守護進程使用 aria2[編輯 | 編輯原始碼]
要使用 aria2 作為守護進程,你可以 寫一個systemd用户單元。比如:
~/.config/systemd/user/aria2cd.service
[Unit] Description=aria2 Daemon [Service] Type=simple ExecStart=/usr/bin/aria2c --conf-path=/path/to/conf [Install] WantedBy=default.target
#示例 aria2.daemon 展示了配置文件示例。
使用 aria2 做種[編輯 | 編輯原始碼]
要做種下載好的種子,使用 --check-integrity
選項:
$ aria2c --check-integrity=true --seed-ratio=0.0 --dir="/path/to/iso" "/path/to/torrent/archlinux-2020.03.01-x86_64.iso.torrent"
指定 --seed-ratio=0.0
選項可以永久做種。