分类
小工具

扩充自己服务器的硬盘——使用rclone挂载网络硬盘

有时候我们需要一个有大硬盘的服务器,但是条件不允许。那么我需要这么多存储空间怎么办?使用rclone可以挂载20多种网盘为本地分区,你可以在上面存movie,搭网站甚至把docker迁移上去。

这里我们以Onedrive为例。我注册的是个人版的Onedrive,只有5gb的空间,不过也够用了。有兴趣的可以研究教育版。

额外需要的材料:Windows电脑一台(当然任何有图形浏览器的电脑皆可)

首先我们在官网上下载windows版的rclone,解压,用cmd打开这个目录。然后输入:

在跳出的浏览器窗口中登录你的microsoft账户,看到网页上的Success即可把浏览器关掉。查看cmd窗口,应该如图所示:

rclone authorize "onedrive"

把code复制过来,包括两个花括号。打开ssh,下载rclone linux版并解压,rclone可执行程序放到/usr/bin下,在root环境下执行配置:

root@localhost:/home/ubuntu# rclone config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
#新建一个配置
name> dav
#名字,可以随便取
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"
 ……省略数行……
22 / Microsoft OneDrive
   \ "onedrive"
……依旧省略数行……
Storage> 22
#存储类型,这里选择22 Onedrive
** See help for onedrive backend at: https://rclone.org/onedrive/ **

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> 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> n
#我们已经有code了,填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"
Then paste the result below:
result> *****
#把那一长串东西粘贴过来
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
#个人版的,填1
Found 1 drives, please select the one you want to use:
0:  (personal) id=*****
Chose drive to use:> 0
#第几号驱动器,按需填写,这里选择0
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=07aecea8e553586e
Is that okay?
y) Yes
n) No
y/n> y
#填y确认
2020/01/27 01:45:09 ERROR : Failed saving config "drive_id" = "*****" in section "dav" of the config file: section 'dav' not found
2020/01/27 01:45:09 ERROR : Failed saving config "drive_type" = "personal" in section "dav" of the config file: section 'dav' not found
--------------------
[dav]
type = onedrive
token = "******"
drive_id = ******
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
#填y保存
Current remotes:

Name                 Type
====                 ====
dav                  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
#退出
root@localhost:/home/ubuntu#

这样我们就配置好了。要启动,可以开个screen,或在代码后加一个&放在后台运行。不过我个人建议开screen,毕竟可看log。代码如下(在root下执行):

rclone mount dav: /dav --allow-other

解释:dav: 挂载的驱动器名字,前面取的,后面加一个冒号表示挂载驱动器根目录;/dav 挂载的本地目录;–allow-other 允许其他用户读写。

这样之后退出screen,执行df -h,看看/dav下是不是多了5个GB?

当然,如果你能找到更大的webdav盘或ftp,也可以在这里挂载!不过这个盘是基于网速的,有时读写性能不会太好,建议不要存放数据库。


蜜视广告:【苹果/安卓APP】蜜视交友 (真人一对一视频交友)

发表评论

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