前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用rclone挂载onedrive扩容服务器空间

使用rclone挂载onedrive扩容服务器空间

作者头像
用户1316967
发布2022-01-18 17:18:56
9.3K0
发布2022-01-18 17:18:56
举报
文章被收录于专栏:IF奇思社IF奇思社

手里的小鸡硬盘太小不够用怎么办?如果你有一个 onedrive 大容量账户如教育版或者企业版 5TB 账户(账户的 onedrive 空间可达 25TB),就可以通过 rclone 将 onedrive 以磁盘方式挂载在服务器上,这样小鸡也可以当大盘鸡使。再也不用担心服务器硬盘不够用了。以下内容在 Ubuntu18.04LTS 环境中使用

获取授权密钥(后面会用到)

在本地安装 rclone 客户端-Win

在 rclone 官网https://rclone.org/downloads/下载适用于 Windows 的最新版客户端,解压到磁盘当中,将文件夹重命名为rc(方便以下操作。。)。按住键盘上win+R输入powershell打开命令行,执行以下命令。

代码语言:javascript
复制
cd d:rc                             #如果解压在其他盘只需相应替换盘符即可
.\rclone authorize "onedrive"

此时会弹出一个验证页面,在此登陆你的 onedrive 账户完成授权即可在 powershell 中获取密钥,如下

代码语言:javascript
复制
PS D:\rc> .\rclone authorize "onedrive"
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=xxxx
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"auth","expiry":"2020-01-28T21:59:50.7394539+08:00"}  #完整复制此步给出的密钥包括{---}之间的所有内容。
<---End paste

在服务器上配置 rclone

安装 rclone (ubuntu18.04LTS)

代码语言:javascript
复制
curl https://rclone.org/install.sh | sudo bash   #rclone on Linux/macOS/BSD systems

配置 rclone

初始化 rclone,执行

代码语言:javascript
复制
rclone config

按照如下提示进行,此步骤的一些步骤会因为 rclone 版本更新出现不同,但总体安装过程和选项相似,请依据现在安装的版本进行。

在获取密钥匙务必确保本地客户端和服务器上的 rclone 版本一致,否则可能出现错误

代码语言:javascript
复制
2020/01/28 21:12:30 NOTICE: Config file "/home/ubuntu/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> rc     #输入一个名称
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> onedrive     #输入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
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 (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> onedrive     #输入1或者onedrive,输入想要链接的类型
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=
Chose drive to use:> 0     #选择想要链接的磁盘id
Found drive 'root' of type 'business', URL:
Is that okay?
y) Yes
n) No
y/n> y
--------------------
[rc]
type = onedrive
token = {"access_token":"auth","expiry":"2020-01-28T22:15:19.3495203+08:00"}
drive_id =
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y      #确认配置
Current remotes:

Name                 Type
====                 ====
rc                   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     #q退出,配置完成

以磁盘方式挂载

挂载配置

在本地新建一个文件夹作为要挂载的本地目录,此处配置的为LocalFolder

代码语言:javascript
复制
$ mkdir /data/rc     #这里的目录路径自行决定

输入以下命令挂载远程硬盘

代码语言:javascript
复制
$ rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &&

挂载命令中DriveName为配置时填的nameFolderonedrive里的文件夹,LocalFolder为刚刚创建的本地文件夹。例如

代码语言:javascript
复制
$ rclone mount rc:/ /data/rc --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &&

挂载完成后可使用df -h命令查看磁盘情况

代码语言:javascript
复制
$ df -h
Filesystem      Size  Used Avail Use%   Mounted on
udev            472M     0  472M   0%   /dev
tmpfs            99M  976K   98M   1%   /run
/dev/sda1       128G  16.3G 111.7G 13% /
tmpfs           491M     0  491M   0%   /dev/shm
tmpfs           5.0M     0  5.0M   0%   /run/lock
tmpfs           491M     0  491M   0%   /sys/fs/cgroup
/dev/loop1       90M   90M     0 100%   /snap/core/8268
/dev/loop0       90M   90M     0 100%   /snap/core/8213
/dev/sda15      105M  3.6M  101M   4%   /boot/efi
rc:upload       5.0T   90G  4.9T   2%   /data/rc
tmpfs            99M     0   99M   0%   /run/user/1001

卸载磁盘

代码语言:javascript
复制
fusermount -qzu LocalFolder      #如fusermount -qzu /data/rc

设置开机自启

添加到 systemd 中

使用 systemctl 管理应用程序

代码语言:javascript
复制
#以下命令如上一步中的挂载命令
command="mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

开始配置

启动 rclone

代码语言:javascript
复制
systemctl start rclone

设置 rclone 开机自启

代码语言:javascript
复制
systemctl enable rclone

重新启动 rclone

代码语言:javascript
复制
systemctl restart rclone

停止 rclone

代码语言:javascript
复制
systemctl stop rclone

查看 rclone

代码语言:javascript
复制
systemctl status rclone
本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-01-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 获取授权密钥(后面会用到)
    • 在本地安装 rclone 客户端-Win
    • 在服务器上配置 rclone
      • 安装 rclone (ubuntu18.04LTS)
        • 配置 rclone
        • 以磁盘方式挂载
          • 挂载配置
            • 卸载磁盘
            • 设置开机自启
              • 添加到 systemd 中
                • 开始配置
                相关产品与服务
                对象存储
                对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
                http://www.vxiaotou.com