rclone是一款可以将多种网盘挂载到服务器上的程序,以下为OneDrive/GoogleDrive挂载。

文章来源:Rat's Blog


环境:centos7 lnmp

OneDrive

客户端授权

在本地Windows电脑上下载rclone,下载后将rclone.exe复制到C:\Windows\System32
运行CMD,输入

rclone authorize "onedrive"

浏览器会自动打开,登入onedrive进行授权,浏览器提示Success!,返回cmd,获取token
复制保存好token
注意:如果是WIN7,CMD生成的token是有回车的,需要将回车删除

服务器配置

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

开始配置:rclone config

n) New remote
s) Set configuration password
q) Quit config
n/s/q> `n`
name> `qfbm`
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
19 / Microsoft OneDrive
   \ "onedrive"
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> `直接回车`
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:
rclone authorize "onedrive"
Then paste the result below:
result> `输入前面获取token`
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
Your choice> `1`
Found 1 drives, please select the one you want to use:
0:  (personal) id=aba1021fbca78159
Chose drive to use:> `0`
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=aba1021fbca78159
Is that okay?
y) Yes
n) No
y/n> `y`
--------------------
[qfbmtc]
type = onedrive
token = {"access_token":"xxx"}
drive_id = aba1021fbca78159
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> `y`
Current remotes:

Name                 Type
====                 ====
qfbmtc               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`

挂载

yum install fuse
mkdir /root/OneDrive #新建本地文件夹
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的nameFolder为OneDrive里的文件夹,格式为/XX/XXXLocalFolder为VPS上的本地文件夹。
如果报错,需要安装fuse:yum install fuse
如需挂载同一个onedrive的不同目录,配置好后执行rclone config可以进行复制,name不能相同

卸载:fusermount -qzu LocalFolder

开机启动

下载脚本

wget https://www.moerats.com/usr/shell/rcloned

修改配置内容:

NAME=""  #rclone name名,及配置时输入的Name
REMOTE=''  #远程文件夹,OneDrive网盘里的挂载的一个文件夹
LOCAL=''  #挂载地址,VPS本地挂载目录

设置自启

cp rcloned /etc/init.d/rclone-img #挂载多个目录进行命名区分
chmod +x /etc/init.d/rclone-img

编辑vi /etc/rc.d/rc.local,在最后面加入

bash /etc/init.d/rclone-img start

执行df -h可以查看到挂载的onedrive
挂载

GoogleDrive

获取API


前往GoogleDrive API,启用API并创建OAuth凭据
需要注意,OAuth 同意屏幕需要添加GoogleDrive权限
google

服务器配置

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

开始配置:rclone config

[root@root ~]# rclone config

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n 
name> gd-emby 
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

13 / Google Drive
   \ "drive"
Storage> 13
** See help for drive backend at: https://rclone.org/drive/ **

client_id> "输入获取的客户端ID"
client_secret> "输入获取的密钥"

Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
scope> 1

root_folder_id> 直接回车
service_account_file> 直接回车
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
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/xxxxx
Log in and authorize rclone for access
Enter verification code> 浏览器打开上面获取的链接,输入获取的密钥
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[gd-emby]
type = drive
client_id = XX
client_secret = XX
scope = drive
token = XX
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name                 Type
====                 ====
gd-emby              drive

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

挂载

yum install fuse
mkdir /root/GoogleDrive #新建本地文件夹
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的nameFolder为GoogleDrive里的文件夹,格式为/XX/XXXLocalFolder为VPS上的本地文件夹。

如果报错,需要安装fuse:yum install fuse
如需挂载同一个onedrive的不同目录,配置好后执行rclone config可以进行复制,name不能相同

卸载:fusermount -qzu LocalFolder

针对流媒体的挂载:

/usr/bin/rclone mount gd-emby:/emby /root/GoogleDrive \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --buffer-size 32M \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 64M \
 --vfs-read-chunk-size-limit 1G

注意,该脚本需要前台运行,可以用于测试(winscp可以检查挂载成功没),后台运行往下看

开机启动

使用Systemctl守护进程
vi /etc/systemd/system/gd.service

[Unit]
Description=rclone
AssertPathIsDirectory=LocalFolder
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount gd-emby:/emby /root/GoogleDrive \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --buffer-size 32M \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 64M \
 --vfs-read-chunk-size-limit 1G
ExecStop=/bin/fusermount -u /root/GoogleDrive
Restart=on-abort

[Install]
WantedBy=default.target

启动脚本:

systemctl enable gd
systemctl start gd

其他备注

挂载的OneDrive/GoogleDrive可配合图床、网盘程序,如兰空图床filerun、AmoliCloud等,将程序读取路径与挂载路径对应

最后修改:2019 年 12 月 08 日 16 : 36