爱生活、爱运动、爱分享、爱折腾、爱编程。

在服务器上挂载OneDrive网盘进行扩容

通过本文可以学习到如何通过 rclone 挂载 OneDrive 为 服务器 增加磁盘空间。

最近迷上了PT资源下载,因服务器内存不够 想起一位大佬给我开了Office账号 OneDrive有5T,于是就试试挂载网盘。

看到有大佬发布一个 OneIndex 程序,可以通过 API 访问 OneDrive for Business 网盘内容并渲染成网页,将 OneDrive 网盘作为图床等直链。>>OneIndex Github

通过 rclone 挂载 OneDrive for Business 为 Linux 增加磁盘空间。这样就可以一些网站到 OneDrive 网盘,然后通过 OneIndex 直接访问在线播放。

在使用 rclone 挂载磁盘的时候,遇到了一些问题,本文主要目的是通过网上教程,(在Debian/Ubuntu上使用rclone挂载OneDrive网盘Rclone: 更新支持 Onedrive for Business(测试教育版也可用)
并根据实际情况,对遇到的问题进行改进。

获取Token

正式配置前,需要通过可以使用浏览器的电脑进行授权

由于Linux没有浏览器页面 所有需要自己电脑进行授权,windows 服务器可直接在服务器上安装

网上的教程大多是通过 Windows 系统来获取授权,但是本人使用 MacOS,所以这一步操作仅适用MacOS。

Windows可以通过访问Rclone downloads,下载适合自己电脑的版本并解压,运行命令是一样的

MacOS 通过 Termial 下载

cd && curl -O https://downloads.rclone.org/rclone-current-osx-amd64.zip

解压、运行

unzip -a rclone-current-osx-amd64.zip && cd rclone-*-osx-amd64
./rclone authorize "onedrive"

获取Token

Choose OneDrive account type?  
* Say b for a OneDrive business account  
* Say p for a personal OneDrive account
b) Business
p) Personal
b/p> b  #这里选择Business版
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth  #接下来会弹出浏览器,要求你登录账号进行授权 Log in and authorize rclone for access Waiting for code... Got code Paste the following into your remote machine ---> {"access_token":"xxxx"}  #复制{xx}整个内容,**包括大括号{}**,后面需要用到 <---End paste

服务器-开始配置

下载 RCLONE

下载并解压

curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip unzip rclone-current-linux-amd64.zip cd rclone-*-linux-amd64

复制文件

sudo cp rclone /usr/bin/ sudo chown root:root /usr/bin/rclone sudo chmod 755 /usr/bin/rclone

安装程序包

sudo mkdir -p /usr/local/share/man/man1 sudo cp rclone.1 /usr/local/share/man/man1/ sudo mandb

初始化配置

rclone config

会出现以下信息:

n) New remote 
s) Set configuration password
q) Quit config
n/s/q> n #创建一个
name> Mydrn #你的取名 后面会用到
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 / A stackable unification remote, which can appear to merge the contents of several remotes
\ "union"
2 / Alias for a 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 / Dropbox
\ "dropbox"
9 / Encrypt/Decrypt a remote
\ "crypt"
10 / FTP Connection
\ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
12 / Google Drive
\ "drive"
13 / Hubic
\ "hubic"
14 / JottaCloud
\ "jottacloud"
15 / Local Disk
\ "local"
16 / Mega
\ "mega"
17 / Microsoft Azure Blob Storage
\ "azureblob"
18 / Microsoft OneDrive
\ "onedrive"
19 / OpenDrive
\ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
21 / Pcloud
\ "pcloud"
22 / QingCloud Object Storage
\ "qingstor"
23 / SSH/SFTP Connection
\ "sftp"
24 / Webdav
\ "webdav"
25 / Yandex Disk
\ "yandex"
26 / http Connection
\ "http"
Storage> 18 #输入 Microsoft 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> y #可选n 配置就采取默认值
Chunk size to upload files with - must be multiple of 320k.
Above this size files will be chunked - must be multiple of 320k. 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> 640k #内存块大小
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> business
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>
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
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:
result> {"access_token":""} #粘贴之前在客户端授权的内容,包括大括号一起粘贴进去
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=xxxxxxx
Chose drive to use:> 0 #选择你创建的磁盘
Found drive 'root' of type 'business', URL: https://09l-my.sharepoint.com/personal/pssion_09l_onmicrosoft_com/Documents
Is that okay?
y) Yes
n) No
y/n> y

[Mydrn]
type = onedrive
chunk_size = 640k
drive_type = business
token = {"access_token":""}
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y #检查并确定配置
Current remotes:

Name Type
==== ====
Mydrn 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
#后台运行,使用这个命令
nohup rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &1&
#注意
DriveName 是前面配置时输入的名字;
Folder 是 OneDrive 文件夹目录;
LocalFolder是服务器的文件夹路径;
如出现 错误 
Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

#安装fuse
yum install fuse

挂载成功后,输入df -h命令查看即可

有点激动

进宝塔面板再看一下 收工

赞(3)
(转载本站文章请注明作者和出处 ,请勿用于任何商业用途)Mydrn Blog » 在服务器上挂载OneDrive网盘进行扩容

评论 抢沙发

评论前必须登录!