以前写爬虫,都是自己傻 fufu 写下载器下载静态资源。最近写一个爬虫将资源路径写数据库后,想使用 aria2c 来下载,于是就有了下面这些操作。
哦,之前的 Nas 搭建我已经弄完了,一直没写文章分享,那天心情好把之前的系列补全。下面这些都是在我自建的 Nas 环境操作的。
安装 Aria2
启动 RPC
创建config
文件
1 2 3 4
| sudo mkdir /etc/aria2c cd /etc/aria2c sudo touch /etc/aria2c/aria2.session sudo vim aria2c.conf
|
编辑aria2c.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
|
dir=/home/bubao/disk/aria2_download
disable-ipv6=true
enable-rpc=true rpc-allow-origin-all=true
rpc-listen-all=true
rpc-listen-port=16800
input-file=/etc/aria2c/aria2.session save-session=/etc/aria2c/aria2.session
max-concurrent-downloads=32
continue=true
max-connection-per-server=16
min-split-size=10M
split=256
max-overall-download-limit=0
max-download-limit=0
max-overall-upload-limit=0
max-upload-limit=0
|
创建/etc/aria2c/aria2c.service
1
| sudo vim /etc/aria2c/aria2c.service
|
1 2 3 4 5 6 7 8 9 10
| [Unit] Description=aria2c Service After=network.target Wants=network.target [Service] Type=simple ExecStart=/usr/bin/aria2c --conf-path=/etc/aria2c/aria2c.conf Restart=on-abnormal [Install] WantedBy=multi-user.target
|
将/etc/aria2c/aria2c.service
文件拷贝到/usr/lib/systemd/system/aria2c.session
1
| sudo cp /etc/aria2c/aria2c.service /usr/lib/systemd/system/aria2c.session
|
重载systemctl
并启动aria2c
开机启动
1 2 3
| sudo systemctl daemon-reload sudo systemctl enable aria2c.service sudo systemctl restart aria2c.service
|
至此,aria2c rpc 就启动成功了。
安装 Aria2Ng
为了更方便使用 aria2c rpc,需要一个界面,这里我们选用了 Aria2Ng。
当时安装后我就那么这东西怎么用,去看看 yay 缓存目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| ➜ cat ~/.cache/yay/aria-ng-deploy/aria-ng-deploy.install
all_off="$(tput sgr0)" bold="${all_off}$(tput bold)" blue="${bold}$(tput setaf 4)" yellow="${bold}$(tput setaf 3)"
note() { printf "${blue}==>${yellow} NOTE:${bold} $1${all_off}\n" }
post_install(){ note "you should copy /usr/share/aria-ng-deploy to your web directory" }
post_upgrade(){ post_install }
|
you should copy /usr/share/aria-ng-deploy to your web directory
emmmmm??????
web directory
,也就是说我需要 Nginx 才能启动。那就安装咯。
安装 Nginx 并配置
安装就这么简单,查看nginx
服务的状态,如果未启动,就启动一下
1 2 3 4 5
| sudo systemctl status nginx
|
配置一下 nginx
修改/etc/nginx/nginx.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 102 103 104 105 106 107 108 109 110 111 112 113
| worker_processes 1;
events { worker_connections 1024; }
http { include mime.types; default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/sites-enabled/*;
server { listen 80; server_name localhost;
location / { root /usr/share/nginx/html; index index.html index.htm; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
}
}
|
编辑/etc/nginx/sites-enabled/aria2-ng.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
| server { listen 10081; listen [::]:10081;
root /usr/share/aria-ng-deploy; index index.html index.htm index.nginx-debian.html;
location ~ /\. { deny all; access_log off; log_not_found off; } location / { index index.html index.htm; access_log off; expires max; } }
|
nginx 的配置我也是抄的。….. 所有大神看见有什么不妥的地方自己改改。
重载 Nginx
最后在浏览器上访问服务器的18600
端口,把 rpc 绑定过来即可。