使用使用rclone挂载OneDrive到服务器

老王混迹网络这么多年,因为各种各样的原因使用过不少服务器(VPS),从国内到国外从早期的服务器合租网到现在的阿里云,当然国外的樱花、Vultr、狗爹也用过不少。

但是都有各种各样的不同缺点(主要是钱没到位),国内的限制带宽不限制流量,国外的限制流量不限制带宽(其实也限制,只是不严格),除此之外,硬盘空间也是个大问题,早期的VPS还好,偶尔有运营商给出便宜点(5-10$/月)的1T或者500G的HDD,大家基本上都是一哄而上抢光,现在的VPS一言难尽啊,基本上都是20-50G的空间了。

那么怎么解决这个问题,运营商开始卖其他的,比如阿里云的OSS,NSA;腾讯、百度也有类似的产品。

但是我们如果因为一些开飞机等需求购买的国外VPS又没有单独的磁盘可购买,怎么办呢?挂载阿里的OSS去交磁盘和流量费?

老王这种牛(qiong)人才不想呢,于是百度谷歌搜了一通,发现一个好东西,rclone!可以挂载N多的网盘作为本地磁盘使用,现在已经支持了

1 / 1Fichier

2 / Alias for an existing remote

3 / Amazon Drive

4 / Amazon S3 Compliant Storage Provider

5 / Backblaze B2

6 / Box

7 / Cache a remote

8 / Citrix Sharefile

9 / Dropbox

10 / Encrypt/Decrypt a remote

11 / FTP Connection

12 / Google Cloud Storage (this is not Google Drive)

13 / Google Drive

14 / Google Photos

15 / Hubic

16 / JottaCloud

17 / Koofr

18 / Local Disk

19 / Mail.ru Cloud

20 / Mega

21 / Microsoft Azure Blob Storage

22 / Microsoft OneDrive

23 / OpenDrive

24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)

25 / Pcloud

26 / Put.io

27 / QingCloud Object Storage

28 / SSH/SFTP Connection

29 / Transparently chunk/split large files

30 / Union merges the contents of several remotes

31 / Webdav

32 / Yandex Disk

33 / http Connection

34 / premiumize.me

软件优缺点

优点

1、 支持众多网络磁盘

2、 操作简单

3、 支持多个平台Windows、Linux(x86、x64、arm)等等

4、 多种安装方式:源码包、安装包等

缺点

1、 操作稍微复杂,如果是远程Linux你还需要一台Windows

2、 Linux系统的虚拟机需要支持fuse才行,也就是说绝大部分openvz不能用了。

判断系统是否支持

如果你购买vps时候已经明确购买的是KVM架构的,那么这一段你可以跳过去了,因为你肯定是支持的。

我们登录系统,输入“ls /dev/fuse”,如果返回的是下图,显示已经找到,那么是可以使用的。

如果系统返回的是下图,那么你需要跟厂商的客户工单沟通下了。

当然沟通的结果可能是我这样的,字里行间透漏出几个大字“穷逼买了openvz不行,你得买KVM架构的去”

当然了,如果你的客服给你开通了fuse的内核,那么太棒了,继续搞下。

安装rclone软件

我们以centos7和onedrive为例讲,其他Linux类似

既然我们这里讲的是挂载onedrive(我真不是可着微软的羊毛使劲撸,只是微软的撸起来顺手……),那么首先我们需要注册一个onedrive,怎么注册一个5T的onedrive呢?看我前面的文章。

安装软件,登录你的服务器,在命令行一次输入下面的内容,输入完后敲回车运行(#开头的文字不要输入)

yum -y update#更新系统yum -y install vim fuse#安装本次需要的软件wget https://downloads.rclone.org/rclone-current-linux-amd64.rpm#下载rclone安装包,其他Linux网页打开找对应的包rpm -ivh rclone-current-linux-amd64.rpm#安装rclone到系统到这里,我们已经安装好软件了。
配置rclone软件

继续在命令行输入

rclone config

系统会提示现在没有远程连接,问你是新建n/设置配置密码s/退出q;输入n新建一个远程,然后输入一个连接名字(随意),在接下来会让你选择网络硬盘,这里每个版本不一样,记得输入Microsoft OneDrive前面对应的序号就行。

rclone configNo remotes found – make a new onen) New remotes) Set configuration passwordq) Quit confign/s/q> nname> laowangType of storage to configure.Enter a string value. Press Enter for the default (“”).Choose a number from below, or type in your own value 1 / 1Fichier “fichier” 2 / Alias for an existing remote “alias” 3 / Amazon Drive “amazon cloud drive” 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc) “s3” 5 / Backblaze B2 “b2” 6 / Box “box” 7 / Cache a remote “cache” 8 / Citrix Sharefile “sharefile” 9 / Dropbox “dropbox”10 / Encrypt/Decrypt a remote “crypt”11 / FTP Connection “ftp”12 / Google Cloud Storage (this is not Google Drive) “google cloud storage”13 / Google Drive “drive”14 / Google Photos “google photos”15 / Hubic “hubic”16 / JottaCloud “jottacloud”17 / Koofr “koofr”18 / Local Disk “local”19 / Mail.ru Cloud “mailru”20 / Mega “mega”21 / Microsoft Azure Blob Storage “azureblob”22 / Microsoft OneDrive “onedrive”23 / OpenDrive “opendrive”24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) “swift”25 / Pcloud “pcloud”26 / Put.io “putio”27 / QingCloud Object Storage “qingstor”28 / SSH/SFTP Connection “sftp”29 / Transparently chunk/split large files “chunker”30 / Union merges the contents of several remotes “union”31 / Webdav “webdav”32 / Yandex Disk “yandex”33 / http Connection “http”34 / premiumize.me “premiumizeme”Storage> 22

接下来会提示输入client_id和client_secret,我们都不需要输入,直接回车跳过,在Edit advanced config? (y/n)选择y进行进阶设置。后面的设置磁盘块大小(drive_id)也可以直接跳过,drive_id也直接跳过,drive_type这里可以根据你的onedrive类型选择输入personal | business | documentLibrary,当然也可以跳过,下一步跳过OneNote文件(expose_onenote_files),直接回车跳过。

Microsoft App Client IdLeave blank normally.Enter a string value. Press Enter for the default (“”).client_id> Microsoft App Client SecretLeave blank normally.Enter a string value. Press Enter for the default (“”).client_secret> Edit advanced config? (y/n)y) Yesn) Noy/n> y/n> yChunk size to upload files with – must be multiple of 320k (327,680 bytes).Above this size files will be chunked – must be multiple of 320k (327,680 bytes). Notethat the chunks will be buffered into memory.Enter a size with suffix k,M,G,T. Press Enter for the default (“10M”).chunk_size> The ID of the drive to useEnter a string value. Press Enter for the default (“”).drive_id> The type of the drive ( personal | business | documentLibrary )Enter a string value. Press Enter for the default (“”).drive_type> Set to make OneNote files show up in directory listings.By default rclone will hide OneNote files in directory listings becauseoperations like “Open” and “Update” won’t work on them. But thisbehaviour may also prevent you from deleting them. If you want todelete OneNote files or otherwise want them to show up in directorylisting, set this option.Enter a boolean value (true or false). Press Enter for the default (“false”).expose_onenote_files> y/n> nFor this to work, you will need rclone available on a machine that has a web browser available.Execute the following on your machine (same rclone version recommended) :rclone authorize “onedrive” “x1b[A” “qtyfaBBYA403=unZUP40~_#”Then paste the result below:result>

然后我们需要输入授权,这里我们因为是 远程shell没法使用浏览器,这里选择n,我们从Windows操作

Remote configMake sure your Redirect URL is set to “http://localhost:53682/” in your custom config.Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machiney) Yesn) Noy/n> nFor this to work, you will need rclone available on a machine that has a web browser available.Execute the following on your machine (same rclone version recommended) :rclone authorize “onedrive” “x1b[A” “qtyfaBBYA403=unZUP40~_#”Then paste the result below:result>

好像到这里一直是跳过啊,没关系,下面开始需要你在Windows上操作了。

Windows获取授权

在windows上下载https://downloads.rclone.org/rclone-current-windows-amd64.zip,然后解压到任意目录中,然后打开解压后的目录,在目录空白处按住shift点右键,选择在此次打开cmd命令行。

然后在命令行中输入

rclone.exe config

然后按照前面的配置全部重新输入一遍 ,一直到前面将的最后一步操作,不要输入n,输入y,因为我们有浏览器啦(自豪),

系统会自动打开我们的默认浏览器,打开onedrive登录页面,输入账号和密码。

 

然后同意授权许可

 

然后网页会提示你回rclone去看结果,已经返回授权access了。

 

我们返回刚刚的命令行继续操作,首先输入1,确认我们刚刚授权的是OneDrive,接下来的一步会提示选择一个用户,直接输入0啊,继续提示问你这个配置是否正确,输入y继续。

Log in and authorize rclone for accessWaiting for code…Got codeChoose a number from below, or type in an existing value 1 / OneDrive Personal or Business “onedrive” 2 / Root Sharepoint site “sharepoint” 3 / Type in driveID “driveid” 4 / Type in SiteID “siteid” 5 / Search a Sharepoint site “search”Your choice> 1Found 1 drives, please select the one you want to use:0: OneDrive (business) id=b!******************Chose drive to use:> 0Found drive ‘root’ of type ‘business’, URL: https://***-my.sharepoint.com/personal/*****_*****_onmicrosoft_com/DocumentsIs that okay?y) Yesn) Noy/n> y

然后会出现一大堆内容,这里分为几个部分,首先是告诉你这个是onedrive,然后是token,这个是最重要的,继续是id和版本,我们需要复制token =后面一直到drive_id(不包含drive_id)前面的所有内容。

About the Author

发表评论

邮箱地址不会被公开。 必填项已用*标注

You may also like these