RCLONE是一个可以给VPS挂载Onedrive/Google Drive等国外主流网盘以及FTP等文件存储的软件。
一. 在VPS上安装rclone
1 2 3 4 | yum -y update yum -y install fuse yum -y install wget wget https://rclone.org/install.sh && bash install.sh |
安装成功后会提示 rclone v1.xx has successfully installed.
二.获取onedrive的token
首先需要在本地电脑也下载 rclone ,用于获取 OneDrive 登录 TOKEN 。
下载地址:https://rclone.org/downloads/ 然后解压出来,比如解压到D盘,文件夹命名为rclone,此时按Win+R,然后输入cmd,确定。再输入以下命令:
1 2 | cd /d d:\rclone rclone authorize "onedrive" |
按照下文配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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 <== 这里 个人账号选 p 工作账号选 b 因为我是 OneDrive Business If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth <== 这里会打开网页 登录你的 OneDrive 账号即可 Log in and authorize rclone for access Waiting for code... Got code <== 这里是返回你的 TOKEN Paste the following into your remote machine ---> {"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImlCakwxUmNxemhpeTR mcHhJeGRacW9oTTJZayIsImtpZCI6ImlCakwxUmNxemhpeTRmcHhJeGRacW9oTTJZayJ9.eyJhdWQiOi JodHRwczovL2FwaS5vZmZpY2UuY29tL2Rpc2NvdmVyeS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3 dzLm5ldC8zOWE2Y2E2MS05OGRjLTRkY2MtYjU5Mi1kM2JhYzYxNDkzOTQvIiwiaWF0IjoxNTI1Mjc2OD ... 98JnWA_VvhIUeW98RvBSAA","expiry":"2018-05-03T01:04:55.9347103+08:00"} <---End paste |
我们所需要的就是最下面的那部分的内容 {“access_token”:” …. “expiry”:”2018-05-03T01:04:55.9347103+08:00″}
三.配置VPS端rclone
在VPS中输入以下命令:
1 | rclone config |
按照下文配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n <== 选择 N name> OneDrive <== (这里输入挂在项目的名字) Type of storage to configure. Choose a number from below, or type in your own value 1 / Alias for a existing remote \ "alias" 2 / Amazon Drive \ "amazon cloud drive" 3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio) \ "s3" 4 / Backblaze B2 \ "b2" 5 / Box \ "box" 6 / Cache a remote \ "cache" 7 / Dropbox \ "dropbox" 8 / Encrypt/Decrypt a remote \ "crypt" 9 / FTP Connection \ "ftp" 10 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 11 / Google Drive \ "drive" 12 / Hubic \ "hubic" 13 / Local Disk \ "local" 14 / Mega \ "mega" 15 / Microsoft Azure Blob Storage \ "azureblob" 16 / Microsoft OneDrive \ "onedrive" 17 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 18 / Pcloud \ "pcloud" 19 / QingCloud Object Storage \ "qingstor" 20 / SSH/SFTP Connection \ "sftp" 21 / Webdav \ "webdav" 22 / Yandex Disk \ "yandex" 23 / http Connection \ "http" Storage> 16 <== (这里选择onedrive对应的ID,新版本rclone的支持的网盘更多,onedrive可能不是16。所需要挂在类型的 ID 上面是可以挂在网盘的列表) Microsoft App Client Id - leave blank normally. client_id> <== (回车留空) Microsoft App Client Secret - leave blank normally. client_secret> <== (回车留空) Remote config 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 <== (我的账号是 OneDrive Business 账号所以选择 b) 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 <== (这里选择 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":"","expiry":""} <== (这里贴入刚才获取TOKEN) -------------------- [OneDrive] type = onedrive client_id = client_secret = token = {"access_token":"","expiry":"2018-05-02T22:56:29.794396289-04:00"} -------------------- y) Yes this is OK e) Edit this remote d) Delete this remote y/e/d> y Current remotes: Name Type ==== ==== OneDrive 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 |
四.挂载到磁盘并配置自启动
1.下载RCLOAD自启动挂载脚本:
1 2 | wget https://resource.imyrs.cn/bash/rcloned vi rcloned |
2.修改RCLOAD自启动脚本关联目录
把打开的文件里的这些信息修改下,然后保存。
1 2 3 | NAME="" #rclone name名,就是在第三步配置rclone时输入的Name REMOTE='' #远程文件夹,OneDrive 网盘里的挂载的一个文件夹,填 / 就是根目录 LOCAL='' #挂载地址,VPS本地挂载目录,比如 /od ,就是挂载到VPS的 /od 目录 |
3.设置RCLOAD自动启动
1 2 3 4 | mv rcloned /etc/init.d/rcloned chmod +x /etc/init.d/rcloned chkconfig rcloned on bash /etc/init.d/rcloned start |
PS:RCLOAD的启动停止命令
1 2 | bash /etc/init.d/rcloned start bash /etc/init.d/rcloned stop |
PS:查看挂载磁盘
1 | df -h |
大功告成