配置成功如下图
使用rclone挂载onedrive扩容服务器空间
手里的小鸡硬盘太小不够用怎么办?如果你有一个 onedrive 大容量账户如教育版或者企业版 5TB 账户(账户的 onedrive 空间可达 25TB),就可以通过 rclone 将 onedrive 以磁盘方式挂载在服务器上,这样小鸡也可以当大盘鸡使。再也不用担心服务器硬盘不够用了。以下内容在 Ubuntu18.04LTS 环境中使用
获取授权密钥(后面会用到)
在本地安装 rclone 客户端-Win
在 rclone 官网https://rclone.org/downloads/下载适用于 Windows 的最新版客户端,解压到磁盘当中,将文件夹重命名为rc
(方便以下操作。。)。按住键盘上win+R
输入powershell
打开命令行,执行以下命令。
cd d:rc #如果解压在其他盘只需相应替换盘符即可.\rclone authorize "onedrive"
此时会弹出一个验证页面,在此登陆你的 onedrive 账户完成授权即可在 powershell 中获取密钥,如下
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)
curl https://rclone.org/install.sh | sudo bash #rclone on Linux/macOS/BSD systems
配置 rclone
初始化 rclone,执行
rclone config
按照如下提示进行,此步骤的一些步骤会因为 rclone 版本更新出现不同,但总体安装过程和选项相似,请依据现在安装的版本进行。
在获取密钥匙务必确保本地客户端和服务器上的 rclone 版本一致,否则可能出现错误
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 onen) 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 OKe) 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
$ mkdir /data/rc #这里的目录路径自行决定
输入以下命令挂载远程硬盘
$ rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &&
挂载命令中DriveName
为配置时填的name
,Folder
为onedrive
里的文件夹,LocalFolder
为刚刚创建的本地文件夹。例如
$ rclone mount rc:/ /data/rc --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &&
挂载完成后可使用df -h
命令查看磁盘情况
$ 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/efirc:upload 5.0T 90G 4.9T 2% /data/rc tmpfs 99M 0 99M 0% /run/user/1001
卸载磁盘
fusermount -qzu LocalFolder #如fusermount -qzu /data/rc
设置开机自启
添加到 systemd 中
使用 systemctl 管理应用程序
#以下命令如上一步中的挂载命令 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
systemctl start rclone
设置 rclone 开机自启
systemctl enable rclone
重新启动 rclone
systemctl restart rclone
停止 rclone
systemctl stop rclone
查看 rclone
systemctl status rclone
原文链接:https://cloud.tencent.com/developer/article/1936298