为了账号安全,请及时绑定邮箱和手机立即绑定

使用Aria2c+Aria2Ng自建服务器下载器

2020.07.29 11:51 1100浏览

以前写爬虫,都是自己傻fufu写下载器下载静态资源。最近写一个爬虫将资源路径写数据库后,想使用aria2c来下载,于是就有了下面这些操作。

哦,之前的Nas搭建我已经弄完了,一直没写文章分享,那天心情好把之前的系列补全。下面这些都是在我自建的Nas环境操作的。

安装Aria2

yay -S aria2

启动RPC

创建config文件

sudo mkdir  /etc/aria2c
cd /etc/aria2c
sudo touch /etc/aria2c/aria2.session
sudo vim aria2c.conf

编辑aria2c.conf

# /etc/aria2c/aria2c.conf
# 文件保存路径, 默认为当前启动位置,自行修改
# dir="./"
dir=/home/bubao/disk/aria2_download
# 禁止ipv6
disable-ipv6=true
# 打开rpc的目的是为了给web管理端用
enable-rpc=true
rpc-allow-origin-all=true
#允许非外部访问
rpc-listen-all=true
# RPC端口, 仅当默认端口被占用时修改
rpc-listen-port=16800

input-file=/etc/aria2c/aria2.session
save-session=/etc/aria2c/aria2.session

# 最大同时下载数(任务数), 路由建议值: 3
max-concurrent-downloads=32
# 断点续传
continue=true
# 同服务器连接数
max-connection-per-server=16
# 最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要
min-split-size=10M
# 单文件最大线程数, 路由建议值: 5
split=256
# 下载速度限制
max-overall-download-limit=0
# 单文件速度限制
max-download-limit=0
# 上传速度限制
max-overall-upload-limit=0
# 单文件速度限制
max-upload-limit=0

# 使用代理
# all-proxy=localhost:20172

创建/etc/aria2c/aria2c.service

sudo vim /etc/aria2c/aria2c.service
[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

sudo cp /etc/aria2c/aria2c.service /usr/lib/systemd/system/aria2c.session

重载systemctl并启动aria2c开机启动

sudo systemctl daemon-reload
sudo systemctl enable aria2c.service
sudo systemctl restart aria2c.service

至此,aria2c rpc就启动成功了。

安装以前写爬虫,都是自己傻fufu写下载器下载静态资源。最近写一个爬虫将资源路径写数据库后,想使用aria2c来下载,于是就有了下面这些操作。

哦,之前的Nas搭建我已经弄完了,一直没写文章分享,那天心情好把之前的系列补全。下面这些都是在我自建的Nas环境操作的。

安装Aria2

yay -S aria2

启动RPC

创建config文件

sudo mkdir  /etc/aria2c
cd /etc/aria2c
sudo touch /etc/aria2c/aria2.session
sudo vim aria2c.conf

编辑aria2c.conf

# /etc/aria2c/aria2c.conf
# 文件保存路径, 默认为当前启动位置,自行修改
# dir="./"
dir=/home/bubao/disk/aria2_download
# 禁止ipv6
disable-ipv6=true
# 打开rpc的目的是为了给web管理端用
enable-rpc=true
rpc-allow-origin-all=true
#允许非外部访问
rpc-listen-all=true
# RPC端口, 仅当默认端口被占用时修改
rpc-listen-port=16800

input-file=/etc/aria2c/aria2.session
save-session=/etc/aria2c/aria2.session

# 最大同时下载数(任务数), 路由建议值: 3
max-concurrent-downloads=32
# 断点续传
continue=true
# 同服务器连接数
max-connection-per-server=16
# 最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要
min-split-size=10M
# 单文件最大线程数, 路由建议值: 5
split=256
# 下载速度限制
max-overall-download-limit=0
# 单文件速度限制
max-download-limit=0
# 上传速度限制
max-overall-upload-limit=0
# 单文件速度限制
max-upload-limit=0

# 使用代理
# all-proxy=localhost:20172

创建/etc/aria2c/aria2c.service

sudo vim /etc/aria2c/aria2c.service
[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

sudo cp /etc/aria2c/aria2c.service /usr/lib/systemd/system/aria2c.session

重载systemctl并启动aria2c开机启动

sudo systemctl daemon-reload
sudo systemctl enable aria2c.service
sudo systemctl restart aria2c.service

至此,aria2c rpc就启动成功了。

安装Aria2Ng

为了更方便使用aria2c rpc,需要一个界面,这里我们选用了Aria2Ng。

yay -S aria-ng-deploy

当时安装后我就那么这东西怎么用,去看看yay缓存目录

cat ~/.cache/yay/aria-ng-deploy/aria-ng-deploy.install
# color
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并配置

yay -S nginx

安装就这么简单,查看nginx服务的状态,如果未启动,就启动一下

sudo systemctl status nginx
# 启动命令
# sudo systemctl start nginx
# 开机启动
# sudo systemctl enable nginx

配置一下nginx

sudo mkdir 

修改/etc/nginx/nginx.conf如下

#user html;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/sites-enabled/*; # 开启的 Server 服务配置

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        #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   /usr/share/nginx/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  /scripts$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;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

编辑/etc/nginx/sites-enabled/aria2-ng.conf

server {
       listen 10081;
       listen [::]:10081;

       # 定义服务器的默认网站根目录位置
       root /usr/share/aria-ng-deploy;
       
       # Add index.php to the list if you are using PHP
       index index.html index.htm index.nginx-debian.html;

       # access log file 访问日志
       # access_log logs/nginx.access.log main;
       
       # 禁止访问隐藏文件
       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }
    
       # 默认请求
       location / {
                # 首先尝试将请求作为文件提供,然后作为目录,然后回退到显示 404。
                # try_files 指令将会按照给定它的参数列出顺序进行尝试,第一个被匹配的将会被使用。
                # try_files $uri $uri/ =404;
      	        index index.html index.htm; # 给定URL文件 
                #try_files $uri $uri/ /index.php?path_info=$uri&$args =404;
                access_log off;
                expires max;
       }
}

nginx 的配置我也是抄的…所有大神看见有什么不妥的地方自己改改。

重载Nginx

nginx -s reload

最后在浏览器上访问服务器的18600端口,把rpc绑定过来即可。

为了更方便使用aria2c rpc,需要一个界面,这里我们选用了Aria2Ng。

yay -S aria-ng-deploy

当时安装后我就那么这东西怎么用,去看看yay缓存目录

cat ~/.cache/yay/aria-ng-deploy/aria-ng-deploy.install
# color
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并配置

yay -S nginx

安装就这么简单,查看nginx服务的状态,如果未启动,就启动一下

sudo systemctl status nginx
# 启动命令
# sudo systemctl start nginx
# 开机启动
# sudo systemctl enable nginx

配置一下nginx

sudo mkdir 

修改/etc/nginx/nginx.conf如下

#user html;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/sites-enabled/*; # 开启的 Server 服务配置

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        #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   /usr/share/nginx/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  /scripts$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;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

编辑/etc/nginx/sites-enabled/aria2-ng.conf

server {
       listen 10081;
       listen [::]:10081;

       # 定义服务器的默认网站根目录位置
       root /usr/share/aria-ng-deploy;
       
       # Add index.php to the list if you are using PHP
       index index.html index.htm index.nginx-debian.html;

       # access log file 访问日志
       # access_log logs/nginx.access.log main;
       
       # 禁止访问隐藏文件
       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }
    
       # 默认请求
       location / {
                # 首先尝试将请求作为文件提供,然后作为目录,然后回退到显示 404。
                # try_files 指令将会按照给定它的参数列出顺序进行尝试,第一个被匹配的将会被使用。
                # try_files $uri $uri/ =404;
      	        index index.html index.htm; # 给定URL文件 
                #try_files $uri $uri/ /index.php?path_info=$uri&$args =404;
                access_log off;
                expires max;
       }
}

nginx 的配置我也是抄的…所有大神看见有什么不妥的地方自己改改。

重载Nginx

nginx -s reload

最后在浏览器上访问服务器的18600端口,把rpc绑定过来即可。

点击查看更多内容

本文首次发布于慕课网 ,转载请注明出处,谢谢合作

1人点赞

若觉得本文不错,就分享一下吧!

评论

相关文章推荐

正在加载中
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消