百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

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

nanshan 2024-10-22 12:59 21 浏览 0 评论

综述

此文又臭又长,如果不是实在闲的蛋疼/刚需建议还是跳过吧

老王混迹网络这么多年,因为各种各样的原因使用过不少服务器(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 config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> laowang
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
 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 Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> 

Edit advanced config? (y/n)
y) Yes
n) No
y/n> y/n> y
Chunk 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). Note
that 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 use
Enter 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 because
operations like "Open" and "Update" won't work on them. But this
behaviour may also prevent you from deleting them. If you want to
delete OneNote files or otherwise want them to show up in directory
listing, set this option.
Enter a boolean value (true or false). Press Enter for the default ("false").
expose_onenote_files> 
 y/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 (same rclone version recommended) :
	rclone authorize "onedrive" "\x1b[A" "qtyfaBBYA403=unZUP40~_#"
Then paste the result below:
result> 

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

Remote config
Make 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 machine
y) Yes
n) No
y/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 (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 access
Waiting for code...
Got code
Choose 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> 1
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!******************
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: https://***-my.sharepoint.com/personal/*****_*****_onmicrosoft_com/Documents
Is that okay?
y) Yes
n) No
y/n> y

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

--------------------
[laowang]
type = onedrive
token = {"access_token":"*********","token_type":"Bearer","refresh_token":"******","expiry":"2019-11-10T15:12:28.3942627+08:00"}
drive_id = b!*********************
drive_type = business
--------------------

复制图片中红色方块之间的内容

返回Linux继续操作

然后我们返回Linux继续操作,把这一串东西粘贴上去,回车。

首先输入1,确认我们刚刚授权的是OneDrive,接下来的一步会提示选择一个用户,直接输入0啊,继续提示问你这个配置是否正确,输入y继续。(好像又重复了)。

到了这里,已经配置完成了,输入q退出就可以了。

--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name Type
==== ====
laowang 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

测试挂载

完成上面的操作,所有网络硬盘有关的配置已经完成了,接下来我们需要挂载到服务器使用了。

首先创建一个目录作为挂载点,然后挂载过去,比如我创建的目录就是/data/rclone,你也可以根据自己情况修改。

简单说一下挂载命令:rclone mount laowang:rclone /data/rclone其实需要修改的就是这部分,laowang是刚刚的远程连接名称,rclone是网盘里的文件夹,/data/rclone是服务器上的目录。

mkdir -p /data/rclone
rclone mount laowang:rclone /data/rclone --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

如果你看到了下面的提示,请返回看我判断系统是否支持那一段。如果系统停到了这里没有任何回复,那么恭喜你,完成挂载了。

2019/11/10 14:32:13 mount helper error: fusermount: fuse device not found, try 'modprobe fuse' first
2019/11/10 14:32:13 Fatal error: failed to mount FUSE fs: fusermount: exit status 1

这时候,我们新开一个终端,登录到服务器,输入df-h,看这里,已经挂载了1T到/data/laowang目录下了

[root@atlanta ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 482M 0 482M 0% /dev
tmpfs 493M 0 493M 0% /dev/shm
tmpfs 493M 6.7M 486M 2% /run
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/vda1 25G 2.3G 22G 10% /
tmpfs 99M 0 99M 0% /run/user/0
laowang:rclone 1.0T 0 1.0T 0% /data/laowang

试一下建一个文件,已经可以使用了,虽然速度不是很快。

[root@atlanta ~]# touch /data/laowang/test.txt
[root@atlanta ~]# ls /data/laowang/
test.txt

注册rclone为系统服务并自启动

不说了,开搞,按照下面步骤做就行了

wget https://www.moerats.com/usr/shell/rcloned && vim rcloned
#感谢网友提供的脚本,这是我从别人博客找到的脚本^_^
#NAME="" #rclone name名,及配置时输入的Name
#REMOTE='' #远程文件夹,OneDrive网盘里的挂载的一个文件夹
#LOCAL='' #挂载地址,VPS本地挂载目录
mv rcloned /etc/init.d/rcloned
#复制脚本到 /etc/init.d/
chmod +x /etc/init.d/rcloned
#给脚本运行权限
chmod 755 /etc/init.d/rcloned
#给脚本用户权限
service rcloned start
[信息] rclone 启动成功 !
#启动rcloned服务
service rcloned stop
[信息] rclone 停止成功 !
#停止rcloned服务
service rcloned restart
[信息] rclone 停止成功 !
[信息] rclone 启动成功 !
#重启rcloned服务
chkconfig rcloned on
#设置rcloned服务自启动
chkconfig --list rcloned
#查看rcloned服务状态,如果返回的是下面一行的内容,说明配置没问题了
rcloned 	0:off	1:off	2:on	3:on	4:on	5:on	6:off

然后你可以重启一下服务器测试一下配置了。

总结

远程挂载onedrive到服务器,的确是解决磁盘大小不够的问题,但是这也只是能做一个简单的应用,毕竟读写速度和响应时间都很差,作为备份目录也算是一个好办法了吧。

相关推荐

F5负载均衡器如何通过irules实现应用的灵活转发?

F5是非常强大的商业负载均衡器。除了处理性能强劲,以及高稳定性之外,F5还可以通过irules编写强大灵活的转发规则,实现web业务的灵活应用。irules是基于TCL语法的,每个iRules必须包含...

映射域名到NAS

前面介绍已经将域名映射到家庭路由器上,现在只需要在路由器上设置一下端口转发即可。假设NAS在内网的IP是192.168.1.100,NAS管理端口2000.你的域名是www.xxx.com,配置外部端...

转发(Forward)和重定向(Redirect)的区别

转发是服务器行为,重定向是客户端行为。转发(Forward)通过RequestDispatcher对象的forward(HttpServletRequestrequest,HttpServletRe...

SpringBoot应用中使用拦截器实现路由转发

1、背景项目中有一个SpringBoot开发的微服务,经过业务多年的演进,代码已经累积到令人恐怖的规模,亟需重构,将之拆解成多个微服务。该微服务的接口庞大,调用关系非常复杂,且实施重构的人员大部分不是...

公司想搭建个网站,网站如何进行域名解析?

域名解析是将域名指向网站空间IP,让人们通过注册的域名可以方便地访问到网站的一种服务。IP地址是网络上标识站点的数字地址,为方便记忆,采用域名来代替IP地址标识站点地址。域名解析就是域名到IP地址的转...

域名和IP地址什么关系?如何通过域名解析IP?

一般情况下,访客通过域名和IP地址都能访问到网站,那么两者之间有什么关系吗?本文中科三方针对域名和IP地址的关系和区别,以及如何实现域名与IP的绑定做下介绍。域名与IP地址之间的关系IP地址是计算机的...

分享网站域名301重定向的知识

网站域名做301重定向操作时,一般需要由专业的技术来协助完成,如果用户自己在维护,可以按照相应的说明进行操作。好了,下面说说重点,域名301重定向的操作步骤。首先,根据HTTP协议,在客户端向服务器发...

NAS外网到底安全吗?一文看懂HTTP/HTTPS和SSL证书

本内容来源于@什么值得买APP,观点仅代表作者本人|作者:可爱的小cherry搭好了NAS,但是不懂做好网络加密,那么隐私泄露也会随时发生!大家好,这里是Cherry,喜爱折腾、玩数码,热衷于分享数...

ForwardEmail免费、开源、加密的邮件转发服务

ForwardEmail是一款免费、加密和开源的邮件转发服务,设置简单只需4步即可正常使用,通过测试来看也要比ImprovMX好得多,转发近乎秒到且未进入垃圾箱(仅以Mailbox.org发送、Out...

使用CloudFlare进行域名重定向

当网站变更域名的时候,经常会使用域名重定向的方式,将老域名指向到新域名,这通常叫做:URL转发(URLFORWARDING),善于使用URL转发,对SEO来说非常有用,因为用这种方式能明确告知搜索引...

要将端口5002和5003通过Nginx代理到一个域名上的操作笔记

要将端口5002和5003通过Nginx代理到域名www.4rvi.cn的不同路径下,请按照以下步骤配置Nginx:步骤说明创建或编辑Nginx配置文件通常配置文件位于/etc/nginx/sites...

SEO浅谈:网站域名重定向的三种方式

在大多数情况下,我们输入网站访问网站的时候,很难发现www.***.com和***.com的区别,因为一般的网站主,都会把这两个域名指向到同一网站。但是对于网站运营和优化来说,www.***.com和...

花生壳出现诊断域名与转发服务器ip不一致的解决办法

出现诊断域名与转发服务器ip不一致您可以:1、更改客户端所处主机的drs为223.5.5.5备用dns为119.29.29.29;2、在windows上进入命令提示符输入ipconfig/flush...

涨知识了!带你认识什么是域名

1、什么是域名从技术角度来看,域名是在Internet上解决IP地址对应的一种方法。一个完整的域名由两个或两个以上部分组成,各部分之间用英文的句号“.”来分隔。如“abc.com”。其中“com”称...

域名被跳转到其他网站是怎么回事

当你输入域名时被跳转到另一个网站,这可能是由几种原因造成的:一、域名可能配置了域名转发服务。无论何时有人访问域名,比如.com、.top等,都会自动重定向到另一个指定的URL,这通常是在域名注册商设...

取消回复欢迎 发表评论: