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> `od`
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
为初始化配置填的name
,Folder
为OneDrive里的文件夹,格式为/XX/XXX
,LocalFolder
为VPS上的本地文件夹。
如果报错,需要安装fuse:yum install fuse
如需挂载同一个onedrive的不同目录,配置好后执行rclone config
可以进行复制,name不能相同
卸载:fusermount -qzu LocalFolder
开机启动
使用Systemctl守护进程vi /etc/systemd/system/od.service
[Unit]
Description=OneDrive
AssertPathIsDirectory=LocalFolder
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/rclone mount od:/Public /root/OneDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
ExecStop=/bin/fusermount -qzu /root/OneDrive
Restart=on-abort
[Install]
WantedBy=default.target
相关命令:
执行df -h
可以查看到挂载的onedrive
GoogleDrive
获取API
前往GoogleDrive API,启用API并创建OAuth凭据
需要注意,OAuth 同意屏幕需要添加GoogleDrive权限
服务器配置
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
为初始化配置填的name
,Folder
为GoogleDrive里的文件夹,格式为/XX/XXX
,LocalFolder
为VPS上的本地文件夹。
如果报错,需要安装fuse:yum install fuse
如需挂载同一个onedrive的不同目录,配置好后执行rclone config
可以进行复制,name不能相同
卸载:fusermount -qzu LocalFolder
针对流媒体的挂载:
/usr/bin/rclone mount gd:/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=GoogleDrive
AssertPathIsDirectory=LocalFolder
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/rclone mount gd:/Public /root/GoogleDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
ExecStop=/bin/fusermount -u /root/GoogleDrive
Restart=on-abort
[Install]
WantedBy=default.target
相关命令:
其他用法
rclone copy /www/原始路径 /www/ftp/远程路径 --size-only -P
rclone sync /www/原始路径 /www/ftp/远程路径 --size-only -P -v
此处评论已关闭