关于aria2最完整的一篇

关于aria2最完整的一篇

Posted by ivo on April 18, 2019

正常用户请直接看我自己的配置文件就够了,其他的由于信息太多意义不是特别大

配置文件如下(以下也有提及)

规划

1、下载目录: /home/ivo/Videos 2、配置文件: ~/aria2/aria2.conf 3、session和log: ~/aria2/aria2.session 和 ~/aria2/aria2.log

配置文件

# touch /data/aria2.session
# vim /etc/aria2/aria2.conf
## '#'开头为注释内容, 选项都有相应的注释说明, 根据需要修改 ##
## 被注释的选项填写的是默认值, 建议在需要修改时再取消注释  ##

## 文件保存相关 ##

# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置
dir=/home/ivo/Videos

# 启用磁盘缓存, 0为禁用缓存, 需1.16以上版本, 默认:16M
#disk-cache=32M
#disk-cache=32M
# 文件预分配方式, 能有效降低磁盘碎片, 默认:prealloc
# 预分配所需时间: none < falloc ? trunc < prealloc
# falloc和trunc则需要文件系统和内核支持
# NTFS建议使用falloc, EXT3/4建议trunc, MAC 下需要注释此项
file-allocation=prealloc
# 断点续传
continue=true

## 下载连接相关 ##

# 最大同时下载任务数, 运行时可修改, 默认:5
max-concurrent-downloads=10
# 同一服务器连接数, 添加时可指定, 默认:1
max-connection-per-server=10
# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M
# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载
min-split-size=10M
# 单个任务最大线程数, 添加时可指定, 默认:5
split=5
# 整体下载速度限制, 运行时可修改, 默认:0
#max-overall-download-limit=0
# 单个任务下载速度限制, 默认:0
#max-download-limit=0
# 整体上传速度限制, 运行时可修改, 默认:0
#max-overall-upload-limit=0
# 单个任务上传速度限制, 默认:0
#max-upload-limit=0
# 禁用IPv6, 默认:false
disable-ipv6=true

## 进度保存相关 ##

# 从会话文件中读取下载任务
input-file=/home/ivo/aria2/aria2.session
# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件
save-session=/home/ivo/aria2/aria2.session
# 定时保存会话, 0为退出时才保存, 需1.16.1以上版本, 默认:0
save-session-interval=60

## RPC相关设置 ##

enable-rpc=true
pause=false
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-save-upload-metadata=true
rpc-secure=false

# 启用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-secure=<taken>
# 设置的RPC访问用户名, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-user=<USER>
# 设置的RPC访问密码, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-passwd=<PASSWD>

## BT/PT下载相关 ##

# 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务, 默认:true
#follow-torrent=true
# BT监听端口, 当端口被屏蔽时使用, 默认:6881-6999
listen-port=51413
# 单个种子最大连接数, 默认:55
#bt-max-peers=55
# 打开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=false
# 每个种子限速, 对少种的PT很有用, 默认:50K
#bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
#peer-id-prefix=-TR2770-
user-agent=Transmission/2.92
#user-agent=netdisk;4.4.0.6;PC;PC-Windows;6.2.9200;WindowsBaiduYunGuanJia
# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0

seed-ratio=1.0
#作种时间大于30分钟,则停止作种
seed-time=30
# 强制保存会话, 话即使任务已经完成, 默认:false
# 较新的版本开启后会在任务完成后依然保留.aria2文件
#force-save=false
# BT校验相关, 默认:true
#bt-hash-check-seed=true
# 继续之前的BT任务时, 无需再次校验, 默认:false
bt-seed-unverified=true
# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false
bt-save-metadata=true
#下载完成后删除.ara2的同名文件
on-download-complete=/home/ivo/aria2/delete_aria2
#on-download-complete=/home/pi/aria2/rasp.sh

以下是正文请慢慢阅读吧

aria2 是另一款 Linux 下轻量级的多线程下载工具,支持 Http/Https、Ftp、BitTorrent、Metalink 协议。它比 axel 优秀的地方在于:完全支持 BitTorrent 协议,同时可以作为 BitTorrent 客户端来下载种子文件;支持 Metalink 协议;远程控制(通过 web 端)下载进程。 比起 wget来说, aria2 支持多线程下载,比起 Transmission, aria2 更快,支持的协议更多。不少网友用来下载迅雷离线文件也是不错的选择。

Aria 2 本身是一款纯命令行工具,看来 6 MB 的体积没能容下精心设计的图形界面,但这绝不妨碍它成为一款使用体验上佳的下载器——退一步讲,没有图形界面也算变相避开了广告等无关因素的骚扰吧。Aria 2 支持 BT、磁力链和普通 HTTP(s) / FTP 下载,没能解析 ed2k:// 是个遗憾。作为下载器中的高端货,设置磁盘缓存、支持断点及分段、多线程、远程服务器登录和上下行限速等不在话下,它甚至能够处理 URL 通配符、从多个地址下载/合并同一文件、加载 Cookie / Header、伪装 User Agent 和允许远程控制等等。

官网地址:http://aria2.sourceforge.net ,首页有简略使用教程(Usage Examples),更多高阶教程围观官网 Manual (一切宝藏尽在这里)。

一、aria2 安装 默认 repo 里没有 aria2 ,我们需要添加第三方的 yum 源。

CentOS:

1.先安装 RepoForge Repos 2.yum -y install aria2

# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# yum -y install aria2

Ubuntu:

$ sudo apt-get install aria2

编译安装:

源码下载地址:http://aria2.sourceforge.net/,目前最新版的是1.18.10,http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.10/

1、下载 源码包 2、编译安装

# wget http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.10/aria2-1.18.10.tar.gz
# tar xf aria2-1.18.10.tar.gz -C /usr/local/src
# cd /usr/local/src
# ./configure 
# make 
### 报错
 ...
 
  CXX      A2STR.lo
  CXX      AbstractAuthResolver.lo
  CXX      AbstractCommand.lo
In file included from AbstractCommand.cc:35:
AbstractCommand.h:261: error: 'nullptr' was not declared in this scope
AbstractCommand.h:263: error: 'nullptr' was not declared in this scope
In file included from FileAllocationMan.h:39,
                 from DownloadEngine.h:50,
                 from AbstractCommand.cc:40:
SequentialPicker.h: In member function 'T* aria2::SequentialPicker<T>::pickNext()':
SequentialPicker.h:78: error: 'nullptr' was not declared in this scope
In file included from DownloadEngine.h:52,
                 from AbstractCommand.cc:40:
DNSCache.h: In member function 'void aria2::DNSCache::CacheEntry::getAllGoodAddrs(OutputIterator) const':
DNSCache.h:86: error: expected initializer before ':' token
...
This is because compiler is too old to support C++11 features aria2 requires. And configure check for C++11 feature is a bit weak. At the moment, gcc >= 4.8.3 or clang >= 3.4 compile aria2 fine. gcc 4.6 or 4.7 may also work. But less than that probably fails.

建议还是下载低版本的 aria2 (aria2-1.17.1), 然后编译安装。

# wget http://sourceforge.net/projects/aria2/files/stable/aria2-1.17.1/aria2-1.17.1.tar.gz
# tar xf aria2-1.17.1.tar.gz -C /usr/local/src
# cd /usr/local/src
# cd aria2-1.17.1/
# ./configure 
# make &&  make install
# 默认情况下,会在/usr/local/bin 目录创建 aria2c 可执行程序。
# aria2c -v
aria2 version 1.17.1
Copyright (C) 2006, 2013 Tatsuhiro Tsujikawa

实际使用的过程中,我发现一些问题,不能下载bt种子文件。为什么呢?

aria2 默认编译的话,BT 和 Metalink 功能没有开启。那该怎么办

# cd /usr/local/src/aria2-1.17.1

我们来看一下 aria2c configure 选项

# ./configure --help

可以发现几个比较感兴趣的选项,大家可以详细的阅读一下,这里我只是简单的列举几个而已。

--prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
--enable-FEATURE[=ARG]  include FEATURE [ARG=yes] 
--enable-threads={posix|solaris|pth|win32}
                          specify multithreading API
--with-tcmalloc         Use tcmalloc.

在这里,我们又要补充一下知识了。tcmalloc 对于 aria2c来说,并不是必须,因为aria2c在运行的过程中,本来就占用很少的内存,大家在编译的时候可以去掉这个参数。

1、什么是 tcmalloc ? TCMalloc(Thread-Caching Malloc)与标准glibc库的malloc实现一样的功能,但是TCMalloc在效率和速度效率都比标准malloc高很多。TCMalloc是google-perftools工具中的一个(gperftools四个工具分别是:TCMalloc、heap-checker、heap-profiler和cpu-profiler),这个工具是开源的,以源码形式发布。如果觉得自己维护一个内存分配器麻烦的话,可以考虑将TCMalloc静态库连接到你的程序中。使用的时候和glibc中的malloc调用方式一模一样。你需要做的只是把TCMalloc的动态库或者静态库连接进你的程序中,你就可以获得一个高效,快速,安全的内存分配器。

2、如何在CentOS6 64位 安装 tcmalloc? 安装 tcmalloc 所需的libunwind库 [64位系统需要安装,32位系统无需安装] libunwind 库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。 For that reason, if you use a 64-bit system, we strongly recommend you install libunwind before trying to configure or install gperftools. 推荐使用 0.99-beta

# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz
# tar xf libunwind-0.99-beta.tar.gz 
# cd libunwind-0.99
# CFLAGS=-fPIC ./configure
# make CFLAGS=-fPIC
# make CFLAGS=-fPIC install

2、安装 tcmalloc

# wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz  
# tar xf google-perftools-2.0.tar.gz
# cd google-perftools-2.0/
# ./configure 
# make && make install

鉴于由于某些原因,可能无法下载,可以使用下面这种方法

# git clone https://github.com/couchbase/gperftools.git 

As of 2.1 gperftools does not have configure and other autotools products checked into it’s source repository. This is common practice for projects using autotools. But, in order to build gperftools checked out from subversion repository you need to have autoconf, automake and libtool installed. And before running ./configure you have to generate it (and a bunch of other files) by running ./autogen.sh script. That script will take care of calling correct autotools programs in correct order.

# ./autogen.sh 
# ./configure 
# make && make install

如果是32位系统,./configure 可以不添加 –enable-frame-pointers,如果是64位系统,并且之前没有安装libunwind,那么一定要添加–enable-frame-pointers 参数。 默认安装时,libunwind与tcmalloc库均安装至/usr/local/lib 3、配置动态链接库

# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
# /sbin/ldconfig

使用:增加编译选项 -ltcmalloc 呼。。,我们还是回到正题,如何编译 aria2c ? 看了前面的选项,大概知道怎么用了吧?

# cd /usr/local/src/aria2-1.17.1/
# ./configure \
    --prefix=/usr/local/aria2 \
    --enable-FEATURE \
    --enable-threads=posix \
    --with-tcmalloc 
# make && make install

漫长的等待,终于大功告成。。。

aria2 命令行基本使用

注意:当源地址存在诸如 &, * 等 shell 的特殊字符,请使用单引号或双引号把 URI 包含起来。

1、Download from WEB
# aria2c -c -s 5 http://example.org/mylinux.iso
-c : 断点续传
-s : 使用线程数

2、Download from 2 sources
# aria2c http://a/f.iso   ftp://b/f.iso

3、Download using 2 connections per host
# aria2c -x2 http://a/f.iso

4、BitTorrent Magnet URI
# aria2c 'magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C'

5、Metalink
# aria2c http://example.org/mylinux.metalink

6、Download URIs found in text file
# aria2c -i uris.txt

7、BT
# aria2c /tmp/CentOS-6.3-i386-bin-DVD1to2.torrent
# aria2c http://mirrors.163.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-minimal.torrent

2.1 断点续传规则 aria2 对断点续传有很好的支持,只需要重新运行一次同样的下载命令即可, 我们加 -c 参数,开启断点续传功能。

# aria2c -c http://mirrors.kernel.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.gz
[#575536 12MiB/116MiB(10%) CN:1 DL:878KiB ETA:2m1s]                                                                  
04/24 20:50:31 [NOTICE] Shutdown sequence commencing... Press Ctrl-C again for emergency shutdown.
04/24 20:50:31 [NOTICE] Download GID#5755367ab0bce05b not complete: /tmp/gcc-5.1.0.tar.gz
Download Results:
gid   |stat|avg speed  |path/URI
======+====+===========+=======================================================
575536|INPR|   816KiB/s|/tmp/gcc-5.1.0.tar.gz
Status Legend:
(INPR):download in-progress.
aria2 will resume download if the transfer is restarted.
If there are any errors, then see the log file. See '-l' option in help/man page for details.

aria2 在下载过程中,我们按下 Ctrl + C 中断进程的执行,那么我们会在此目录下发现 gcc-5.1.0.tar.gz 以及 gcc-5.1.0.tar.gz.aria2 这两个文件。

其中 gcc-5.1.0.tar.gz.aria2 保存这下载的进度信息,当aria2使用同样的命令重新运行时,它会读取这个文件并继续原来的下载。当然,aria2并不要求一定要是使用完全一直的参数:用户需要指定那些可以找到.aria2文件的参数,所有-d选项是很重要的,而URI却不一定与上次相同,只要保证他们指向了同样的文件即可。这意味着你可以用某个URI开始下载,然后使用torrent文件进行续传。当然如果只存在.aria2文件,续传就会被忽略掉。

为了能够成功进行续传,需要考虑到如下的一些情况。

“size known” 表示文件大小在开始下载前是已知的,如metalink可以提供文件大小 “file size match”表示控制文件中的大小与远端(或metalink)的大小相同 ‘D’表示不关心 ACTION表示在上面的各种情况下aria2会采取的动作

aria2 配置示例

aria2 或者 aria2c 通常有两种模式:

第一种模式:

命令行模式:直接在命令行下载,比如 aria2c ‘http://host/file.tar.gz’ 这种,然后当下载完成后,就自动退出了,就和wget 的工作方式一样。

第二种模式:

Daemon模式:另一种就是 rpc server 模式,特点就是,它启动之后什么都不干,然后等着从rpc接口添加任务,下载完也不退出,而是一直等着。对,就像迅雷干的那样,当然,它不会上传你硬盘上的数据。 因为第一种方式要每次都敲命令,除非像我是原生*nix,没有命令行就没法用电脑,估计也没什么用,于是常用的就是第二种。一般启动命令是

# aria2c –enable-rpc –rpc-listen-all=true –rpc-allow-origin-all -c -D

但是,其实这个命令是不好的!不要使用这种启动方式。 默认情况下是没有保存设定的功能的,重启服务或服务器,配置都会丢失。

首先,用命令方式导致配置不方便修改保存,-D导致无法看到出错信息。推荐启动方式是使用配置文件

$HOME/.aria2/aria2.conf

或者

/etc/aria2/aria2.conf

嗯,我知道路由上这个地址是无法修改或者重启后会丢失的,那么你可以放到别的地方,然后

aria2c --conf-path=<PATH> -D 

注意 填完整路径,因为鬼知道这个程序是从那个路径启动的。-D (用于后台执行,daemon 模式, 这样ssh断开连接后程序不会退出) 只有在确认OK之后在启动脚本中使用。

以下方案都基于配置文件方式

图形界面

aria2是没有图形界面的,已知相对好用的图形界面有:

YAAW

另一个web前端 webui-aria2 请使用 chrome,firefox 等现代浏览器访问。这两个东西都可以直接使用,除了看英文不爽以外,有什么必要下载回来使用。这两个东西上的配置在重启后都会失效! 使用配置文件保存您的设置

windows下有Aria2c Remote Control

iphone有Aria2 Download Manager 图形界面基本都基于RPC模式,所以一定确定开启了RPC,IP端口可访问,并且在管理器中填写了正确的地址。

配置文件

http://aria2.sourceforge.net/manual/en/html/index.html手册

请将所有配置置于配置文件中 只有在确认配置无误后再加上 -D 选项 请阅读出错信息! 以下的配置文件用到那部分写那部分到配置文件,没用的不用写

RPC
需要1.14及以上版本
http://aria2.sourceforge.net/manual/en/html/aria2c.html#rpc-options

#允许rpc
enable-rpc=true
#允许所有来源, web界面跨域权限需要
rpc-allow-origin-all=true
#允许非外部访问
rpc-listen-all=true
#RPC端口, 仅当默认端口被占用时修改
#rpc-listen-port=6800

如果启动时出现 Initializing EpollEventPoll failed. 或相似错误, 在配置中加上 event-poll=select

使用token验证(建议使用,需要1.18.4以上版本,帐号密码方式将在后续版本中停用!)

token验证
rpc-secret=secret

在YAAW中使用 http://token:secret@hostname:port/jsonrpc 的地址格式设置secret.

如果需要使用密码验证(需要1.15.2以上,1.18.6以下版本)

#用户名
rpc-user=username
#密码
rpc-passwd=passwd

在YAAW中使用 http://username:passwd@hostname:port/jsonrpc 的地址格式设置密码. 对于RPC模式来说, 界面和后端是分离的, 只要给后端设置密码即可. 前端认证什么的是毫无意义的. 如果你比较新潮, 在YAAW中也可以用 ws:// 为前缀,只用websocket连接aria2c, 如果你不知道websocket是什么. 那就算了.

速度相关
#最大同时下载数(任务数), 路由建议值: 3
max-concurrent-downloads=5
#断点续传
continue=true
#同服务器连接数
max-connection-per-server=5
#最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要
min-split-size=10M
#单文件最大线程数, 路由建议值: 5
split=10
#下载速度限制
max-overall-download-limit=0
#单文件速度限制
max-download-limit=0
#上传速度限制
max-overall-upload-limit=0
#单文件速度限制
max-upload-limit=0
#断开速度过慢的连接,当速度低于某个特定值的时候,放弃下载
#lowest-speed-limit=0
#验证用,需要1.16.1之后的release版本
#referer=*
进度保存相关

aria2c只有在正常退出时(ctrl-c), 突然断电是无法保存进度的. 在第一次使用的时候会出现会话文件不存在的错误, 手动创建一个空文件即可. 如果您编写的是自动启动脚本, 在启动aria2前加上 touch aria2.session 这句命令.

input-file=/some/where/aria2.session
save-session=/some/where/aria2.session
#定时保存会话,需要1.16.1之后的release版
#save-session-interval=60

保存任务记录: 每一个能够被aria2c识别解析并进行下载的任务都有一个唯一的 gid。 保存任务记录的话比较好解决,在配置文件里记得开启save-session-interval=60, 再在配置文件末尾另起一行添加force-save=true,断电或重启后任务下载记录都不会丢失的,aria2.session文件也有记录了。

#save-session=/data/aria2.session
#save-session-interval=60
#force-save=true

断点续传: 默认情况下,当 aria2 重启后,所有任务记录都会清空,并且不会自动续传

#input-file=/data/aria2.session
#continue=true
磁盘相关
#文件保存路径, 默认为当前启动位置
dir=/some/where
#文件缓存(推荐), 使用内置的文件缓存, 如果你不相信Linux内核文件缓存和磁盘内置缓存时使用, 需要1.16及以上版本
#disk-cache=0

#另一种Linux文件缓存方式, 使用前确保您使用的内核支持此选项, 需要1.15及以上版本(?),由于大多数其他平台的CPU(路由器)都是32位的,而 aria2 enable-mmap 这个功能就是把整个文件映射到系统上,所以如果下载文件大于4G的话,aria2进程就会被内核杀掉。aria2 官方已提供另一种磁盘缓存,所以此选项基本作废。
#enable-mmap=true
#文件预分配, 能有效降低文件碎片, 提高磁盘性能. 缺点是预分配时间较长
#当使用 ext4, btrfs, xfs或者NTFS等文件系统时,作者推荐使用 --file-allocation=falloc,这种方式会在瞬间完成大文件(数G)的空间分配,并且不会带来额外的性能下降。
#所需时间 none < falloc ? trunc << prealloc, falloc和trunc需要文件系统和内核支持
file-allocation=falloc
BT相关
#启用本地节点查找
bt-enable-lpd=true
#添加额外的tracker
#bt-tracker=<URI>,…
#单种子最大连接数
#bt-max-peers=55
#强制加密, 防迅雷必备
#bt-require-crypto=true
#当下载的文件是一个种子(以.torrent结尾)时, 自动下载BT
follow-torrent=true
#BT监听端口, 当端口屏蔽时使用
#listen-port=6881-6999

aria2亦可以用于PT下载, 下载的关键在于伪装

#不确定是否需要,为保险起见,need more test
enable-dht=false
bt-enable-lpd=false
enable-peer-exchange=false
#修改特征
user-agent=uTorrent/2210(25130)
peer-id-prefix=-UT2210-
#修改做种设置, 允许做种
seed-ratio=0
#保存会话
force-save=true
bt-hash-check-seed=true
bt-seed-unverified=true
bt-save-metadata=true
#定时保存会话,需要1.16.1之后的某个release版本(比如1.16.2)
#save-session-interval=60

配置实战 (注意:请留意aria2的软件版本,其配置参数不一定都适用,请自行调整)

规划

1、下载目录: /home/ivo/Videos 2、配置文件: ~/aria2/aria2.conf 3、session和log: ~/aria2/aria2.session 和 ~/aria2/aria2.log

第一步:编辑配置文件

# touch /data/aria2.session
# vim /etc/aria2/aria2.conf
## '#'开头为注释内容, 选项都有相应的注释说明, 根据需要修改 ##
## 被注释的选项填写的是默认值, 建议在需要修改时再取消注释  ##

## 文件保存相关 ##

# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置
dir=/home/ivo/Videos

# 启用磁盘缓存, 0为禁用缓存, 需1.16以上版本, 默认:16M
#disk-cache=32M
#disk-cache=32M
# 文件预分配方式, 能有效降低磁盘碎片, 默认:prealloc
# 预分配所需时间: none < falloc ? trunc < prealloc
# falloc和trunc则需要文件系统和内核支持
# NTFS建议使用falloc, EXT3/4建议trunc, MAC 下需要注释此项
file-allocation=prealloc
# 断点续传
continue=true

## 下载连接相关 ##

# 最大同时下载任务数, 运行时可修改, 默认:5
max-concurrent-downloads=10
# 同一服务器连接数, 添加时可指定, 默认:1
max-connection-per-server=10
# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M
# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载
min-split-size=10M
# 单个任务最大线程数, 添加时可指定, 默认:5
split=5
# 整体下载速度限制, 运行时可修改, 默认:0
#max-overall-download-limit=0
# 单个任务下载速度限制, 默认:0
#max-download-limit=0
# 整体上传速度限制, 运行时可修改, 默认:0
#max-overall-upload-limit=0
# 单个任务上传速度限制, 默认:0
#max-upload-limit=0
# 禁用IPv6, 默认:false
disable-ipv6=true

## 进度保存相关 ##

# 从会话文件中读取下载任务
input-file=/home/ivo/aria2/aria2.session
# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件
save-session=/home/ivo/aria2/aria2.session
# 定时保存会话, 0为退出时才保存, 需1.16.1以上版本, 默认:0
save-session-interval=60

## RPC相关设置 ##

enable-rpc=true
pause=false
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-save-upload-metadata=true
rpc-secure=false

# 启用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-secure=<taken>
# 设置的RPC访问用户名, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-user=<USER>
# 设置的RPC访问密码, 此选项新版已废弃, 建议改用 --rpc-secret 选项
#rpc-passwd=<PASSWD>

## BT/PT下载相关 ##

# 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务, 默认:true
#follow-torrent=true
# BT监听端口, 当端口被屏蔽时使用, 默认:6881-6999
listen-port=51413
# 单个种子最大连接数, 默认:55
#bt-max-peers=55
# 打开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=false
# 每个种子限速, 对少种的PT很有用, 默认:50K
#bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
#peer-id-prefix=-TR2770-
user-agent=Transmission/2.92
#user-agent=netdisk;4.4.0.6;PC;PC-Windows;6.2.9200;WindowsBaiduYunGuanJia
# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0

seed-ratio=1.0
#作种时间大于30分钟,则停止作种
seed-time=30
# 强制保存会话, 话即使任务已经完成, 默认:false
# 较新的版本开启后会在任务完成后依然保留.aria2文件
#force-save=false
# BT校验相关, 默认:true
#bt-hash-check-seed=true
# 继续之前的BT任务时, 无需再次校验, 默认:false
bt-seed-unverified=true
# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false
bt-save-metadata=true
#下载完成后删除.ara2的同名文件
on-download-complete=/home/ivo/aria2/delete_aria2
#on-download-complete=/home/pi/aria2/rasp.sh

第二步:启动服务

–conf-path 指定配置文件路径 -D 以Daemon的方式启动

aria2c --conf-path=~/aria2/aria2.conf -D
# ss -tulpn | grep aria2c
tcp    LISTEN  0   1   :::6800     :::*     users:(("aria2c",41664,7))
tcp    LISTEN  0   1    *:6800         *:*    users:(("aria2c",41664,6))

为了方便控制,我们提供启动脚本: aia2start.sh 如果需要关闭 输入killall aria2c即可

cat aria2start.sh

#!/bin/bash
# Program
# Start aria2 use path address aria2.conf
address=/home/ivo/aria2
aria2c --conf-path="$address"/aria2.conf -D

添加可执行权限 chmod +x ~/aria2/aria2start.sh

另一个网上的例子,上面的配置文件是我自己的 网上copy的一个 aria2.conf 配置,大家可以参考:

mkdir -p /opt/var/log/aria2
mkdir -p /opt/etc/aria2
mkdir -p /tmp/mnt/disca_3/Downloads
touch /opt/etc/aria2/aria2.conf

cat /opt/etc/aria2/aria2.conf

daemon=true
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
####### your download folder, ensure that this folder exist! ##########
dir=/tmp/mnt/disca_3/Downloads
#where is your logfile located
log=/opt/var/log/aria2/aria2.log
log-level=warn
dht-listen-port=6801
auto-save-interval=30
#seed ratio and seed time in minutes
seed-ratio=1.0
seed-time=1460
max-upload-limit=20K
event-poll=select

aria2c 的服务管理脚本:

touch /opt/etc/init.d/S85aria2
vim /opt/etc/init.d/S85aria2
# For Olegs & Ily's FW for Asus Routers
# store this script in /opt/etc/init.d if you've installed optware

# Prgmname=/full_path/Prgmname
prgmname1="/opt/bin/aria2c"
shortname="aria2c"

#one option 
options="--conf-path="

# configfile=/full_path/configfile
configfile="/opt/etc/aria2/aria2.conf"

start() {
        # Code here to start the program
        logger -t ARIA2C "Starting aria2c daemon "
        ${prgmname1} ${options}${configfile}
	sleep 5
        return 0
}

stop() {
        # Code here to stop the program and check it's dead
        if [ -n "`pidof $shortname`" ]; then
           logger -t ARIA2C "Shutting down aria2c daemon "
            /usr/bin/killall $shortname
           sleep 5
        fi
        return 0
}
##########################start here##########################
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        logger -t ARIA2C "$shortname restart, executed from $(whoami)"
        stop
        sleep 2
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
sleep 1
exit

chmod 755 /opt/etc/init.d/S85aria2 reboot

aria2 web 前端控制界面

当我们在使用 yaaw 或者 webui-aria2时,需要注意的是:

请使用 chrome, firefox 等现代浏览器来访问。 这两种工具上的配置在重启浏览器后都会失效,因此请使用配置文件保存您的设置 图形界面都是基于 RPC 模式,所以一定确定开启了 RPC, IP端口可以访问,并且在管理器中填写了正确的地址。 YAAW前端远程访问(前提是路由已经开启远程访问功能):配置 防火墙

iptables -A INPUT -p tcp –dport 6800 -j ACCEPT  
YAAW – Yet Another Aria2 Web Frontend

是一个纯前端实现的Aria2 Web前端界面。无需架设任何服务器,只需要在浏览器(chrome, firefox, 使用IE的同学嘛。。。)中打开即刻使用。

http://aria2.ghostry.cn/yaaw-master/

Usage:

1、run aria2 with RPC enabled aria2c –enable-rpc –rpc-listen-all=true –rpc-allow-origin-all -c -D

2、visit index.html

3、change “JSON-RCP Path” setting if “Internal server error” occurred。

在扳手处填入path: http://:6800/jsonrpc,然后修改 JSON-RPC Path, 否则报错:Error: Internal server error

Aria2 webui

Aria 2 Web-UI 是一个在线图形界面(下载到本地也可以使用),完美支持 Aria 2 的各种功能,包括自定义客户端地址进行远程控制。要下载最新版本请访问 http://github.com/ziahamza/webui-aria2 或用你的浏览器(推荐Firefox, Chrome)直接访问

http://ziahamza.github.com/webui-aria2

http://ziahamza.github.io/webui-aria2/

我们可以直接访问在线的链接, 然后设置服务器地址即可。 Aria2 webui 部署到本地服务器:

首先部署 web 服务器,这里使用nginx

使用yum工具安装 gcc 编译器以及相关工具

yum -y install gcc gcc-c++ automake autoconf libtool make

使用yum工具安装模块依赖的库pcre, zlib, 前者为了支持重写rewrite, 后者为了支持gzip压缩ssl

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
# 添加用户和组
# groupadd nginx
# useradd -g nginx -s /sbin/nologin nginx
 
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.7.9.tar.gz
# tar xf nginx-1.7.9.tar.gz 
# cd nginx-1.7.9
# ./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx/lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--user=nginx \
--group=nginx
 make && make install
# 注意iptables 与 SELinux , 这里我们关闭它
## For iptables
service iptables stop
# chkconfig iptables off
## For SELinux
setenforce 0
getenforce
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 

nginx 服务管理脚本

vim /etc/init.d/nginx
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /var/run/nginx.pid
   
# Source function library.
. /etc/rc.d/init.d/functions
   
# Source networking configuration.
. /etc/sysconfig/network
   
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
   
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
   
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
   
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
   
lockfile=/var/lock/subsys/nginx
   
make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
   
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
   
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
   
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
   
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
   
force_reload() {
    restart
}
   
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
   
rh_status() {
    status $prog
}
   
rh_status_q() {
    rh_status >/dev/null 2>&1
}
   
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

添加可执行权限

chmod +x /etc/init.d/nginx

启动

 ss -tulpn | grep nginx
tcp    LISTEN     0    128   *:80   *:*   users:(("nginx",44232,6),("nginx",44234,6))

下载官方的 aria2 webgui

git clone https://github.com/ziahamza/webui-aria2.git

部署到nginx

 cp -r webui-aria2 /usr/local/nginx/html/

编辑 nginx.conf 配置文件

 vim /etc/nginx/nginx.conf
 location /webui-aria2 {
            root   html;
            index  index.html index.htm;
        }

重启nginx

service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

4、访问

打开浏览器,在地址栏输入 http://your_ip/webui-aria2 即可访问

webui-aria2, 以及 yaaw 都有相应的中文汉化版。可以 查看这个网址: http://aria2.ghostry.cn/ yaaw: https://github.com/ghostry/yaaw 上面几种方式都可以进行下载,但是需要提醒的是:

因为下载完成后文件是存在服务器上的,所以下载完成后需要通过ftp或ssh等其他方式才能取得文件。当然,我们可以开启nginx作为下载服务器,然后进行下载到本地的操作。

最简单的配置nginx.conf使之成为静态文件下载服务器 sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on;

    server {
        listen       8082;        #端口
        server_name  localhost;   #服务名
        root    /dev/shm/update;  #显示的根索引目录
        autoindex on;             #开启索引功能
        autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
        autoindex_localtime on;   # 显示本机时间而非 GMT 时间
    }

用户认证

server { 
     listen       80;  //监听端口为80 
     server_name  www1.rsyslog.org;  //虚拟主机网址 
      location / { 
            root   sites/www1;  //虚拟主机网站根目录 
            index  index.html index.htm;  //虚拟主机首页 
            
            auth_basic "secret";  //虚拟主机认证命名 
            auth_basic_user_file /usr/local/nginx/passwd.db; //虚拟主机用户名密码认证数据库 
        } 
        location /status { 
                stub_status on;  //开启网站监控状态 
                access_log /usr/local/nginx/logs/www1_status.log; //监控日志 
                auth_basic "NginxStatus"; } 
    } 

通过htpasswd命令生成用户名及对应密码数据库文件。 htpasswd -c /usr/local/nginx/passwd.db admin //创建认证信息,admin 为认证用户名 New password: *** //输入认证密码 Re-type new password: **** //再次输入认证密码 如果你输入htpasswd命令提示没有找到命令时,你需要安装httpd。如果是centos可以执行如下来安装 更多详细信息,请参考:http://www.92csz.com/25/116.html

yum -y install httpd

五、ThunderLixianExporter 作用: 将迅雷离线地址导出成aria2/wget等下载命令,方便Linux/Mac用户使用 您需要拥有迅雷会员帐号才能使用此插件 原生导出界面整合, 原生设置界面整合 反文件名截断 多种可扩展的导出器(aria2/aria2-rpc/wget/IDM/Orbit) 云点播HTML5播放,导出 直接输出选中的链接,配合FlashGot/DownThemAll使用 接下来要改造chrome 浏览器。请访问 http://binux.github.com/ThunderLixianExporter/

然后我们去迅雷离线网站 lixian.xunlei.com,然后通过某个方式找一个迅雷账号,登录。在主界面下,点下刚才保存的书签,会在取回本地按钮边出现一个下拉菜单(先不要点哈)。 先点 右上角 的齿轮图标,进去后填如下地址,当然IP还是改成你的 aria2 服务器的 IP,其它不改 保存设置,然后找到一个文件,点取回本地的下拉“三角”, 选择 YAAW 然后打开刚才弄好的Aria WebUI,看看是不是有任务开始下载了?如果你没有成功,别着急,可能需要重新打开迅雷离线网站,点下那个书签,再下一次,应该没问题的。

常见问题

Internal server error

手动访问你的JSON-RPC地址 http://hostname:port/jsonrpc?jsoncallback=1 如果没有返回, 请确认aria2是否启动以及连通性. 如果aria2在路由器后或没有公网IP, 请做好端口映射.

如何使用迅雷离线

http://binux.github.com/ThunderLixianExporter/ 安装后, 在迅雷离线的右上角的设置中设置RPC地址. 提供chrome插件:https://chrome.google.com/webstore/detail/thunderlixianassistant/eehlmkfpnagoieibahhcghphdbjcdmen

如何使用旋风离线(QQ离线)

http://userscripts.org/scripts/show/142624安装脚本后, 在旋风离线页面使用.

如何安装aria2

我也不知道, 看你的box上有什么开源包管理器之类的东西, 有什么用什么. 如果没有, google之, 如果没有, 放弃吧.

http://www.right.com.cn/forum/thread-115029-1-1.html

http://aria2.ghostry.cn/yaaw-master/

http://aria2.dualwan.cn/webui/index.html

http://binux.github.io/ThunderLixianExporter/

http://blog.binux.me/2012/12/aria2-examples/

http://www.chiphell.com/thread-580013-1-1.html

本内容同步更新在我的个人博客 「EZLOST」 https://ezlost.com 搜索查询关注订阅评论 更加方便快捷.内容转载请注明来源。