rclone 挂载网盘为本地磁盘
rclone是命令行程序
linux安装rclone
本教程讲解-onedrive全球版挂载方法
由于rclone等工具自带的onedrive授权方式经常出现 token过期的问题(时间长的可以撑一天,短的就几个小时)
# windows 安装,获取网盘token
由于 Onedrive 需要 Outh 认证,需要浏览器操作,故需要本地也安装 Rclone,前往 https://rclone.org/downloads
输入cd 你的reclone路径
# linux安装命令
curl https://rclone.org/install.sh | sudo bash
sudo apt-get install fuse -y
#rclone v1.56.0 has successfully installed.
OneDrive 全球版
#配置网盘命令
rclone config
n
Storage> 26 // 选择需要挂载的项目
** See help for onedrive backend at: https://rclone.org/onedrive/ **
OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> // 直接回车
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> // 直接回车
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
1 / Microsoft Cloud Global
\ "global"
2 / Microsoft Cloud for US Government
\ "us"
3 / Microsoft Cloud Germany
\ "de"
4 / Azure and Office 365 operated by 21Vianet in China
\ "cn"
region> 1 // 选择 1
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> 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 (default)
n) No
y/n> n // 选择 n
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":"XXX"} // 粘贴自己的 Token
输入 VPS 中显示的命令,注意命令前面需要添加一个.\
选择你的 Onedrive 类型,我个人为家庭版,故选 1
接下来的选项全部选 y 即可,不值得截图。
最后,配置完成后退出配置页面
测试 Onedrive 连通性
rclone lsd onedrive:
# 网盘 配置文件
非root用户,路径可能不同
nano /root/.config/rclone/rclone.conf
#手动挂载 Mount 命令
我这里假设我前面添加的名称为GDrive,想要挂载在本机的X:上,并设置缓存目录为F:\Temp(cache路径中请不要带有空格,默认缓存目录为C盘用户目录下, C:\Users\<Your user name>\AppData\Local\rclone)。那么运行以下命令执行挂载(整个GDrive根目录)操作,然后你就会看到一个可爱的X盘出现了~
rclone mount GDrive:/ x: --cache-dir F:\Temp --vfs-cache-mode writes
#新建-本地挂载文件夹
mkdir -p /root/app/onedrive
#新建-缓存文件夹
mkdir -p /root/app/onedrive_temp
# 手动 启动 挂载 命令
rclone mount onedrive:/ /root/app/onedrive --cache-dir /root/app/onedrive_temp --vfs-cache-mode writes
# 网盘缓存 命令-选项细节
--vfs-cache-mode writes or full is recommended for this remote as it can't stream
- 推荐用于此遥控器的VFS-Cache模式写入或完整,因为它不能流
off: In this mode the cache will read directly from the remote and write directly to the remote without caching anything on disk. (本地不做任何缓存,所有文件直接从云端获取并写入。建议网速特别好时(复制粘贴大文件时建议至少100M管以上速度)使用。
minimal: This is very similar to “off” except that files opened for read AND write will be buffered to disks. This means that files opened for write will be a lot more compatible, but uses the minimal disk space. (和off类似,但是已经打开的文件会被缓存到本地。个人推荐,小文件基本够用,但是如果你的网络情况(梯子)不是特别好的话,用writes也行
writes: In this mode files opened for read only are still read directly from the remote, write only and read/write files are buffered to disk first. (如果文件属性为只读则只从云端获取,不然先
缓存在本地进行读写操作,随后被同步。个人推荐使用,但是在直接从本地复制文件到GDrive时还是看网络情况
full:In this mode all reads and writes are buffered to and from disk. When a file is opened for read it will be downloaded in its entirety first. (所有的读写操作都会缓存到磁盘中。然后才会同步。不是很推荐。会导致所有文件均被缓存到本地。直到达到你缓存总额(--cache-total-chunk-size,默认大小10G)。但是你网速特别差时也可以使用。
写入 rmount systemd 文件
以实现开机自启,掉线重启等。
--syslog
在有能力的操作系统(不是 Windows 或 Plan9)上,将所有日志输出发送到 syslog。
这对于在脚本或rclone mount.
--progress
此标志使 rclone 更新终端中静态块中的统计信息,提供传输的实时概览。
任何日志消息都会在静态块上方滚动。日志消息会将静态块向下推到终端的底部,它将停留在那里。
通常这会每 500 毫秒更新一次,但此周期可以被--stats标志覆盖。
这可以与--stats-one-line标志一起使用以实现更简单的显示。
--use-mmap
如果设置了此标志,则 rclone 将使用基于 Unix 的平台上的 mmap 和 Windows 上的 VirtualAlloc 为其传输缓冲区(大小由 控制--buffer-size)分配的匿名内存。像这样分配的内存不会进入 Go 堆,并且可以在完成后立即返回给操作系统。
如果未设置此标志,则 rclone 将使用 Go 内存分配器分配和释放缓冲区,这可能会使用更多内存,因为内存页返回给操作系统的积极性较低。
这可能不适用于所有平台,因此默认情况下禁用;将来它可能会默认启用
#添加 linux 守护 服务
#缓存在本地进行读写操作,随后被同步
# 添加 服务文件
sudo nano /etc/systemd/system/rmount.service
[Unit]
Description=Rclone mount service
Documentation=https://rclone.org/commands/rclone_mount/
After=network.target
[Service]
Type=notify
User=root
Group=root
RemainAfterExit=yes
ExecStart=/usr/bin/rclone mount onedrive:/ /root/app/onedrive --syslog --progress --allow-non-empty --allow-other --cache-dir=/root/app/onedrive_temp --vfs-cache-mode writes --use-mmap --umask 000
ExecReload=/usr/bin/kill -SIGHUP \$MAINPID
ExecStop=/usr/bin/kill -s STOP \$MAINPID
LimitNOFILE=65536
RestartSec=3s
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 服务运行命令
# 重新加载
sudo systemctl daemon-reload
sudo systemctl start rmount
# 启动进程
sudo systemctl enable rmount
# 开机启动
sudo systemctl disable rmount
# 禁止 开机启动
systemctl restart rmount
# 重启进程
sudo systemctl status rmount
# 进程状态
sudo systemctl stop rmount
# 停止
#编辑后 重启
sudo systemctl daemon-reload
sudo systemctl restart rmount
sudo systemctl status rmount
#查看 启动信息
journalctl -xe