2021-03-25更新:快速部署考虑Aria2 一键安装管理脚本 增强版

前言

由于想使用网盘的离线下载功能,需要搭建aria2,特此记录。

一、编译安装Aira2

安装wget

1
yum install wget

安装编译器

1
yum install gcc gcc-c++

创建aria2目录

1
2
mkdir -p /home/aria2/downloads
cd /home/aria2

下载并解压aira2

1
2
wget https://github.com/aria2/aria2/releases/download/release-1.33.1/aria2-1.33.1.tar.gz
tar -xzvf aria2-1.33.1.tar.gz

编译安装aria2

1
2
3
4
5
cd aria2-1.33.1
./configure
make
cd src
cp aria2c /usr/bin

安装完成后执行

1
aria2c -v

出现”aria2 version 1.33.1”等代码则安装成功

接下来设置aria2c

1
2
touch /home/aria2/aria2.session
vim /home/aria2/aria2.conf

内容为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
## 文件保存相关 ##

# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置
dir=/home/aria2/downloads
# 启用磁盘缓存, 0为禁用缓存, 需1.16以上版本, 默认:16M
disk-cache=32M
# 文件预分配方式, 能有效降低磁盘碎片, 默认:prealloc
# 预分配所需时间: none < falloc ? trunc < prealloc
# falloc和trunc则需要文件系统和内核支持
# NTFS建议使用falloc, EXT3/4建议trunc, MAC 下需要注释此项
file-allocation=trunc
# 断点续传
continue=true

## 下载连接相关 ##

# 最大同时下载任务数, 运行时可修改, 默认:5
max-concurrent-downloads=10
# 同一服务器连接数, 添加时可指定, 默认:1
max-connection-per-server=10
# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M
# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载
min-split-size=20M
# 单个任务最大线程数, 添加时可指定, 默认:5
split=10
# 整体下载速度限制, 运行时可修改, 默认:0
max-overall-download-limit=0
# 单个任务下载速度限制, 默认:0
max-download-limit=0
# 整体上传速度限制, 运行时可修改, 默认:0
max-overall-upload-limit=500K
# 单个任务上传速度限制, 默认:0
max-upload-limit=100K
# 禁用IPv6, 默认:false
disable-ipv6=false

## 进度保存相关 ##

# 从会话文件中读取下载任务
input-file=/home/aria2/aria2.session
# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件
save-session=/home/aria2/aria2.session
# 定时保存会话, 0为退出时才保存, 需1.16.1以上版本, 默认:0
save-session-interval=60
# 强制保存会话, 即使任务已经完成, 默认:false
# 较新的版本开启后会在任务完成后依然保留.aria2文件
force-save=true
bt-hash-check-seed=true
bt-seed-unverified=true
bt-save-metadata=true

## RPC相关设置 ##

# 启用RPC, 默认:false
enable-rpc=true
# 允许所有来源, 默认:false
rpc-allow-origin-all=true
# 允许非外部访问, 默认:false
rpc-listen-all=true
# 事件轮询方式, 取值:[epoll, kqueue, port, poll, select], 不同系统默认值不同
event-poll=select
# RPC监听端口, 端口被占用时可以修改, 默认:6800
rpc-listen-port=6800
# 设置的RPC授权令牌, v1.18.4新增功能, 取代 --rpc-user 和 --rpc-passwd 选项
rpc-secret=123456

## BT/PT下载相关 ##

# 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务, 默认:true
follow-torrent=true
# BT监听端口, 当端口被屏蔽时使用, 默认:6881-6999
listen-port=19999
# 单个种子最大连接数, 默认:55
bt-max-peers=100
# 打开DHT功能, PT需要禁用, 默认:true
enable-dht=true
# 打开IPv6 DHT功能, PT需要禁用
enable-dht6=false
# DHT网络监听端口, 默认:6881-6999
dht-listen-port=6881-6999
# 本地节点查找, PT需要禁用, 默认:false
bt-enable-lpd=true
# 种子交换, PT需要禁用, 默认:true
enable-peer-exchange=true
# 每个种子限速, 对少种的PT很有用, 默认:50K
bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0
seed-ratio=0.2
# BT校验相关, 默认:true
bt-hash-check-seed=true
# 继续之前的BT任务时, 无需再次校验, 默认:false
bt-seed-unverified=true
# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false
bt-save-metadata=false
#强制加密, 防迅雷必备
bt-require-crypto=true
#添加额外tracker#
#bt-tracker=

其中RPC相关设置中的秘钥在ariang管理面板需要填写,默认123456,完成后到服务器安全组开放6800端口

执行命令使配置生效

1
aria2c --conf-path=/home/aria2/aria2.conf -D

设置开机自启动

1
vim /etc/rc.d/rc.local

在最后添加

1
aria2c --conf-path=/home/aria2/aria2.conf -D

二、编译安装Nginx Web服务器

安装nginx依赖

1
2
3
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel

下载并解压nginx

1
2
3
cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz

编译安装nginx

1
2
3
4
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
make
make install

创建nginx账号

1
2
3
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
1
vim nginx.conf

将第一行”#user nobody”改为

1
user nginx nginx

ESC+:wq+Enter保存并退出

启动nginx

1
/usr/local/nginx/sbin/nginx

浏览器输入服务器公网IP,出现Welcome to nginx!则成功

将nginx添加到系统服务

1
vim /usr/lib/systemd/system/nginx.service

内容为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

结束nginx进程

1
2
lsof -i:80
kill -9 进程号

执行

1
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

通过系统服务启动nginx

1
systemctl start nginx

设置为开机启动

1
systemctl enable nginx

重启服务器后在浏览器输入公网IP查看是否成功

三、搭建Aria2Ng Web面板

创建站点目录

1
2
mkdir /home/www
mkdir /home/www/aria2ng

下载并解压aria2ng

1
2
3
4
cd /home/www/aria2ng
wget https://github.com/mayswind/AriaNg/releases/download/1.1.6/AriaNg-1.1.6.zip
yum install uzip
unzip AriaNg-1.1.6.zip

创建nginx配置文件

1
2
mkdir /usr/local/nginx/vhost
vim /usr/local/nginx/vhost/vhost_aria2ng.conf

内容为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
server {
listen 6801;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /home/www/aria2ng;
index index.html index.htm index.php;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
1
vim /usr/local/nginx/conf/nginx.conf

在http{}代码块最后添加

1
include /usr/local/nginx/vhost/*.conf;

在服务器开放6801端口后重启nginx

1
systemctl restart nginx

完成后在浏览器输入服务器公网IP:6801,在“AriaNg设置–PRC(localhost:6800)–Aria2 PRC 秘钥”填写秘钥,刷新页面即可

参考文章:

CentOS7将Nginx添加系统服务的方法步骤

linux编译安装aria2,远程下载设置

Liunx Mint下载方案Aria2、web面板AriaNG搭建