昨天淘的电源和散热片终于到货了,别看这货身子小,要求到挺高,本来是周一就拿到了深圳韵动发过来的B+板,但是用公司台式机笔记本的U口,死活就是驱不起来着块小板子,回家用HTC手机的1A电源头,勉强倒是可以工作,用ssh登进去看了一眼,系统也算比较完整,我安装的是raspbian,该有的功能基本上都有,gcc都带了,还有什么不能满足呢。孰料第二天将电源头和板子拿回公司试,却又回到老样子,电源灯总是闪一会儿就灭了,无奈啊,谁叫MicroUSB线不过关呢,只好再去淘宝上买一套电源,顺带捎了一个散热片,这下总算完备了。接下来,就该让Pi为我们干活了,做什么呢,看看陈建皓的《RASPBERRY PI入门指南》,搭建wordpress,tomcat,mysql什么的,这些都太考验我们的小Pi了,还是先弄个离线下载服务器吧,省时省力省电,何乐而不为呢.
说实话,关于Aria2,我还是第一次从这里听说。平时工作生活都用的是windows系统,下载工具当然首选迅雷了,还有某某网盘的离线下载,基本上也就止步于此。Aria2,还真是一个小清新。废话不多说,下面就顺一下我的安装历程,其实整个安装过程非常的简单,raspbian默认的源里面就带有Aria2,所以基本上就是一个命令的事,主要值得学习的,还是Aria2c的配置。
第一步 安装aria2
1 2 3 |
sudo apt-get install aria2 |
目前安装的版本是1.15
第二步 配置
首先给出我的配置文件
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 |
## Run as daemon. The current working directory will be changed to / and standard input, standard output and standard error will be redirected to /dev/null. Default: false daemon=true ## The directory to store the downloaded file dir=/home/pi/download ## Set log level to output. LEVEL is either debug, info, notice, warn or error. Default: debug log-level=info ## The file name of the log file. If - is specified, log is written to stdout. If empty string("") is specified, or this option is omitted, no log is written to disk at all. log=/var/aria2/log/aria.log ### RPC Options ### ## Enable JSON-RPC/XML-RPC server. It is strongly recommended to set secret authorization token using --rpc-secret option. See also --rpc-listen-port option. Default: false enable-rpc=true ## Listen incoming JSON-RPC/XML-RPC requests on all network interfaces. If false is given, listen only on local loopback interface. Default: false rpc-listen-all=true ## Add Access-Control-Allow-Origin header field with value * to the RPC response. Default: false rpc-allow-origin-all=true ### RPC Options ### ## Downloads the URIs listed in FILE. You can specify multiple sources for a single entity by putting multiple URIs on a single line separated by the TAB character. Additionally, options can be specified after each URI line. Option lines must start with one or more white space characters (SPACE or TAB) and must only contain one option per line. Input files can use gzip compression. input-file=/home/pi/aria2/aria2.session ## Save error/unfinished downloads to FILE on exit. You can pass this output file to aria2c with --input-file option on restart. If you like the output to be gzipped append a .gz extension to the file name. Please note that downloads added by aria2.addTorrent() and aria2.addMetalink() RPC method and whose meta data could not be saved as a file are not saved. Downloads removed using aria2.remove() and aria2.forceRemove() will not be saved. GID is also saved with gid, but there are some restrictions, see below. ## Normally, GID of the download itself is saved. But some downloads use meta data (e.g., BitTorrent and Metalink). In this case, there are some restrictions. ## 1.magnet URI, and followed by torrent download ## GID of BitTorrent meta data download is saved. ## 2.URI to torrent file, and followed by torrent download ## GID of torrent file download is saved. ## 3.URI to metalink file, and followed by file downloads described in metalink file ## GID of metalink file download is saved. ## 4.local torrent file ## GID of torrent download is saved. ## 5.local metalink file ## Any meaningful GID is not saved. save-session=/home/pi/aria2/aria2.session ## Save error/unfinished downloads to a file specified by --save-session option every SEC seconds. If 0 is given, file will be saved only when aria2 exits. Default: 0 save-session-interval=60 ## Continue downloading a partially downloaded file. Use this option to resume a download started by a web browser or another program which downloads files sequentially from the beginning. Currently this option is only applicable to HTTP(S)/FTP downloads continue=true ## Download a file using N connections. If more than N URIs are given, first N URIs are used and remaining URIs are used for backup. If less than N URIs are given, those URIs are used more than once so that N connections total are made simultaneously. The number of connections to the same host is restricted by the --max-connection-per-server option. See also the --min-split-size option. Default: 5 split=5 ## Set the maximum number of parallel downloads for every queue item. See also the --split option. Default: 5 max-concurrent-downloads=3 ## The maximum number of connections to one server for each download. Default: 1 max-connection-per-server=5 ## Set timeout in seconds. Default: 60 timeout=600 ## Set number of tries. 0 means unlimited. See also --retry-wait. Default: 5 max-tries=0 ## Set the seconds to wait between retries. When SEC > 0, aria2 will retry downloads when the HTTP server returns a 503 response. Default: 0 retry-wait=30 ## FTP Specific Options ## Use the passive mode in FTP. If false is given, the active mode will be used. Default: true #ftp-pasv[=true|false] ## ## Stop BitTorrent download if download speed is 0 in consecutive SEC seconds. If 0 is given, this feature is disabled. Default: 0 #bt-stop-timeout=<SEC> ## Set max overall upload speed in bytes/sec. 0 means unrestricted. You can append K or M (1K = 1024, 1M = 1024K). To limit the upload speed per torrent, use --max-upload-limit option. Default: 0 max-overall-upload-limit=512 ### Advance ### ## Disable IPv6. This is useful if you have to use broken DNS and want to avoid terribly slow AAAA record lookup. Default: false disable-ipv6=true ## Enable disk cache. If SIZE is 0, the disk cache is disabled. This feature caches the downloaded data in memory, which grows to at most SIZE bytes. The cache storage is created for aria2 instance and shared by all downloads. The one advantage of the disk cache is reduce the disk I/O because the data are written in larger unit and it is reordered by the offset of the file. If hash checking is involved and the data are cached in memory, we don't need to read them from the disk. SIZE can include K or M (1K = 1024, 1M = 1024K). Default: 16M disk-cache=40M ## Specify file allocation method. none doesn't pre-allocate file space. prealloc pre-allocates file space before download begins. This may take some time depending on the size of the file. If you are using newer file systems such as ext4 (with extents support), btrfs, xfs or NTFS(MinGW build only), falloc is your best choice. It allocates large(few GiB) files almost instantly. Don't use falloc with legacy file systems such as ext3 and FAT32 because it takes almost same time as prealloc and it blocks aria2 entirely until allocation finishes. falloc may not be available if your system doesn't have posix_fallocate(3) function. trunc uses ftruncate(2) system call or platform-specific counterpart to truncate a file to a specified length. ## Possible Values: none, prealloc, trunc, falloc Default: prealloc file-allocation=none ### Advance ### ## iptables -I INPUT -p tcp --dport 6800 -j ACCEP |
这里补充几句,上面的配置是从手册和其他人的blog里面集成而来,原来的注释可能都是中文,但是我怎么看怎么别扭,于是就去sourceforge查看了一下原生的option说明,比来比去还是觉得原味的好,于是就将用到的选项的官方说明都粘贴于此,以便于理解。其中有三个选项需要关注一下:rpc-allow-origin-all,disk-cache和max-overall-upload-limit,第一个选项是为了我们能用YaaW顺利的连上aria2,强调的目的就是我刚开始没有配置这一项,结果YaaW总是提示internel error,所以提醒一下;disk-cache是为了增加缓存的大小,毕竟SD卡也是有寿命的,我们的Pi有512M的内存,应该合理的利用;最后一个是max-overall-upload-limit,限制上传的速度。配置文件中用到了几个外部文件/home/pi/download,/home/pi/aria2/aria2.session,/var/aria2/log/aria.log连同配置文件自己,都需要手动创建:
1 2 3 4 5 6 7 8 |
mkdir /home/pi/download mkdir /home/pi/aria2 sudo mkdir -p /var/aria2/log cd /home/pi/aria2 touch aria2.conf touch aria2.session |
这里是sourceforge的原生参数说明,注意这里给出的是aria2c的命令参数,前面都有两个- -,将- -去掉就是配置文件里面使用的选项:
http://aria2.sourceforge.net/manual/en/html/aria2c.html#cmdoption-i
第三步 启动aria2c
1 2 3 |
sudo aria2c --conf-path=/home/pi/aria2/aria2.conf -D |
启动完成之后,应该可以看到aria2c的进程,已经默认的6800端口已经被监听了:
1 2 3 4 |
ps -ef| grep aria2c netstat -anp| grep 6800 |
第四步 使用YaaW,建立我们的下载任务
YaaW建议直接下载到本地,不用在chrome里面安装应用,但是浏览器还是应该使用chrome,因为我的老牛本上测试IE7无法工作的,IE8是否情况会好点?
下面是下载链接:
https://codeload.github.com/binux/yaaw/zip/master
解压下载后的压缩包,打开里面的index.html,然后点击refresh旁边的扳手来配置Pi的ip地址,例如:
http://192.168.1.105:6800/jsonrpc
然后保存,接下来就可以通过Add选项添加你的下载任务了,应该都很简单的
补充:
从raspbian源上下载的aria2版本是1.15,目前最新的版本已经更新到1.18了,所以我们有必要对它升个级,升级的办法也很简单,就是下载源码包重新编译一下:
http://jaist.dl.sourceforge.net/project/aria2/stable/aria2-1.18.8/aria2-1.18.8.tar.bz2
1 2 3 4 5 6 |
tar -jxvf aria2-1.18.8.tar.bz2 cd aria2-1.18.8 ./configure make |
编译很简单,因为是放到raspbian里编译的,所以也不用配置什么环境,make之后会在src下面找到已经生成的aria2c,将其拷贝到/usr/bin下面即可,注意原来的1.15版本最好是备份一下。
后记:
当天晚上就去去网上搜了一部蝎子王4的种子,早晨起来看Pi已经下载完成了,真个是非常的方便,再也不用开着笨重的电脑去下载电影或者什么了,以后得省下多少电啊