rclone 掛載網(wǎng)盤為本地磁盤
rclone是命令行程序
?
linux安裝rclone
?
本教程講解-onedrive全球版掛載方法
?
由于rclone等工具自帶的onedrive授權(quán)方式經(jīng)常出現(xiàn)?token過期的問題(時(shí)間長的可以撐一天,短的就幾個(gè)小時(shí))
?
?
?
?
?
# windows 安裝,獲取網(wǎng)盤token
由于 Onedrive 需要 Outh 認(rèn)證,需要瀏覽器操作,故需要本地也安裝 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 全球版
?
#配置網(wǎng)盤命令
rclone config
?
n??
?
Storage> 26????? // 選擇需要掛載的項(xiàng)目
** 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 中顯示的命令,注意命令前面需要添加一個(gè).\
?
選擇你的 Onedrive 類型,我個(gè)人為家庭版,故選 1
接下來的選項(xiàng)全部選 y 即可,不值得截圖。
最后,配置完成后退出配置頁面
測試 Onedrive 連通性
?
rclone lsd onedrive:
?
?
?
# 網(wǎng)盤 配置文件
非root用戶,路徑可能不同
nano /root/.config/rclone/rclone.conf
?
#手動(dòng)掛載 Mount 命令
我這里假設(shè)我前面添加的名稱為GDrive,想要掛載在本機(jī)的X:上,并設(shè)置緩存目錄為F:\Temp(cache路徑中請(qǐng)不要帶有空格,默認(rèn)緩存目錄為C盤用戶目錄下,?C:\Users\<Your user name>\AppData\Local\rclone)。那么運(yùn)行以下命令執(zhí)行掛載(整個(gè)GDrive根目錄)操作,然后你就會(huì)看到一個(gè)可愛的X盤出現(xiàn)了~
?
rclone mount GDrive:/ x: --cache-dir F:\Temp --vfs-cache-mode writes
?
#新建-本地掛載文件夾?
mkdir -p /root/app/onedrive
?
#新建-緩存文件夾
mkdir -p /root/app/onedrive_temp
?
# 手動(dòng)? 啟動(dòng) 掛載 命令
rclone mount onedrive:/ /root/app/onedrive? --cache-dir? /root/app/onedrive_temp? --vfs-cache-mode? writes
?
?
?
# 網(wǎng)盤緩存 命令-選項(xiàng)細(xì)節(jié)
?
--vfs-cache-mode writes or full is recommended for this remote as it can't stream
?
?- 推薦用于此遙控器的VFS-Cache模式寫入或完整,因?yàn)樗荒芰?/p>
?
?
off: In this mode the cache will read directly from the ? ? ? remote and write directly to the remote without caching anything on disk. ? ? ? (本地不做任何緩存,所有文件直接從云端獲取并寫入。建議網(wǎng)速特別好時(shí)(復(fù)制粘貼大文件時(shí)建議至少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類似,但是已經(jīng)打開的文件會(huì)被緩存到本地。個(gè)人推薦,小文件基本夠用,但是如果你的網(wǎng)絡(luò)情況(梯子)不是特別好的話,用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. (如果文件屬性為只讀則只從云端獲取,不然先
緩存在本地進(jìn)行讀寫操作,隨后被同步。個(gè)人推薦使用,但是在直接從本地復(fù)制文件到GDrive時(shí)還是看網(wǎng)絡(luò)情況
?
?
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. (所有的讀寫操作都會(huì)緩存到磁盤中。然后才會(huì)同步。不是很推薦。會(huì)導(dǎo)致所有文件均被緩存到本地。直到達(dá)到你緩存總額(--cache-total-chunk-size,默認(rèn)大小10G)。但是你網(wǎng)速特別差時(shí)也可以使用。
?
寫入 rmount systemd 文件
以實(shí)現(xiàn)開機(jī)自啟,掉線重啟等。
?
--syslog
在有能力的操作系統(tǒng)(不是 Windows 或 Plan9)上,將所有日志輸出發(fā)送到 syslog。
這對(duì)于在腳本或rclone mount.
?
--progress
?
此標(biāo)志使 rclone 更新終端中靜態(tài)塊中的統(tǒng)計(jì)信息,提供傳輸?shù)膶?shí)時(shí)概覽。
任何日志消息都會(huì)在靜態(tài)塊上方滾動(dòng)。日志消息會(huì)將靜態(tài)塊向下推到終端的底部,它將停留在那里。
通常這會(huì)每 500 毫秒更新一次,但此周期可以被--stats標(biāo)志覆蓋。
這可以與--stats-one-line標(biāo)志一起使用以實(shí)現(xiàn)更簡單的顯示。
?
--use-mmap
如果設(shè)置了此標(biāo)志,則 rclone 將使用基于 Unix 的平臺(tái)上的 mmap 和 Windows 上的 VirtualAlloc 為其傳輸緩沖區(qū)(大小由 控制--buffer-size)分配的匿名內(nèi)存。像這樣分配的內(nèi)存不會(huì)進(jìn)入 Go 堆,并且可以在完成后立即返回給操作系統(tǒng)。
如果未設(shè)置此標(biāo)志,則 rclone 將使用 Go 內(nèi)存分配器分配和釋放緩沖區(qū),這可能會(huì)使用更多內(nèi)存,因?yàn)閮?nèi)存頁返回給操作系統(tǒng)的積極性較低。
這可能不適用于所有平臺(tái),因此默認(rèn)情況下禁用;將來它可能會(huì)默認(rèn)啟用
?
#添加 linux 守護(hù) 服務(wù)
?
#緩存在本地進(jìn)行讀寫操作,隨后被同步
# 添加 服務(wù)文件
?
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
?
?
?
?# 服務(wù)運(yùn)行命令
?
# 重新加載
sudo systemctl daemon-reload
?
sudo systemctl start rmount
# 啟動(dòng)進(jìn)程
?
sudo systemctl enable rmount
?# 開機(jī)啟動(dòng)
?
sudo systemctl disable rmount
?# 禁止 開機(jī)啟動(dòng)
?
?
systemctl restart rmount
# 重啟進(jìn)程
?
sudo systemctl status rmount
# 進(jìn)程狀態(tài)
?
sudo systemctl stop rmount
# 停止
?
#編輯后? 重啟
sudo systemctl daemon-reload
sudo systemctl restart rmount
sudo systemctl status rmount
?
?
#查看 啟動(dòng)信息
?journalctl -xe
?
?
?
?
?
?
?
?