在linux系统上安装Aria2和WEBUI搭建离线下载神器
一、安装aria2
1、安装aria2的方法很简单,一条命令就够了
Centos 7:
1 2 3 |
yum install epel-release yum install aria2 |
Ubuntu:
1 |
apt-get install aria2 |
如果出现【Unable to locate package aria2】或者【No package aria2 available.】的错误,表示你需要更新一下。
Centos 7:
1 |
yum update |
Ubuntu:
1 |
apt-get update |
系统版本不同源自带的aria2版本也会不同,centos6的话是aria2 16.0X的版本,centos7能到18.x,至于ubuntu,一向包更新的比较快,应该都是最新。如果你对版本不满意,也可以自己下载源码后编译。
2、下载安装好了以后,远程下载文件就很简单了
单个文件下载
1 |
aria2c http://example.org/mylinux.iso |
从两个来源(更多也可以)
aria2c http://a/f.iso ftp://b/f.iso
BitTorrent
aria2c http://example.org/mylinux.torrent
BitTorrent Magnet URI
aria2c ‘magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C’
Metalink
aria2c http://example.org/mylinux.metalink
文本文件uri.text中的链接(URI)
aria2c -i uri.txt
显示种子中包含了哪些文件
aria2c -S bit.torrent
二、配置aria2
1、开启RPC远程管理命令
1 |
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -c -D |
说明: 这个命令在VPS上运行即可开启rpc服务,可以用多种方式进行远程管理,但貌似不会保存配置文件,重启后会丢失之前的下载记录
2、让配置文件不丢失
用winscp新建以下目录【/etc/aria2/】然后在aria2目录下创建文件文件【aria2.conf】,文件内容如下:
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
## '#'开头为注释内容, 选项都有相应的注释说明, 根据需要修改 ## ## 被注释的选项填写的是默认值, 建议在需要修改时再取消注释 ## #允许rpc enable-rpc=true #允许所有来源, web界面跨域权限需要 rpc-allow-origin-all=true #允许非外部访问 rpc-listen-all=true #RPC端口, 仅当默认端口被占用时修改 #rpc-listen-port=6800 #用户名 rpc-user=susu #密码 rpc-passwd=138vps ###速度相关 #最大同时下载数(任务数), 路由建议值: 3 max-concurrent-downloads=5 #断点续传 continue=true #同服务器连接数 max-connection-per-server=5 #最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要 min-split-size=20M #单文件最大线程数, 路由建议值: 5 split=10 #下载速度限制 0 不限制 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=* ###进度保存相关 input-file=/root/aria2.session save-session=/root/aria2.session #定时保存会话,需要1.16.1之后的release版 #save-session-interval=60 ###磁盘相关 #文件保存路径, 默认为当前启动位置 dir=/var/www/html/ #文件缓存, 使用内置的文件缓存, 如果你不相信Linux内核文件缓存和磁盘内置缓存时使用, 需要1.16及以上版本 #disk-cache=0 #另一种Linux文件缓存方式, 使用前确保您使用的内核支持此选项, 需要1.15及以上版本 #enable-mmap=true #文件预分配, 能有效降低文件碎片, 提高磁盘性能. 缺点是预分配时间较长 #所需时间 none < falloc ? trunc << prealloc, falloc和trunc需要文件系统和内核支持 file-allocation=prealloc ###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版本 #save-session-interval=60 |
3、然后运行该命令
1 |
aria2c --conf-path=<span class="hljs-regexp">/etc/</span>aria2/aria2.conf -D |
4、开机自动启动
centos
到【/etc/rc.d/rc.local】文件下面加入下面这一行
1 |
aria2c --conf-path=<span class="hljs-regexp">/etc/</span>aria2/aria2.conf -D & |
ubuntu
到【/etc/rc.local】文件内,在【exit 0】前面加入下面一行
1 |
aria2c --conf-path=<span class="hljs-regexp">/etc/</span>aria2/aria2.conf -D & |
启动脚本
1 |
$ vi /etc/init.d/aria2 |
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 |
#!/bin/bash # # aria2 - this script starts and stops the aria2 daemon # # chkconfig: - 85 15 # description: Aria2 - Download Manager # processname: aria2c # config: /etc/aria2/aria2.conf # pidfile: # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 aria2c="/usr/bin/aria2c" ARIA2C_CONF_FILE="/etc/aria2/aria2.conf" options=" --conf-path=$ARIA2C_CONF_FILE -D " RETVAL=0 start() { # code here to start the program echo -n "Starting aria2c daemon." ${aria2c} ${options} RETVAL=$? echo } stop() { echo -n "Shutting down aria2c daemon." /usr/bin/killall aria2c RETVAL=$? echo } status() { ID=$(/bin/ps -ef | grep 'aria2c' | grep -v 'grep' | awk '{print $2}') if [[ "x$ID" != "x" ]]; then echo "Aria2 is running." else echo "Aria2 is not running." fi } restart() { stop sleep 3 start } case "$1" in start) start ;; stop) stop ;; status) status ;; restart) restart ;; *) echo "Usage: service aria2c {start|stop|restart}" RETVAL=1 esac exit $RETVAL |
三、安装WEBUI
1、首先要安装http服务,注意,如果有iptables,要先开放80端口,具体教程请本博客搜索 iptables
centos:
1 2 3 4 5 |
yum -y install httpd chkconfig --levels 235 httpd on service httpd start |
ubuntu:
1 |
apt-get -y install apache2 |
2、到https://github.com/ziahamza/webui-aria2下载最新的WebUI压缩包。
解压后上传到 【/var/www/html/】,并改名为【webui】。同时设置权限:
1 |
chmod 755 /var/www/html/webui |
3、http://IP地址/webui 就可访问成功;如果报错,在“设置”–> “服务器设置”中“主机:”后后面填写自己的IP地址就可;
如果Aria2.conf配置文件中启用了RPC安全认证,需要在WEB客户端设置中填入RPC用户名和密码,否则客户端报错。
注意:centos7安装好WebUI后,连接上去会出现“上次连接请求未成功,正在尝试使用另一个配置 糟糕! 无法连接到 Aria2 RPC 服务器,将在10秒后重试……..”的错误,这个时候再运行一遍第二步的第1步代码就好了:
1 |
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -c -D |