Installing aria2 + yaaw on CentOS for Offline Downloads

Publish: 2017-07-15 | Modify: 2018-07-16

Last time I shared how to use idle VPS to set up a CDN node: "Smart Parsing + Nginx Reverse Proxy, Self-built CDN Acceleration Node". I feel like the VPS is still not fully utilized, So~ we can also use aria2 + yaaw to achieve offline downloading.

image

Install aria2

aria2 is a lightweight command-line download tool that supports multiple protocols and sources, including HTTP/HTTPS, FTP, SFTP, BitTorrent, and Metalink. aria2 can be operated through its built-in JSON-RPC and XML-RPC interfaces.

The CentOS default software source does not include aria2, so you need to install epel first and then install aria2 by executing the following commands:

# Install epel source
yum -y install epel-release
# Install aria2
yum -y install aria2
# Check aria2 version
aria2c -v

After installation, you can use aria2 for multi-threaded downloading. The commonly used parameters are as follows:

-o: download and rename
-x: number of threads to use, followed by a number, the more threads, the faster the speed (up to 16)
-c: resume download
# Download a file using 16 threads
aria2c -x 16 http://soft.xiaoz.top/windows/ChromeStandaloneSetup.exe

Configure aria2

aria2 has many configuration options. If we want to use the WEB interface for offline downloading, we need to enable JSON-RPC support, modify the following rules appropriately, and save it as /home/soft/aria2/aria2.conf.

# Create download directory
mkdir -p /home/download
# Create folder
mkdir -p /home/soft/aria2
# Create session file
touch /home/soft/aria2/aria2.session
# Save the following content as aria2.conf
vi /home/soft/aria2/aria2.conf
# The path to save the file (absolute or relative), default: current startup position
dir=/home/download
# Enable disk cache, 0 to disable cache, requires version 1.16 or above, default: 16M
# disk-cache=32M
# File allocation method, can effectively reduce disk fragmentation, default: prealloc
# Pre-allocation time: none < falloc ? trunc < prealloc
# falloc and trunc require file system and kernel support
# NTFS recommends using falloc, EXT3/4 recommends trunc, MAC needs to comment out this item
file-allocation=trunc
# Resume download
continue=true

## Download connection related ##

# Maximum number of simultaneous download tasks, can be modified during runtime, default: 5
max-concurrent-downloads=5
# Number of connections to the same server, can be specified when adding, default: 1
max-connection-per-server=5
# Minimum file size for splitting, can be specified when adding, range: 1M -1024M, default: 20M
# Assuming size=10M, if the file is 20MiB, two sources will be used for downloading; if the file is 15MiB, one source will be used for downloading
min-split-size=10M
# Maximum number of threads for a single task, can be specified when adding, default: 5
split=32
# Overall download speed limit, can be modified during runtime, default: 0
# max-overall-download-limit=0
# Download speed limit for a single task, default: 0
# max-download-limit=0
# Overall upload speed limit, can be modified during runtime, default: 0
# max-overall-upload-limit=0
# Upload speed limit for a single task, default: 0
# max-upload-limit=0
# Disable IPv6, default: false
disable-ipv6=true

## Progress saving related ##

# Read download tasks from session file
input-file=/home/soft/aria2/aria2.session
# Save 'error/incomplete' download tasks to session file when Aria2 exits
save-session=/home/soft/aria2/aria2.session
# Save session at regular intervals, 0 to save only when exiting, requires version 1.16.1 or above, default: 0
# save-session-interval=60

## RPC related settings ##

# Enable RPC, default: false
enable-rpc=true
# Allow all sources, default: false
rpc-allow-origin-all=true
# Allow non-external access, default: false
rpc-listen-all=true
# Event polling method, values: [epoll, kqueue, port, poll, select], default value varies on different systems
# event-poll=select
# RPC listening port, can be modified when the port is occupied, default: 6800
# rpc-listen-port=6800
# RPC authorization token, added in version 1.18.4, replaces the --rpc-user and --rpc-passwd options
# rpc-secret=<TOKEN>
# RPC access username, this option is deprecated in the new version, it is recommended to use the --rpc-secret option
# rpc-user=<USER>
# RPC access password, this option is deprecated in the new version, it is recommended to use the --rpc-secret option
# rpc-passwd=<PASSWD>

## BT/PT related ##

# Automatically start BT tasks when downloading a torrent file (ends with .torrent), default: true
# follow-torrent=true
# BT listening port, used when the port is blocked, default: 6881-6999
listen-port=51413
# Maximum number of connections for a single seed, default: 55
# bt-max-peers=55
# Enable DHT, disable for PT, default: true
enable-dht=false
# Enable IPv6 DHT, disable for PT
# enable-dht6=false
# DHT network listening port, default: 6881-6999
# dht-listen-port=6881-6999
# Local node search, disable for PT, default: false
# bt-enable-lpd=false
# Torrent exchange, disable for PT, default: true
enable-peer-exchange=false
# Speed limit for each seed, useful for less seeded PT, default: 50K
# bt-request-peer-speed-limit=50K
# Client disguise, required for PT
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
# Automatically stop seeding when the share ratio of a seed reaches this number, 0 to keep seeding indefinitely, default: 1.0
seed-ratio=0
# Force save session, even if the task is already completed, default: false
# The newer version will keep the .aria2 file after the task is completed when this is enabled
# force-save=false
# BT hash check related, default: true
# bt-hash-check-seed=true
# Do not verify again when resuming previous BT tasks, default: false
bt-seed-unverified=true
# Save magnet link metadata as a torrent file (.torrent file), default: false
bt-save-metadata=true

Then enter the following command to run aria2 in the background. If it fails to start, pay attention to the error message.

# Run aria2c
aria2c --conf-path=/home/soft/aria2/aria2.conf
# If you need it to run persistently, modify it to
nohup aria2c --conf-path=/home/soft/aria2/aria2.conf &

Add authentication

In aria2 version 1.18.4 and above, rpc-secret authentication is added. If you do not want the interface to be publicly accessible, you can uncomment the line rpc-secret= in the configuration above and fill in your own key. In this way, the interface address format will be http://token:key@IP:6800/jsonrpc.

Install yaaw

yaaw is a management tool that provides a WEB interface for aria2. It is completely implemented using HTML + JavaScript, so no script environment is required. Download it to your local machine or deploy it to your WEB server.

# Download yaaw
wget https://github.com/binux/yaaw/archive/master.zip
# Unzip
unzip master.zip
# Move
mv yaaw-master/* ./

If everything goes well, you should be able to see the yaaw interface by visiting http://yourdomain.com/index.html, as shown in the screenshot above.

Set the interface

Click the Settings button in the upper right corner, fill in the WEB interface. If you haven't set a password, the interface address is http://IP:6800/jsonrpc. If you have enabled rpc-secret=, the interface address is http://token:key@IP:6800/jsonrpc. Note that you also need to open port 6800 in the firewall to avoid download failures. In a production environment, it is recommended to set a password for aria2 to prevent malicious downloads.

Some content in this article is referred to from: "Download Artifact - Aria2, Create Your Own Offline Download Server".


Comments