更好的閱讀體驗歡迎訪問博客搭建Aria2+Aria2Web管理面板
前言
由於想使用網盤的離線下載功能,需要搭建aria2,特此記錄。
一、編譯安裝Aira2
安裝wget
yum install wget
安裝編譯器
yum install gcc gcc-c++
創建aria2目錄
mkdir -p /home/aria2/downloads
cd /home/aria2
下載並解壓aira2
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
cd aria2-1.33.1
./configure
make
cd src
cp aria2c /usr/bin
安裝完成后執行
aria2c -v
出現"aria2 version 1.33.1"等代碼則安裝成功
接下來設置aria2c
touch /home/aria2/aria2.session
vim /home/aria2/aria2.conf
內容為
## 文件保存相關 ##
# 文件的保存路徑(可使用絕對路徑或相對路徑), 默認: 當前啟動位置
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端口
執行命令使配置生效
aria2c --conf-path=/home/aria2/aria2.conf -D
設置開機自啟動
vim /etc/rc.d/rc.local
在最后添加
aria2c --conf-path=/home/aria2/aria2.conf -D
二、編譯安裝Nginx Web服務器
安裝nginx依賴
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
下載並解壓nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
編譯安裝nginx
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
make
make install
創建nginx賬號
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vim nginx.conf
將第一行"#user nobody"改為
user nginx nginx
ESC+:wq+Enter保存並退出
啟動nginx
/usr/local/nginx/sbin/nginx
瀏覽器輸入服務器公網IP,出現Welcome to nginx!則成功
將nginx添加到系統服務
vim /usr/lib/systemd/system/nginx.service
內容為
[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進程
lsof -i:80
kill -9 進程號
執行
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
通過系統服務啟動nginx
systemctl start nginx
設置為開機啟動
systemctl enable nginx
重啟服務器后在瀏覽器輸入公網IP查看是否成功
三、搭建Aria2Ng Web面板
創建站點目錄
mkdir /home/www
mkdir /home/www/aria2ng
下載並解壓aria2ng
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配置文件
mkdir /usr/local/nginx/vhost
vim /usr/local/nginx/vhost/vhost_aria2ng.conf
內容為
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;
#}
}
vim /usr/local/nginx/conf/nginx.conf
在http{}代碼塊最后添加
include /usr/local/nginx/vhost/*.conf;
在服務器開放6801端口后重啟nginx
systemctl restart nginx
完成后在瀏覽器輸入服務器公網IP:6801,在“AriaNg設置--PRC(localhost:6800)--Aria2 PRC 秘鑰”填寫秘鑰,刷新頁面即可
參考文章: