download source code
Install some necessary dependencies
apt install -y libcurl4-openssl-dev libevent-dev \
ca-certificates libssl-dev pkg-config \
build-essential intltool libgcrypt-dev \
libssl-dev libxml2-dev
Download the latest aria2 source code:
wget --no-check-certificate https://github.com/aria2/aria2/releases/download/release-1.31.0/aria2-1.31.0.tar.gz
tar zxf aria2-1.31.0.tar.gz
cd ./aria2-1.31.0
Modify the source code
The parameters of Aria2 -max-server-connection
largely -min-split-files
determine the download speed of the network disk.
Here I -max-server-connection
set the highest to 256 and -min-split-files
the smallest to 256k.
#aira2的基本配置选项大多都存储在文件OptionHandlerFactory.cc中
vi src/OptionHandlerFactory.cc
#定位到441行
#将服务器最大连接数16修改为256
OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONNECTION_PER_SERVER,
TEXT_MAX_CONNECTION_PER_SERVER,
// "1", 1, 16, 'x'));
"1", 1, 256, 'x'));
#定位到第503行
#将最文件分片大小设置为256_k
#到此源代码需要修改的地方改完了
OptionHandler* op(new UnitNumberOptionHandler(
//PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "1M", 1_m, 1_g, 'k'));
PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "1M", 256_k, 1_g, 'k'));
Parameter settings before compilation
./configure
compile
make
After compiling
cp src/aria2c /usr/local/bin
Check if the installation was successful
aria2c -v
If the version number can be displayed, it means success.
configuration
Create a new aria2 directory in /etc, and create a new configuration file aria2.conf
mkdir -p /etc/aria2
vi /etc/aria2/aria2.conf
Insert the following:
dir=/home/wen/Downloads # 这里改成绝对路径
disable-ipv6=true
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-listen-port=6800
continue=true
input-file=/etc/aria2/aria2.session
#rpc-user=admin
#rpc-passwd=password
save-session=/etc/aria2/aria2.session
save-session-interval=7200
max-concurrent-downloads=20
max-connection-per-server=256
min-split-size=256k
#log=/var/log/aria2/aria2.log
# Complete delete .aria2 files
on-download-complete=/etc/aria2/delete_aria2
max-overall-upload-limit=5K
max-upload-limit=5K
follow-torrent=true
#BT
bt-request-peer-speed-limit=200K
#PT download
bt-max-peers=48
listen-port=26834
enable-dht=false
bt-enable-lpd=false
enable-peer-exchange=false
user-agent=uTorrent/341(109279400)(30888)
peer-id-prefix=-UT341-
seed-ratio=0
force-save=true
bt-hash-check-seed=true
bt-seed-unverified=true
bt-save-metadata=true
Create a new aria2.session to store some information being downloaded
touch /etc/aria2/aria2.session
start up
Startup file configuration
#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Aria2 Downloader
### END INIT INFO
case "$1" in
start)
echo -n "Starting aria2cn"
sudo -u root aria2c --conf-path=/etc/aria2/aria2.conf -D
#sudo -u后面的是你正在使用的用户名,因为我用的root
;;
stop)
echo -n "Shutting down aria2c "
killall aria2c
;;
restart)
echo -n "Shutting down aria2c "
killall aria2c
sleep 3
echo -n "Starting aria2c"
sudo -u root aria2c --conf-path=/etc/aria2/aria2.conf -D
#同上面的一样,根据自己的用户名改root。
;;
*)
echo 'Usage:' `basename $0` '[option]'
echo 'Available option:'
for option in start stop restart
do
echo ' -' $option
done
;;
esac
Give the startup file a permission and run aria2 automatically when booting
sudo chmod 755 /etc/init.d/aria2c
update-rc.d aria2c defaults
start aria2
sudo service aria2c start