介绍 可能更多人想知道的是Aria2是什么?它有什么优势?
aria2 是一款支持多种协议的轻量级命令行下载工具。有以下特性:
多线程连线:aria2 会自动从多个线程下载文件,并充分利用你的带宽; 轻量:运行时不会占用过多资源,根据官方介绍,内存占用通常在 4MB~9MB; 支持 RPC 界面远程控制。 官方网站是aria2.github.io
当然在官方网站上有很多已经编译好的二进制文件供下载,但是想要修改一些配置还是得自己编译。
在官方编译好的二进制文件中,单服务器连接数是16,感觉有点少,所以我们得提高一些。
方法 我们使用Docker构建镜像进行编译。
这是为了在生产环境中减少环境污染,即用即删。
先安装好Docker,这里就不说怎么安装了。
1 2 3 4 5 # 为方便,先创建一个文件夹 mkdir a2 cd a2 wget -O Dockerfile https://github.com/aria2/aria2/raw/master/Dockerfile.mingw vi Dockerfile
Dockerfile里的内容如下
ps:把线程数从16改为了128
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 # Dockerfile to build aria2 Windows binary using ubuntu mingw-w64 # cross compiler chain. # # # /aria2/src/aria2c.exe. You can copy the binary using following # commands: # # $ sudo docker cp $id :/aria2/src/aria2c.exe <dest> # $ sudo docker rm -v $id FROM ubuntu:16.04 MAINTAINER xxx xxx# Change HOST to x86_64-w64-mingw32 to build 64-bit binary ENV HOST x86_64-w64-mingw32# It would be better to use nearest ubuntu archive mirror for faster # downloads. # RUN sed -ie 's/archive\.ubuntu/jp.archive.ubuntu/g' /etc/apt/sources.list RUN apt-get update && \ apt-get install -y \ make binutils autoconf automake autotools-dev libtool \ pkg-config git curl dpkg-dev gcc-mingw-w64 \ autopoint libcppunit-dev libxml2-dev libgcrypt11-dev lzip sed RUN curl -L -O https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz && \ curl -L -O http://downloads.sourceforge.net/project/expat/expat/2.2.4/expat-2.2.4.tar.bz2 && \ curl -L -O https://www.sqlite.org/2017/sqlite-autoconf-3200100.tar.gz && \ curl -L -O http://zlib.net/zlib-1.2.11.tar.gz && \ curl -L -O https://c-ares.haxx.se/download/c-ares-1.13.0.tar.gz && \ curl -L -O http://libssh2.org/download/libssh2-1.8.0.tar.gz RUN tar xf gmp-6.1.2.tar.lz && \ cd gmp-6.1.2 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --disable-cxx \ --enable-fat \ CFLAGS="-mtune=generic -O2 -g0" && \ make install RUN tar xf expat-2.2.4.tar.bz2 && \ cd expat-2.2.4 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` && \ make install RUN tar xf sqlite-autoconf-3200100.tar.gz && \ cd sqlite-autoconf-3200100 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` && \ make install RUN tar xf zlib-1.2.11.tar.gz && \ cd zlib-1.2.11 && \ CC=$HOST-gcc \ AR=$HOST-ar \ LD=$HOST-ld \ RANLIB=$HOST-ranlib \ STRIP=$HOST-strip \ ./configure \ --prefix=/usr/local/$HOST \ --libdir=/usr/local/$HOST/lib \ --includedir=/usr/local/$HOST/include \ --static && \ make install RUN tar xf c-ares-1.13.0.tar.gz && \ cd c-ares-1.13.0 && \ ./configure \ --disable-shared \ --enable-static \ --without-random \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ LIBS="-lws2_32" && \ make install RUN tar xf libssh2-1.8.0.tar.gz && \ cd libssh2-1.8.0 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ --without-openssl \ --with-wincng \ LIBS="-lws2_32" && \ make install ADD https://api.github.com/repos/aria2/aria2/git/refs/heads/master version.json RUN git clone https://github.com/aria2/aria2 && \ cd aria2 && sed -i 's/16,/128,/g' src/OptionHandlerFactory.cc && autoreconf -i && ./mingw-config && make && \ $HOST-strip src/aria2c.exe
接下来创建镜像,构建的时间有点长,编译完后二进制文件在/aria2/src目录。
1 docker build -t a2e:x64 .
构建完后,运行
1 docker run --name aria -t -i a2e:x64 /bin/bash
从镜像中把二进制文件复制至本地
1 docker cp aria:/aria2/src/aria2c.exe .