aria2+oneindex+onedrive实现离线网盘下载服务器

0.环境说明:

①Centos7.X VPS

②安装软件:aria2+oneindex+aria2Ng

③使用教育网邮箱申请的onedrive账号

1.安装aria2(这里使用无脑脚本):

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/aria2.sh && chmod +x aria2.sh && bash aria2.sh

到下面界面输入1并回车安装,等待依赖安装完成,过程中选择输入Y

接下来会让你选择安装版本:

如此处,输入 :

1
 1.34.0

出现启动成功的提示,aria2安装完成,记住此时的密码,ariaNg的前端RPC配置中输入此密码,否则不能链接成功。

2.安装oneindex

定位到你为oneindex开辟的网站目录,并安装:

cd /youoneindexhome  # /youoneindexhome 是你开辟的 oneindex 网站目录
git clone https://github.com/donwa/oneindex.git
cd oneindex
chmod -R 777 config/ cache/
mv * ../
cd ../
rm -rf oneindex

oneindex安装完成。

3.安装ariaNg(aria2前端):

安装uzip工具:

yum install unzip -y

安装ariaNg,首先定位到你为 ariaNg开辟的网站目录,并安装:

cd /yourariang # / yourariang  是你开辟的ariaNg网站目录
wget https://github.com/mayswind/AriaNg/releases/download/1.1.1/AriaNg-1.1.1.zip
unzip AriaNg-1.1.1.zip

4.oneindex和aria2配置

更改oneindex伪静态规则,如果你的网站使用nginx,只需要在对应的conf文件server段添加以下内容:

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;
         }

登录你的oneindex站点,获取oneindex密钥的方法可以参考这篇文章:

https://www.newlearner.site/2019/01/11/oneindex.html

刷新缓存和token,下面的语句表示每小时刷新TOKEN和每十分钟重建缓存

crontab -e
0 * * * * php /youoneindexhome/one.php token:refresh                              
*/10 * * * * php /youoneindexhome/one.php cache:refresh

接下来配置aria2:

修改aria2.conf配置:

find / -name aria2.conf
vi /root/.aria2/aria2.conf

增加行 seed-time=0 ,否则会发生一直做种的情况,增加行 on-download-complete=/root/upload_onindex.sh ,后保存退出

seed-time=0 
on-download-complete=/root/upload_oneindex.sh

修改upload_oneindex.sh实现自动上传

vi /root/upload_oneindex.sh

加入以下内容:

!/bin/bash
logfile = 'onedown.log'
path=$3 
downloadpath='/usr/local/caddy/www/aria2/Download' 
folder='/others/download/key'   
 if [ $2 -eq 0 ] 
   then
     exit 0
 fi
 while true; do
 filepath=$path    
 path=${path%/*};  :
 if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ] 
     then
     echo "开始处理文件" $folder >> $logfile
     php /youoneindexhome/one.php upload:file "$filepath" /$folder/  >> $logfile
     echo "等待300秒后删除文件" $folder >> $logfile
     sleep 300
     rm -rf "$filepath"  >>   $logfile
     rm -rf  *.aria2  >>  $logfile
     php /youoneindexhome/one.php cache:refresh 
     exit 0
 elif [ "$path" = "$downloadpath" ] 
     then
     echo "开始处理文件" $folder >> $logfile
     php /youoneindexhome/one.php upload:folder "$filepath" /$folder/ >> $logfile
     echo "等待300秒后删除文件" $folder >> $logfile
     sleep 300
     rm -rf "$filepath/" 
     php /youoneindexhome/one.php cache:refresh 
     exit 0
 fi
 done

修改脚本权限:

chmod 755 /root/upload_oneindex.sh

重启aria

发表评论

Your email address will not be published.