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存储挂载工具。

注意:如果使用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

安装

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

配置账户

[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>  # 留空直接回车
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

使用

# 挂载
rclone mount leotestone:testdir /mnt/ --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 &

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

# 卸载
fusermount -qzu /mnt/

开机启动

# 编辑文件,写入以下内容(注意修改自己的配置)
vim /etc/init.d/rcloned

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
NAME_BIN="rclone"
### BEGIN INIT INFO
# Provides:          rclone
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start rclone at boot time
# Description:       Enable rclone by daemon.
### END INIT INFO

NAME="leotestone"       # leotestone为初始化配置填的账户名
REMOTE='testdir'        # OneDrive里的远程文件夹名
LOCAL='/mnt/'  # 挂载路径

Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
RETVAL=0

check_running(){
   PID="$(ps -C $NAME_BIN -o pid= |head -n1 |grep -o '[0-9]\{1,\}')"
   if [[ ! -z ${PID} ]]; then
      return 0
   else
      return 1
   fi
}
do_start(){
   check_running
   if [[ $? -eq 0 ]]; then
      echo -e "${Info} $NAME_BIN (PID ${PID}) 正在运行..." && exit 0
   else
      fusermount -zuq $LOCAL >/dev/null 2>&1
      mkdir -p $LOCAL
      sudo /usr/bin/rclone mount $NAME:$REMOTE $LOCAL --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 &
      sleep 2s
      check_running
      if [[ $? -eq 0 ]]; then
         echo -e "${Info} $NAME_BIN 启动成功 !"
      else
         echo -e "${Error} $NAME_BIN 启动失败 !"
      fi
   fi
}
do_stop(){
   check_running
   if [[ $? -eq 0 ]]; then
      kill -9 ${PID}
      RETVAL=$?
      if [[ $RETVAL -eq 0 ]]; then
         echo -e "${Info} $NAME_BIN 停止成功 !"
      else
         echo -e "${Error} $NAME_BIN 停止失败 !"
      fi
   else
      echo -e "${Info} $NAME_BIN 未运行"
      RETVAL=1
   fi
   fusermount -zuq $LOCAL >/dev/null 2>&1
}
do_status(){
   check_running
   if [[ $? -eq 0 ]]; then
      echo -e "${Info} $NAME_BIN (PID $(echo ${PID})) 正在运行..."
   else
      echo -e "${Info} $NAME_BIN 未运行 !"
      RETVAL=1
   fi
}
do_restart(){
   do_stop
   do_start
}
case "$1" in
   start|stop|restart|status)
   do_$1
   ;;
   *)
   echo "使用方法: $0 { start | stop | restart | status }"
   RETVAL=1
   ;;
esac
exit $RETVAL



# 修改权限,启动
chmod +x /etc/init.d/rcloned
chkconfig rcloned on
bash /etc/init.d/rcloned start

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

(●゚ω゚●)
  1. luolibin

    已经支持oss了哦

    Reply