设置
  • 日夜间
    随系统
    浅色
    深色
  • 主题色

IT之家学院:强大的网盘管理工具Rclone安装教程

2018/11/11 17:44:09 来源:IT之家 作者:hersxx1470 责编:玄隐
感谢IT之家网友 软媒用户1157091 的线索投递!

上期给大家介绍了Go语言BT下载利器CloudTorrent,那么这期给大家带来的依旧是一款基于Go语言的应用——Rclone。Rclone是一款非常强大的网盘工具,能够帮助用户在终端界面管理包括Dropbox、Box、Onedrive、Gdrive、Mega等在内的主流网盘中的各类资源,同时实用的挂载功能能够把网盘挂载到本地(OpenVZ架构的VPS不支持挂载)服务于Aria2、CloudTorrent等下载工具以及FileBrowser等私人网盘工具。

Rclone-GitHub首页:https://github.com/ncw/rclone

检查Rclone支持的网盘以及Rclone的官方安装脚本请前往GitHub,本文继续以Debian 9 VPS为例示范手动安装方法,Windows版本不另作示范。

介于上期内容许多家友觉得复杂,本期起取消所有的基础命令解释,想要学习手动配置但是基础薄弱的家友可以自己搜索相关命令的含义进行更改。

一、下载安装

复制以下命令到终端或者SSH工具中执行(整体复制,一个回车):

yum install unzip -y 

apt-get install unzip -y 

wget https://downloads.rclone.org/v1.44/rclone-v1.44-windows-amd64.zip

unzip rclone-v1.44-windows-amd64.zip

cd rclone-*/

mv rclone /usr/bin/

chmod 755 /usr/bin/rclone

mkdir -p /usr/local/share/man/man1

mv rclone.1 /usr/local/share/man/man1/

cd ..

rm -rf rclone-* 


安装成功检查:

此时执行rclone命令出现相关指令的帮助证明安装成功。

注意:

权限不足手动sudo或者sudo su启动root账户,通常VPS默认帐户为root帐户。

为方便配置网盘的示例展示,这里选择rclone-1.44-linux-amd64版本的Rclone,如果需要不同版本请自行更换参数。

Rclone版本检查页面:https://downloads.rclone.org/

二、配置网盘

1.本地配置

这里我们以Onedrive for business为例,其余网盘根据应用提示进行操作。

执行rclone config命令进行配置

No remotes found - make a new one

n) New remote

s) Set configuration password

q) Quit config

无远端配置,请新建

n)新建

s)设置配置访问密码

q)退出配置

输入n新建

远端网盘命名(配置好后以此命名操作网盘)

输入one作为示范

Type of storage to configure.

Enter a string value. Press Enter for the default ("").

Choose a number from below, or type in your own value

Storage

选择配置的存储类型

输入配置值,回车表示默认

选择以下你需要的存储类型

输入18选择Onedrive作为示范

Microsoft App Client Id

Leave blank normally.

Enter a string value. Press Enter for the default ("").


微软App Client Id

通常留空

输入配置值,回车表示默认

输入回车留空


Microsoft App Client Secret

Leave blank normally.

Enter a string value. Press Enter for the default ("").

微软App Client Secret,同上

输入回车留空

Edit advanced config? (y/n)

y) Yes

n) No

是否进行高级配置

y)是

n)否

输入n否


Remote config

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)否

输入y启动浏览器登陆Onedrive进行授权

输入n否,以无图形界面浏览器的VPS作为示范

2.远端授权

如果使用谷歌网盘等静态授权口令的网盘可以登陆网盘相关界面获取,微软Onedrive采用动态授权口令这里需要我们准备装有图形界面浏览器和Rclone的设备,Linux图形版本同下载安装步骤操作,Windows版本不另作示范。

装有图形界面浏览器和Rclone的设备在终端中执行:

rclone authorize "onedrive"

此时若终端不能调用浏览器,请手动用浏览器打开链接。

浏览器中授权成功后返回终端会生成自动授权码。


复制这两者间的所有内容

<---End paste

3.继续本地配置

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:

这种工作模式你需要一台能装有Rclone和浏览器的设备

在该设备上执行rclone authorize "onedrive"获取授权码

把授权码粘贴在此

粘贴我们复制的授权码


Choose a number from below, or type in an existing value

Your choice

选择以下数值选择Onedive类型

1)OneDrive Personal or Business -Onedrive个人版或者企业版

2)Root Sharepoint site - Sharepoint站点

其余不常用

输入1,以Onedrive for business作为示范


Found 1 drives, please select the one you want to use:

0: OneDrive (business) id=Onedrive ID

Chose drive to use:

找到1个存储驱动器,请选择你需要的

输入0,某些Onedrive会有多个存储驱动器


Found drive 'root' of type 'business', URL:

Is that okay?

y) Yes

n) No

找到存储驱动器类型为企业版,访问链接为:这个链接就是Onedrive映射到Windows本地磁盘的地址

是否正确

输入y


y) Yes this is OK

e) Edit this remote

d) Delete this remote

y/e/d

这里Rclone会报一些网盘的配置参数

y)确定

e)编辑

d)删除

输入y,完成


三、使用命令

复制rclone copy source:sourcepath dest:destpath

移动rclone move source:sourcepath dest:destpath

删除文件rclone delete

删除空目录rclone rmdir

删除内容无视目录非空rclone purge remote:path

列表rclone ls remote:path

同步rclone sync source:path dest:path


示范中配置的Onedrive命名为one:

列出Onedrive的A0目录下的文件内容

rclone ls one:/A0

复制Onedrive的A0目录到本地的/home目录下

rclone copy one:/A0 /home


更多操作命令请访问Rclone官方网站或者GitHub。


四、挂载网盘

复制以下命令到终端或者SSH工具中执行:

yum install fuse -y

apt-get install fuse -y

mkdir /root/1drive

rclone mount one:/ /root/1drive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000


挂载成功检查:

挂载成功执行df -h会在分区中显示挂载的网盘信息。

注意:

这里使用的是示范中命名为one的Onedrive网盘以及挂载到本地的/root/1drive目录下,配置或者需求不同的家友可以手动修改。挂载完成后便可以放弃rclone的命令,进而像本地磁盘那样操作Onerdive中的内容了。

OpenVZ架构的VPS不支持挂载!


挂载命令开机自启动

复制以下命令到终端或者SSH工具中执行(整体复制,一个回车):

cat <<eof /usr/lib/systemd/system/1drive.service

[Unit]

Description=1drive

[Service]

User=root

ExecStart=/usr/bin/rclone mount one:/ /root/1drive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

Restart=on-abort

[Install]

WantedBy=multi-user.target

eof

systemctl daemon-reload

systemctl start 1drive

systemctl enable 1drive

systemctl status 1drive


注意:

这里ExecStart=后面的参数根据自己的配置进行修改,这里仅以示范为例。

五、其他说明

如果我们把Rclone挂载的目录设为Aria2或者CloudTorrent的下载目录,可以看到显示的剩余空间确实是网盘空间(CloudTorrent按照1000进制计算的容量会偏大),但是这样直接把网盘挂载目录作为下载目录的操作会导致下载的缓存文件下载的瞬间就被上传,并不能生成一个完整的下载文件。

CloudTorrent由于应用本身的问题目前只能够手动上传,而Aria2可以利用其配置来设置上传脚本实现下载完成自动上传Onedrive的,就此实现Onedrive的离线下载功能。


Aira2自动上传脚本


#!/bin/bash

GID="$1";

FileNum="$2";

File="$3";

MinSize="5" #限制最低上传大小,默认5k

MaxSize="157286400" #限制最高文件大小(单位k),默认15G

RemoteDIR="/RATS/"; #rclone挂载的本地文件夹,最后面保留/

LocalDIR="/download/"; #Aria2下载目录,最后面保留/


if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi

if [[ "$FileNum" -le '0' ]]; then exit 0; fi

if [[ "$#" != '3' ]]; then exit 0; fi

function LoadFile(){

  IFS_BAK=$IFS

  IFS=$'\n'

  if [[ ! -d "$LocalDIR" ]]; then return; fi

  if [[ -e "$File" ]]; then

    FileLoad="${File/#$LocalDIR}"

    while true

      do

        if [[ "$FileLoad" == '/' ]]; then return; fi

        echo "$FileLoad" |grep -q '/';

        if [[ "$?" == "0" ]]; then

          FileLoad=$(dirname "$FileLoad");

        else

          break;

        fi;

      done;

    if [[ "$FileLoad" == "$LocalDIR" ]]; then return; fi

    EXEC="$(command -v mv)"

    if [[ -z "$EXEC" ]]; then return; fi

    Option=" -f";

    cd "$LocalDIR";

    if [[ -e "$FileLoad" ]]; then

      ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1)

      if [[ -z "$ItemSize" ]]; then return; fi

      if [[ "$ItemSize" -le "$MinSize" ]]; then

        echo -ne "\033[33m$FileLoad \033[0mtoo small to spik.\n";

        return;

      fi

      if [[ "$ItemSize" -ge "$MaxSize" ]]; then

        echo -ne "\033[33m$FileLoad \033[0mtoo large to spik.\n";

        return;

      fi

      eval "${EXEC}${Option}" \'"${FileLoad}"\' "${RemoteDIR}";

      if [[ $? == '0' ]]; then

        rm -rf "$FileLoad";

      fi

    fi

  fi

  IFS=$IFS_BAK

}

LoadFile;

<———以上是脚本内容———

使用:

/root目录新建名为rcloneupload.sh的脚本并编辑为以上内容,授权chmod +x rcloneupload.sh,然后再到Aria2配置文件中加上一行on-download-complete=/root/rcloneupload.sh即可,后面为脚本的路径。最后重启Aria2生效。

依照#后的描述自行根据实际配置进行更改。


MaxSize="157286400" #不要大于这个值,目前Onedrive最大只支持15GB的单文件

RemoteDIR="/RATS/"; #Rclone配置示范中的挂载地址是/root/1drive/

LocalDIR="/download/"; #检查自己Aria2的下载目录


说明:

此脚本并非本人所著且没有经过验证,使用相关的帮助以及原理可以访问脚本作者关于此脚本的说明页面:https://www.moerats.com/archives/482/

对原脚本作者和修改作者萌咖和萌鼠两位大佬表示感谢。

广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,IT之家所有文章均包含本声明。

软媒旗下网站: IT之家 辣品 - 超值导购,优惠券 最会买 - 返利返现优惠券 iPhone之家 Win7之家 Win10之家 Win11之家

软媒旗下软件: 魔方 酷点桌面 Win7优化大师 Win10优化大师 软媒手机APP应用