Aria2+Aria2Ng+OneIndex+OneDrive建立不限流量/离线BT下载/在线观看网盘

1、安装宝塔

#Centos系统
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.sh && sh install.sh
#Ubuntu系统
wget -O install.sh http://download.bt.cn/install/install-ubuntu.sh && sudo bash install.sh
#Debian系统
wget -O install.sh http://download.bt.cn/install/install-ubuntu.sh && bash install.sh

安装完成后,进入面板安装PHP 5.6+、Nginx。

2、安装OneIndex

先添加域名,然后上传程序文件到网站根目录/www/wwwroot/xx.com,将文件解压出来,并设置config/、cache/可读写权限,程序下载:OneIndex.zip
也可以使用命令上传到根目录:

#Debian/Ubuntu系统
apt-get install git -y
#CentOS系统
yum install git -y

#修改为自己域名根目录后再运行
cd /www/wwwroot/xx.com
git clone https://github.com/donwa/oneindex.git
mv oneindex/* ./
chmod 777 ./config && chmod 777 ./cache

再点击域名设置,添加Nginx伪静态:

if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)$ /index.php?/$1 last;
}

最后打开域名进行安装和绑定OneDrive了,后台地址:https://xx.com/?/admin ,默认密码:oneindex。如果你想给域名加上https安全访问,可以通过域名设置配置一下SSL证书。

3、安装Aria2

这里用的逗比的脚本,使用命令:

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/aria2.sh && chmod +x aria2.sh && bash aria2.sh
#备用地址
wget -N --no-check-certificate https://www.moerats.com/usr/shell/Aria2/aria2.sh && chmod +x aria2.sh && bash aria2.sh

安装完成后,如果我们想修改密码、下载文件位置、端口的话,可以使用命令bash aria2.sh,再选择修改配置即可,这里建议使用该脚本配置自动更新BT-Tracker服务器,对下载BT有加成。

4、安装AriaNg

这一步和安装OneIndex差不多,先添加一个域名,不想用域名的可以在添加域名那里填上IP或者IP:端口,然后将AriaNg程序上传到对应的根目录,可以使用命令:

#这里以添加IP为例
#Debian/Ubuntu系统
apt-get install unzip -y
#CentOS系统
yum install unzip -y

cd /www/wwwroot/11.22.33.44
wget https://www.moerats.com/usr/down/aria-ng-0.2.0.zip && unzip aria-ng-0.2.0.zip

这时候我们就可以使用IP访问AriaNg界面了,或者IP:端口,这取决于你添加域名的时候填的什么了。

配置Aria2上传

这里说下3种自动上传的方法,第1种使用OneIndex程序自带的上传,第2种使用Rclone挂载后自动上传,第3种使用上传脚本,由于前2种上传有BUG,建议使用第3种脚本上传,对于不想折腾的人来说,也可以直接使用第1种方法。

1、OneIndex上传

先在/root/.aria2文件夹新建一个上传脚本,命名oneindexup.sh。

#这里也可以使用vi命令,自己看着办
nano /root/.aria2/oneindexup.sh

将以下代码修改后,复制进脚本:

#!/bin/bash
path=$3 #取原始路径,我的环境下如果是单文件则为/data/demo.png,如果是文件夹则该值为文件夹内某个文件比如/data/a/b/c/d.jpg
downloadpath='/usr/local/caddy/www/aria2/Download'  #修改成Aria2下载文件夹
domain='moerats.com'  #修改成自己域名

if [ $2 -eq 0 ]
        then
                exit 0
fi
while true; do  #提取下载文件根路径,如把/data/a/b/c/d.jpg变成/data/a
filepath=$path
path=${path%/*}; 
if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ]  #如果下载的是单个文件
    then
    php /www/wwwroot/$domain/one.php upload:file $filepath /$folder/
    rm -rf $filepath
    php /www/wwwroot/$domain/one.php cache:refresh
    exit 0
elif [ "$path" = "$downloadpath" ]
    then
    php /www/wwwroot/$domain/one.php upload:folder $filepath /$folder/
    rm -rf "$filepath/"
    php /www/wwwroot/$domain/one.php cache:refresh
    exit 0
fi
done

然后再授权:

chmod +x /root/.aria2/oneindexup.sh

最后在配置文件aria2.conf里加上一行on-download-complete=/root/.aria2/oneindexup.sh,可以直接使用命令:

echo "on-download-complete=/root/.aria2/oneindexup.sh" >>/root/.aria2/aria2.conf
#重启Aria2
service aria2 restart

2、Rclone挂载上传

我们先使用挂载Rclone挂载OneDrive
在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/ 。然后解压出来,比如我解压到D盘,文件夹命名rclone,此时点击Win+R,然后输入cmd,确定。再输入以下命令:

cd /d d:\rclone
rclone authorize "onedrive"

会出现以下信息:

C:\Users\Administrator>cd /d d:\rclone

d:\rclone>rclone authorize "onedrive"
2018/01/23 20:28:56 NOTICE: Config file "C:\\Users\\Administrator\\.config\\rclo
ne\\rclone.conf" not found - using defaults
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
If your browser doesn't open automatically go to the following link: http://127.
0.0.1:53682/auth  #接下来会弹出浏览器,要求你登录账号进行授权
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容,后面需要用到
<---End paste

【安装rclone】本教程只适用Debian/Ubuntu系统,如果你是CentOS,请参考:https://rclone.org/install/ ,安装rclone。挂载方法和下面差不多。
1、安装rclone

wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

2、初始化配置

rclone config

会出现以下信息:

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 14  #原博文选择14,但新版本序号可能已经修改,请查找:Microsoft OneDrive-"onedrive"
Microsoft App Client Id - leave blank normally.
client_id>  #留空 
Microsoft App Client Secret - leave blank normally.
client_secret>  #留空 
Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n  #选择n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""}  #输入之前在客户端授权的内容
--------------------
[Rats]
client_id = 
client_secret = 
token = {"access_token":""}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  选择y
Current remotes:

Name                 Type
====                 ====
Rats                 onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q  #选择q退出

【挂载rclone】
1、挂载为磁盘

#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/OneDrive
#挂载为磁盘
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的name,Folder为OneDrive里的文件夹,LocalFolder为VPS上的本地文件夹。
如果挂载过程中出现NOTICE: One drive root 'test': poll-interval is not supported by this remote错误,可以无视该错误。
挂载成功后,输入df -h命令查看即可!

2、卸载磁盘

fusermount -qzu LocalFolder

【配置自启动】
1、下载并编辑脚本
使用命令:

wget https://www.moerats.com/usr/shell/rcloned && nano rcloned

修改一下内容:

NAME=""  #rclone name名,及配置时输入的Name
REMOTE=''  #远程文件夹,OneDrive网盘里的挂载的一个文件夹
LOCAL=''  #挂载地址,VPS本地挂载目录

2、设置自启
使用命令:

#Debian系统
apt-get install sudo -y

#设置自启
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults
bash /etc/init.d/rcloned start

检测信息显示rclone启动成功即可。

最后我们就可以利用OneDrive for Business为Linux VPS增加5TB的空间了。

阅读剩余
THE END