king

靜態編譯最新aria2+修改成128線程
1.安裝開發環境的依賴包apt-get install -y libgnutls28-dev nettle-dev...
扫描右侧二维码阅读全文
14
2018/03

靜態編譯最新aria2+修改成128線程

1.安裝開發環境的依賴包

apt-get install -y libgnutls28-dev nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libcppunit-dev autoconf automake autotools-dev autopoint libtool git gcc g++ libxml2-dev make quilt
apt-get install -y libcurl4-openssl-dev libevent-dev ca-certificates libssl-dev  build-essential intltool libgcrypt-dev libssl-dev 
apt install python-pip
pip install --upgrade pip
pip install sphinx

2.下載aria2

git clone https://github.com/aria2/aria2.git

3.安裝靜態編譯所需要的依賴,這裡使用腳本

vim aria2-x86_64-gnu-linux-build-libs
#!/bin/bash

# In this configuration, the following dependent libraries are compiled:
#
# * zlib
# * c-ares
# * expat
# * sqlite3
# * openSSL
# * libssh2

#COMPILER AND PATH
PREFIX=/opt/aria2/build_libs
C_COMPILER="gcc"
CXX_COMPILER="g++"

#CHECK TOOL FOR DOWNLOAD
 aria2c --help > /dev/null
 if [ "$?" -eq 0 ] ; then
   DOWNLOADER="aria2c --check-certificate=false"
 else
   DOWNLOADER="wget -c"
 fi

## DEPENDENCES ##
ZLIB=http://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz
OPENSSL=http://www.openssl.org/source/openssl-1.0.2m.tar.gz
EXPAT=https://sourceforge.net/projects/expat/files/expat/2.2.0/expat-2.2.0.tar.bz2
SQLITE3=http://www.sqlite.org/2017/sqlite-autoconf-3210000.tar.gz
C_ARES=http://c-ares.haxx.se/download/c-ares-1.13.0.tar.gz
SSH2=https://www.libssh2.org/download/libssh2-1.7.0.tar.gz

## CONFIG ##
BUILD_DIRECTORY=/tmp/

## BUILD ##
cd $BUILD_DIRECTORY
#
 # zlib build
  $DOWNLOADER $ZLIB
  tar zxvf zlib-1.2.11.tar.gz
  cd zlib-1.2.11/
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./configure --prefix=$PREFIX --static
  make
  make install
#
 # expat build
  cd ..
  $DOWNLOADER $EXPAT
  tar jxvf expat-2.2.0.tar.bz2
  cd expat-2.2.0/
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./configure --prefix=$PREFIX --enable-static --enable-shared
  make
  make install
#
 # c-ares build
  cd ..
  $DOWNLOADER $C_ARES
  tar zxvf c-ares-1.13.0.tar.gz
  cd c-ares-1.13.0/
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./configure --prefix=$PREFIX --enable-static --disable-shared
  make
  make install
#
 # Openssl build
  cd ..
  $DOWNLOADER $OPENSSL
  tar zxvf openssl-1.0.2m.tar.gz
  cd openssl-1.0.2m/
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./Configure --prefix=$PREFIX linux-x86_64 shared
  make
  make install
#
 # sqlite3
  cd ..
  $DOWNLOADER $SQLITE3
  tar zxvf sqlite-autoconf-3210000.tar.gz
  cd sqlite-autoconf-3210000/
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./configure --prefix=$PREFIX --enable-static --enable-shared
  make
  make install
#
 # libssh2
  cd ..
  $DOWNLOADER $SSH2
  tar zxvf libssh2-1.7.0.tar.gz
  cd libssh2-1.7.0/
  rm -rf $PREFIX/lib/pkgconfig/libssh2.pc
  PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ LD_LIBRARY_PATH=$PREFIX/lib/ CC="$C_COMPILER" CXX="$CXX_COMPILER" ./configure --without-libgcrypt --with-openssl --without-wincng --prefix=$PREFIX --enable-static --disable-shared
  make
  make install
#
 #cleaning
  cd ..
  rm -rf c-ares*
  rm -rf sqlite-autoconf*
  rm -rf zlib-*
  rm -rf expat-*
  rm -rf openssl-*
  rm -rf libssh2-*
#
 echo "finished!"

執行腳本

chmod +x aria2-x86_64-gnu-linux-build-libs
./aria2-x86_64-gnu-linux-build-libs

安裝完後進入 aria2 資料夾

cd aria2

產生設定檔

autoreconf -i

修改原碼的線程數
進入aria2/src

cd src

找到OptionHandlerFactory.cc

vim OptionHandlerFactory.cc

OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONNECTION_PER_SERVER,
                                               TEXT_MAX_CONNECTION_PER_SERVER,
                                               "1", 1, 16, 'x'));

修改為

OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONNECTION_PER_SERVER,
                                               TEXT_MAX_CONNECTION_PER_SERVER,
                                               "128", 1, -1, 'x'));

PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "20M", 1_m, 1_g, 'k'));

修改為

PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "4K", 1_k, 1_g, 'k'));

PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "60", 1, 600));

修改為

PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "30", 1, 600));

PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_m, 1_g));

修改為

PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "4k", 1_k, 1_g));

new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "0", 0, 600));

修改為

new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "2", 0, 600));

new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "5", 1, -1, 's'));

修改為

new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "8", 1, -1, 's'));

或者使用sed指令進行取代

sed -i 's/"1", 1, 16/"128", 1, -1/g' ./src/OptionHandlerFactory.cc

sed -i 's/"20M", 1_m, 1_g/"4K", 1_k, 1_g/g' ./src/OptionHandlerFactory.cc

sed -i 's/PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "60", 1, 600/PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "30", 1, 600/g' ./src/OptionHandlerFactory.cc

sed -i 's/PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_m, 1_g/PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "4k", 1_k, 1_g/g' ./src/OptionHandlerFactory.cc

sed -i 's/new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "0", 0, 600/new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "2", 0, 600/g' ./src/OptionHandlerFactory.cc

sed -i 's/new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "5", 1, -1,/new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "8", 1, -1,/g' ./src/OptionHandlerFactory.cc

靜態編譯部分
這裡使用設定檔腳本( 注意:腳本放置在要進行編譯的目錄裡面 )

vim aria2-x86_64-gnu-linux-config
#!/bin/bash

# In this configuration, the following dependent libraries are used:
#
# * zlib
# * c-ares
# * expat
# * sqlite3
# * openSSL
# * libssh2

#COMPILER AND PATH
PREFIX=/usr
C_COMPILER="gcc"
CXX_COMPILER="g++"

## BUILD ##
PKG_CONFIG_PATH=/opt/aria2/build_libs/lib/pkgconfig/ \
LD_LIBRARY_PATH=/opt/aria2/build_libs/lib/ \
CC="$C_COMPILER" \
CXX="$CXX_COMPILER" \
./configure \
    --prefix=$PREFIX \
    --without-libxml2 \
    --without-libgcrypt \
    --with-openssl \
    --without-libnettle \
    --without-gnutls \
    --without-libgmp \
    --with-libssh2 \
    --with-sqlite3 \
    --with-ca-bundle='/etc/ssl/certs/ca-certificates.crt' \
    ARIA2_STATIC=yes \
    --enable-shared=no

儲存後離開

:wq
chmod +x aria2-x86_64-gnu-linux-config

執行設定檔腳本

./aria2-x86_64-gnu-linux-config

完成後,開始編譯(多線程編繹)

make -j4

編譯完成後去除aria2c的符號表

strip -s aria2c

完成後安裝

make install

測試是否修改成功

aria2c -x 128 https://github.com/mayswind/AriaNg/releases/download/0.4.0/aria-ng-0.4.0.zip

將編譯完成的檔案提取出來,以方便之後重複利用

mkdir /root/aria2-static-128-thread
cp src/aria2c /root/aria2-static-128-thread
cp doc/manual-src/en/_build/man/aria2c.1 /root/aria2-static-128-thread
cp AUTHORS /root/aria2-static-128-thread
cp /etc/ssl/certs/ca-certificates.crt /root/aria2-static-128-thread
cp ChangeLog /root/aria2-static-128-thread
cp COPYING /root/aria2-static-128-thread
cp LICENSE.OpenSSL /root/aria2-static-128-thread
cp NEWS /root/aria2-static-128-thread
cp README /root/aria2-static-128-thread
cp README.html /root/aria2-static-128-thread
cp README.rst /root/aria2-static-128-thread

建立Makefile檔,並加入以下內容

vim Makefile
#################################################
# Installing aria2 static builds (q3aql)        #
#################################################

PREFIX=/usr

install:
    mkdir -p /etc/ssl/certs/
    mkdir -p $(PREFIX)/share/man/man1/
    cp aria2c $(PREFIX)/bin
    cp aria2c.1 $(PREFIX)/share/man/man1/aria2c.1
    cp ca-certificates.crt /etc/ssl/certs/
    chmod 755 $(PREFIX)/bin/aria2c
    chmod 644 $(PREFIX)/share/man/man1/aria2c.1
    chmod 644 /etc/ssl/certs/ca-certificates.crt
    
uninstall:
    rm $(PREFIX)/bin/aria2c
    rm $(PREFIX)/share/man/man1/aria2c.1

儲存並離開

:wq

複製至資料夾

cp Makefile /root/aria2-static-128-thread

加入程壓縮檔

cd /root

tar zcvf aria2-static-128-thread.tar.gz aria2-static-128-thread

這樣以後要使用你編完的aria2時,只要解壓縮,切換至該目錄
並輸入以下指令,就會自動安裝了

make install

這裡附上成功編譯完的

aria2-v1.33.1-static-build-128-thread

https://github.com/king567/aria2-v1.33.1-static-build-128-thread/releases/download/v1.33.1/success.tar.gz
Last modification:November 30th, 2018 at 06:06 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment