AKZN Notes

Archives for My Lazy and Forgetful Mind

INSTALL aria2 to Ubuntu VPS

Contents

[VPS][UBUNTU] INSTALL aria2

Table of Contents

  1. Install Aria2
  2. Make and configure aria2 config
  3. Make the service handler aria2 on init.d
  4. install Aria2 Webui

Install Aria2

sudo apt install aria2

Make and configure aria2 config

install to your path

sudo nano /path/to/config/aria2/aria2.conf 

configure as required,

  • uncomment the rpc part if you want to use aria2 webui or the likes
  • replace "dir" directory to your download dir path
    
    #
    ## aria2 config
    #
    # man page  = http://aria2.sourceforge.net/manual/en/html/aria2c.html
    # file path = $HOME/.aria2/aria2.conf

Download Directory: specify the directory all files will be downloaded to.

When this directive is commented out, aria2 will download the files to the

current directory where you execute the aria2 binary.

dir=/some/download/

Bit Torrent: If the speed of the incoming data (download) from other peers is

greater then the peer-speed-limit, then do not allow any more connections

then max-peers. The idea is to limit the amount of clients our system will

connect with to reduce our overall load when we are already saturating our

incoming bandwidth. Make sure to set the the peer-speed-limit to your

preferred incoming (download) speed. Speeds are in kilobytes per second or

megebytes per second and must be whole numbers; 5.5M is illegal but 5500K

and 5M is valid.

bt-max-peers=55
bt-request-peer-speed-limit=5M

Bit Torrent: the max upload speed for all torrents combined. Again, only

whole numbers are valid. We find a global upload limit is more flexible then

an upload limit per torrent. Zero(0) is unlimited.

max-overall-upload-limit=5M

Bit Torrent: When downloading a torrent remove ALL trackers from the listing.

This is a good method to only use distributed hash table (DHT) and Peer

eXchange (PeX) on connections. We find start up of the torrent takes 20

seconds longer with all trackers disabled, but helps reduce the load on

trackers.

bt-exclude-tracker="*"

Bit Torrent: ports and protocols used for bit torrent TCP and UDP

connections. Peers use TCP. DHT and PEX as well as UDP based trackers use UDP

and make sure the DHT server is enabled.

dht-listen-port=6881
enable-dht=true
enable-peer-exchange=true
listen-port=6881

When running aria2 on FreeBSD with ZFS, disable disk-cache due to ZFS using

Adaptive Replacement Cache (ARC). ZFS can also take advantage of the "sparse

files" format which is significantly faster then pre allocation of file

space. For other file systems like EXT4 and XFS you can test with "prealloc"

and "falloc" to see which file-allocation allows arai2 to start quicker and

use less disk I/O.

disk-cache=0
file-allocation=none

Bit Torrent: fully encrypt the negotiation as well and the payload of all bit

torrent traffic. Encryption is required and all older, non-encrypted clients

are ignored. This may help avoid some ISPs rate limiting P2P clients, but may

also reduce the amount of clients aria2 will talk to.

bt-min-crypto-level=arc4
bt-require-crypto=true

Bit Torrent: timeout values for servers and clients.

bt-tracker-connect-timeout=10
bt-tracker-interval=900
bt-tracker-timeout=10

Bit Torrent: Download the torrent file into memory (RAM) if there is no need

to save the .torrent file itself. This option works with both magnet and

torrent URL links.

follow-torrent=mem

Bit Torrent: The amount of time and the upload-to-download ratio you wish to

seed to. If either the time limit ( seconds ) or the seed ratio is reached,

torrent seeding will stop. You can set seed-time to zero(0) to disable

seeding completely.

seed-ratio=1.0
seed-time=900

Bit Torrent: scripts or commands to execute before, during or after a

download finishes.

on-bt-download-complete=/path/to/script.sh

on-download-complete=/path/to/script.pl

on-download-error=/path/to/script

on-download-pause=/path/to/script.sh

on-download-start=/path/to/script.pl

on-download-stop=/path/to/script

Event Multiplexing: set polling to the OS type you are using. For FreeBSD,

OpenBSD and NetBSD set to "kqueue". For Linux set to "epoll".

event-poll=poll

Certificate Authority PEM : specify the full path to the OS certificate

authority pem file to verify the peers. On FreeBSD with OpenSSL the following

file path is valid. Without a valid pem file aria2 will print out the error,

"[ERROR] Failed to load trusted CA certificates from no. Cause:

error:02001002:system library:fopen:No such file or directory"

ca-certificate=/usr/local/openssl/cert.pem

Data Integrity: check the MD5 / SHA256 hash of metalink downloads as well as

the hash of bit torrent chunks as our client receives them. CPU time is

reasonably low for the high value of verified data.

check-integrity=true
realtime-chunk-checksum=true

File Names: Resume file downloads if we have a partial copy. Do not rename

the file or make another copy if the same file is downloaded a second time.

allow-overwrite=false
always-resume=true
auto-file-renaming=false
continue=true
remote-time=true

User Agent: Disable the identification string of our client. If you connect

to a server which requires a certain id string you can always add one here.

Trackers should never use client id strings as security authentication or

access control.

peer-id-prefix=""
user-agent=""

Status Summery messages are disabled since the status of the download is

updated in real time on the CLI anyways.

summary-interval=0

FTP: use passive ftp which is firewall friendly and reuse the ftp data

connection when asking for multiple resources from the same server for

efficiency.

ftp-pasv=true
ftp-reuse-connection=true

Metalink: Set the country code to make sure mirrors closest to you are used

first. Prefer more secure https mirrors over http and ftp servers.

metalink-language=en-US
metalink-location=us
metalink-preferred-protocol=https

Disconnect from https, http or ftps server who do not upload data to us

faster then the specified value. Aria2 will then find another mirror in the

metalink file which might be quicker. If there are no more mirrors left then

the current slow mirror is still used. This value is NOT used for bit torrent

connections though. NOTE: we hope to convince the developer to add a

lower-speed value or even a minimal client U/D ratio to bit torrent some day

to kick off leachers too.

lowest-speed-limit=50K

Concurrent downloads: Set the number of different servers to download from

concurrently; i.e. in parallel. If we are downloading a single file then

split that file into the same amount of streams. Make sure to keep in mind

that if the amount of parallel downloads times the lowest-speed-limit is

greater then your total download bandwidth then you will drop servers

incorrectly. For example, we have ten(10) connections at a minimum of

50KiB/sec which equals 500KiB/sec. If our total download bandwidth is not at

least 500KiB/sec then arai2 will think the mirrors are too slow and drop

connection slowing down the whole download. Do not set the

max-connection-per-server greater then one(1) as to avoid abusing a single

server.

max-concurrent-downloads=10
max-connection-per-server=10
min-split-size=5M
split=10

RPC Interface: To access aria2 through XML-RPC API, like using webui-aria2.

enable-rpc

rpc-listen-all

rpc-user=username

rpc-passwd=passwd

Daemon Mode: To run aria2 in the background as a daemon. Use daemon mode to

start aria2 on reboot or when using an RPC interface like webui-aria2.

daemon

#
#

Reference: the following options are commented out and the developers

defaults are used. We kept them here for reference.

bt-max-open-files=100

bt-save-metadata=false

bt-stop-timeout=0

bt-tracker="udp://tracker.openbittorrent.com:80/announce"

check-certificate=true
conditional-get=true

dht-entry-point="dht.transmissionbt.com:6881"

dht-file-path=$HOME/.aria2/dht.dat

dht-message-timeout=10

disable-ipv6=true

http-accept-gzip=true

log=$HOME/.aria2/aria2.log

log-level=debug

EOF


## Make the service handler aria2 on init.d
make file

sudo nano /etc/init.d/aria2

copy this

!/bin/sh

BEGIN INIT INFO

Provides: aria2

Required-Start: $local_fs $remote_fs $network

Required-Stop: $local_fs $remote_fs $network

Should-Start: $network

Should-Stop: $network

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: aria2c init script.

Description: Starts and stops aria2 daemon.

END INIT INFO

USER="root"
DAEMON=/usr/bin/aria2c
CONF=/etc/aria2/aria2.conf

start() {
if [ -f $CONF ]; then
logger -st ARIA2C "Starting aria2c daemon..."
nohup start-stop-daemon -S -c $USER -x $DAEMON -- -D --enable-rpc --conf-path=$CONF
else
logger -st ARIA2C "Couldn't start aria2 daemon (no $CONF found)"
fi
}

stop() {
logger -st ARIA2C "Stoping aria2c daemon..."
start-stop-daemon -o -c $USER -K -u $USER -x $DAEMON
}

status() {
dbpid=`pgrep -fu $USER $DAEMON`
if [ -z "$dbpid" ]; then
logger -st ARIA2C "aria2c daemon not running."
else
logger -st ARIA2C "aria2c daemon running..."
fi
}

case "$1" in
start)
start
sleep 1
;;
stop)
stop
sleep 1
;;
restart)
stop
sleep 2
start
;;
status)
status
;;
*)
echo "Usage: {start|stop|restart|status}"
exit 1
esac

exit 0


Start the service and make sure aria2 is running

chmod +x /etc/init.d/aria2
chkconfig --level 345 aria2 on
service aria2 start
ps -aux | grep aria



## install Aria2 Webui 
download the aria webui from https://github.com/ziahamza/webui-aria2 to ur web server, or follow instruction on the repo 

---
thats it

Leave a Reply

Your email address will not be published.