MENU

Centos7安装rclone并挂载OneDrive

February 24, 2020 • Read: 4512 • 笔记阅读设置

RCLONE是一个可以给VPS挂载Onedrive/Google Drive等国外主流网盘以及FTP等文件存储的软件。

#安装依赖
yum install fuse -y
#安装主程序
curl https://rclone.org/install.sh | sudo bash

1.需要先在本地Windows获得OneDrive授权认证

下载 https://downloads.rclone.org/rclone-current-windows-amd64.zip
将解压后得到的 rclone.exe 移动到 C:\Windows\System32
打开CMD运行输入 rclone authorize "onedrive"
此时浏览器会弹出OneDrive授权页面,授权完成后将得到下方的一串token,保存好,备用。
20200224020811.jpg

2.返回Centos7初始化rclone
执行 rclone config 配置OneDrive

rclone config
2020/02/24 01:36:44 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> OneDrive #自定义配置名
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 / In memory object storage system.
   \ "memory"
17 / JottaCloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Transparently chunk/split large files
   \ "chunker"
32 / Union merges the contents of several remotes
   \ "union"
33 / Webdav
   \ "webdav"
34 / Yandex Disk
   \ "yandex"
35 / http Connection
   \ "http"
36 / premiumize.me
   \ "premiumizeme"
Storage> 23 #输入23选定网盘提供商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 (default)
y/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 (default)
n) No
y/n> n #输入N开始配置OneDrive
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> {"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} #将前面在Windows下获取的token粘贴进来
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 #这里选择1个人
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=xxxxxxxxxxxxxxxxxx
Chose drive to use:> 0 #选择发现的OneDrive drives
Found drive 'root' of type 'business', URL: https://ofmeio-my.sharepoint.com/personal/test_e3_notpdpton_cn/Documents
Is that okay?
y) Yes (default)
n) No
y/n> #默认回车
--------------------
[OneDrive]
type = onedrive
token = {"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
drive_id = xxxxxxxxxxxxxxxxxx
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> #信息核对正确回车确认即可
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 #退出配置程序

此时rclone初始化配置已经完成
按格式修改命令,挂载到本地目录

mkdir -p /mnt/drive-test #新建需要挂载的目录
rclone mount 服务名:/远程路径 /本地路径 --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

回车后SSH会停留在当前命令,如果一切正确无误,不会出现报错。
新建SSH,输入 df -h 可以查看已经挂载到本地
20200224022141.jpg

可以使用dd命令测速

dd if=/dev/zero of=/mnt/drive-test/test  bs=2048 count=1k

3.卸载目录
卸载很简单就是直接umount就行了

#卸载
umount /mnt/drive-test

4.配置rclone开机自启并挂载OneDrive
由于rclone仅能在前台运行,SSH断掉就失效
这里Gayhub搜集到一个类似service启动的脚本,可以做到后台运行并开机自启
输入 vi rclone 创建

#!/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="OneDrive" #rclone 服务名
REMOTE='Download' #远程目录,OneDrive 网盘里的挂载的一个文件夹,填 / 就是根目录
LOCAL='/mnt/drive-test' #本地路径

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

此脚本出自 https://raw.githubusercontent.com/x91270/Centos/master/rcloned
使用时候先改好里面的变量

NAME="OneDrive" #rclone 服务名
REMOTE='Download' #远程目录,OneDrive 网盘里的挂载的一个文件夹,填 / 就是根目录
LOCAL='/mnt/drive-test' #本地路径

设置自启动

mv rclone /etc/init.d/rclone
chmod +x /etc/init.d/rclone
chkconfig rclone on
bash /etc/init.d/rclone start

启动与停止命令

bash /etc/init.d/rclone start
bash /etc/init.d/rclone stop

Last Modified: February 27, 2020
Archives QR Code
QR Code for this page
Tipping QR Code