Rclone挂载网盘到Linux
     分类:杂项     有: 1 条评论

Rclone挂载网盘到Linux

     分类:杂项     有: 1 条评论

申请OneDrive 5TB 网盘(随时可能失效)
免费开放申请 Office 365 A1 帐号 / OneDrive 5TB 网盘:https://www.mrkevin.net/share/2891.html
申请地址:https://www.microsoft.com/zh-cn/education/products/office/default.aspx

简介

Rclone支持挂载的网盘有:Google Drive、 Dropbox 、Google Cloud Storage 、Microsoft One Drive 、Hubic、 Backblaze B2 、Yandex Disk 、Openstack Swift / Rackspace cloud files / Memset Memstore 。更强大的是,Rclone还支持SFTP 、FTP 、HTTP挂载。

Rclone支持挂载的网盘基本上都是国外的,如果有国内的VPS想要使用的话,可以用用SFTP 、FTP 、HTTP方式来挂载,将不同的服务器存储整合到一起。如果有腾讯云和阿里云的用户,可以试试COS-Fuse和OSSFS这两款专门用于腾讯云COS和阿里云OSS存储挂载工具。

安装rclone

yum install fuse
curl https://rclone.org/install.sh | sudo bash

OneDrive 配置(支持商业版)

注意:如果使用Linux等服务器,没有GUI界面,可以下用win、MAC OSX上运行注册步骤生成授权码,再配置到Linux中。
下载地址:https://rclone.org/downloads/ 。下载win版rclone然后解压出来,cmd进入rclone目录,输入以下命令:

./rclone.exe authorize "onedrive"
# 会自动打开浏览器,输入账户、密码授权,回到cmd窗口,copy授权码备用:
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容(包括花括号),后面需要用到
<---End paste

[root@localhost ~]# rclone config   # 开始配置
2019/05/12 23:29:13 NOTICE: Config file "/root/.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    # 新建,n
name> leotestone  # 配置文件名,随便填(可以挂载多个账户,以此来区分,记住这个名称)
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 / Koofr
   \ "koofr"
16 / Local Disk
   \ "local"
17 / Mega
   \ "mega"
18 / Microsoft Azure Blob Storage
   \ "azureblob"
19 / Microsoft OneDrive
   \ "onedrive"
20 / OpenDrive
   \ "opendrive"
21 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
22 / Pcloud
   \ "pcloud"
23 / QingCloud Object Storage
   \ "qingstor"
24 / SSH/SFTP Connection
   \ "sftp"
25 / Webdav
   \ "webdav"
26 / Yandex Disk
   \ "yandex"
27 / http Connection
   \ "http"
Storage> 19   #选择挂载账户
** 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>  # 留空直接回车
--------------------------------------------
# 注意这里!!!留空是共用id,高峰期可能出现请求过多等问题,这里可以修改为自己的id,解决上下传报错的问题
# 提供Google Drive的解决方法:https://www.moerats.com/archives/877/
--------------------------------------------
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  #高级配置?not
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  #自动配置?not
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:  # 把之前win上copy下来的授权码粘贴到这里
result> {"access_token":"XXXXXXX","expiry":"2019-05-13T00:44:22.865526+08:00"}
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=b!GHMk346543454BUQtGjZGepo4rZMulF_pIsUBPv67UkBopNtTJzjXYwK-lwL
Chose drive to use:> 0  #选择发现的磁盘
Found drive 'root' of type 'business', URL: https://2d2-my.sharepoint.com/personal/fa99tisfm_free_host_ac_cn/Documents
Is that okay?
y) Yes
n) No
y/n> Y  #确定使用
--------------------
[leotestone]
type = onedrive
token = {"access_token":"XXXXXXX","expiry":"2019-05-13T00:44:22.865526+08:00"}
drive_id = b!GHMk346543454BUQtGjZGepo4rZMulF_pIsUBPv67UkBopNtTJzjXYwK-lwL
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> Y   # 配置完成
Current remotes:

Name                 Type
====                 ====
leotestone           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

Google Drive配置

流程和上面的一样,注意按提示就行
参考:https://www.moerats.com/archives/481/


挂载

# 命令挂载
rclone mount [leotestone之前记录的配置名]:[testdir网盘中的绝对路径] [/mnt/data_sync本地同步的绝对路径] --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &

leotestone为初始化配置填的账户名,
testdir为OneDrive里的文件夹,
/mnt/data_sync为挂载目录
加&后台运行,该命令只有持续运行才能正常工作

# 卸载
umount /mnt/data_sync
如果卸载不了就用下面的命令
fusermount -qzu /mnt/data_sync

-----------------------------------------------------
# 服务模式(推荐 !!!)

command="mount [leotestone之前记录的配置名]:[testdir网盘中的绝对路径] [/mnt/data_sync本地同步的绝对路径] --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"

# 注意服务名称,多个、多种网盘自行设置名称
cat > /etc/systemd/system/[rclone_onedrive服务名称].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


# 服务管理
systemctl start rclone_onedrive
systemctl enable rclone_onedrive
systemctl stop rclone_onedrive
systemctl status rclone_onedrive

参考资料:
https://www.moerats.com/archives/481/
https://wzfou.com/rclone-cos-fuse-ossfs/
https://spiritx.xyz/503.html

(●゚ω゚●)

captcha

  1. luolibin

    已经支持oss了哦

    Reply