Linux VPS使用Rclone掛載Google Drive為本地硬盤使用
說明
本教程隻適用Debian
/Ubuntu
係統,如果你是CentOS
或者其它Linux
係統,請使用以下命令安裝rclone
:
curl https://rclone.org/install.sh | sudo bash
安裝rclone
Debian
/Ubuntu
wget https://cdn.jsdelivr.net/gh/sunpma/cdn/other/rclone_debian.sh && bash rclone_debian.sh
開始配置
rclone config
詳細配置過程
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #輸入n回車,新建配置
name> GD #新建配置的名稱,隨意填寫,後麵會用到
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 / Dropbox
\ "dropbox"
9 / Encrypt/Decrypt a remote
\ "crypt"
10 / FTP Connection
\ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
12 / Google Drive
\ "drive"
13 / Google Photos
\ "google photos"
14 / Hubic
\ "hubic"
15 / JottaCloud
\ "jottacloud"
16 / Koofr
\ "koofr"
17 / Local Disk
\ "local"
18 / Mega
\ "mega"
19 / Microsoft Azure Blob Storage
\ "azureblob"
20 / Microsoft OneDrive
\ "onedrive"
21 / OpenDrive
\ "opendrive"
22 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
23 / Pcloud
\ "pcloud"
24 / Put.io
\ "putio"
25 / QingCloud Object Storage
\ "qingstor"
26 / SSH/SFTP Connection
\ "sftp"
27 / Union merges the contents of several remotes
\ "union"
28 / Webdav
\ "webdav"
29 / Yandex Disk
\ "yandex"
30 / http Connection
\ "http"
31 / premiumize.me
\ "premiumizeme"
Storage> 12 #選擇需要掛載的網盤
** See help for drive backend at: https://rclone.org/drive/ **
Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> #默認直接回車,或者輸入自己的OAuth ID
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> #默認直接回車,或者輸入自己的OAuth秘鎖
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
\ "drive"
2 / Read-only access to file metadata and file contents.
\ "drive.readonly"
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ "drive.appfolder"
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ "drive.metadata.readonly"
scope> 1 #默認輸入1回車
ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
Enter a string value. Press Enter for the default ("").
root_folder_id> #默認直接回車
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>
Edit advanced config? (y/n)
y) Yes
n) No
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
n) No
y/n> n #是否使用自動配置,輸入n回車
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/XXX
Log in and authorize rclone for access
Enter verification code> XXXX #複製上麵的鏈接在瀏覽器中打開,將得到的授權碼複製到這裏後回車
Configure this as a team drive?
y) Yes
n) No
y/n> y #是否掛載團隊網盤,如果沒有輸入n回車,需要掛載團隊版輸入y回車
Fetching team drive list...
Choose a number from below, or type in your own value
1 / SunPma
\ "0ADYACmKjlU3JUk9PVA"
Enter a Team Drive ID> 1 #選擇你需要掛載的團隊盤然後回車
--------------------
[SUNPMAGD]
type = drive
scope = drive
token = {"access_token":"XXX","expiry":"2019-10-23T14:32:06.481207275+08:00"}
team_drive = 0ADYACmKjlU3JUk9PVA
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y #默認輸入y回車
Current remotes:
Name Type
==== ====
SUNPMAGD 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 #輸入q回車,保存配置退出
新建本地掛載文件夾
mkdir /home/GD
掛載磁盤
說明
#/usr/bin/rclone mount DriveName:Folder LocalFolder \
下麵整體代碼中最上麵的這條需要自己修改,不要直接複製,注意代碼中有空格
DriveName #配置時填寫的name
Folder #網盤裏要掛載的文件夾名
LocalFolder #本地要掛載的文件夾絕對路徑
例:/usr/bin/rclone mount GD:VPS /home/GoogleDrive \
掛載
#下麵代碼是一個整體,全部複製後粘貼運行
/usr/bin/rclone mount DriveName:Folder LocalFolder \
--umask 0000 \
--default-permissions \
--allow-non-empty \
--allow-other \
--transfers 1 \
--buffer-size 64M \
--low-level-retries 200
#如果你還涉及到讀取使用,比如使用H5ai等線上播放,就在後麵多加上以下三條參數
--dir-cache-time 12h
--vfs-read-chunk-size 32M
--vfs-read-chunk-size-limit 1G
參數說明
--transfers:該參數是最大同時傳輸任務數量,如果經常傳輸大文件,或CPU性能不佳,建議設置為單線程,也就是設置為“1”
--buffer-size:該參數為讀取每個文件時的內存緩衝區大小,控製rclone上傳和掛載的時候的內存占用
--low-level-retries:該參數為傳輸文件沒速度的時候重試次數,沒速度的時候,單個會自動睡眠10ms起,然後再重試
掛載成功後,輸入df -h
命令查看是否掛載成功;
卸載磁盤
fusermount -qzu LocalFolder
LocalFolder
為本地掛載文件夾絕對路徑
設置自啟動
下載並編輯腳本
wget https://www.moerats.com/usr/shell/rcloned && nano rcloned
修改以下內容:
NAME="" #rclone name名,及配置時輸入的name
REMOTE='' #遠程文件夾,Google Drive網盤裏的掛載的一個文件夾
LOCAL='' #掛載地址,VPS本地掛載目錄
設置自啟
apt-get install sudo -y
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults
bash /etc/init.d/rcloned start
檢測信息顯示rclone
在運行即可;
rclone命令
### 文件上傳
rclone copy /home/backup gdrive:backup # 本地路徑 配置名字:穀歌文件夾路徑
### 文件下載
rclone copy gdrive:backup /home/backup # 配置名字:穀歌文件夾路徑 本地路徑
### 新建文件夾
rclone mkdir gdrive:backup # 配置名字:穀歌文件夾路徑
### 獲取文件夾大小
rclone size gdrive:backup # 配置名字:穀歌文件夾路徑
### 列表
rclone ls gdrive:backup
rclone lsl gdrive:backup # 比上麵多一個顯示上傳時間
rclone lsd gdrive:backup # 隻顯示文件夾
### 掛載
rclone mount gdrive:mm /root/mm &
### 卸載
fusermount -u /root/mm
#### 其他 ####
#### https://softlns.github.io/2016/11/28/rclone-guide/
rclone config - 以控製會話的形式添加rclone的配置,配置保存在.rclone.conf文件中。
rclone copy - 將文件從源複製到目的地址,跳過已複製完成的。
rclone sync - 將源數據同步到目的地址,隻更新目的地址的數據。 –dry-run標誌來檢查要複製、刪除的數據
rclone move - 將源數據移動到目的地址。
rclone delete - 刪除指定路徑下的文件內容。
rclone purge - 清空指定路徑下所有文件數據。
rclone mkdir - 創建一個新目錄。
rclone rmdir - 刪除空目錄。
rclone check - 檢查源和目的地址數據是否匹配。
rclone ls - 列出指定路徑下所有的文件以及文件大小和路徑。
rclone lsd - 列出指定路徑下所有的目錄/容器/桶。
rclone lsl - 列出指定路徑下所有文件以及修改時間、文件大小和路徑。
rclone md5sum - 為指定路徑下的所有文件產生一個md5sum文件。
rclone sha1sum - 為指定路徑下的所有文件產生一個sha1sum文件。
rclone size - 獲取指定路徑下,文件內容的總大小。.
rclone version - 查看當前版本。
rclone cleanup - 清空remote。
rclone dedupe - 交互式查找重複文件,進行刪除/重命名操作。
重啟:systemctl restart rclone
停止:systemctl stop rclone
狀態:systemctl status rclone
將命令掛載到後台運行
掛載後台運行,Rclone的上傳下載命令需要開著SSH,SSH斷開後任務會中斷,對於大文件不太方便,我們可以掛載到後台運行
nohup 這裏填寫需要執行的命令,注意前後有空格 &
查看進程PID
ps -ef
結束進程PID
kill -6 任務的PID
相關參考:
https://moeclub.org/2017/11/28/500/
https://www.moerats.com/archives/481/
https://www.moerats.com/archives/877/
2020年最便宜的雲服務器,性價比最高的服務器推薦睿數據!www.ruidata.net ,海內外G口計量雲,香港日本新加坡英國法國等十六國!
相關說明:
1、VIP會員無限製任意下載,免積分。立即前往開通>>
2、下載積分可通過日常 簽到、綁定郵箱 以及 積分兌換 等途徑獲得!
3、本站資源大多存儲在雲盤,如出現鏈接失效請評論反饋,如有密碼,均為:www.ipipn.com。
4、所有站內資源僅供學習交流使用。未經原版權作者許可,禁止用於任何商業環境,否則後果自負。為尊重作者版權,請購買正版作品。
5、站內資源來源於網絡公開發表文件或網友分享,如侵犯您的權益,請聯係管理員處理。
6、本站提供的源碼、模板、軟件工具等其他資源,都不包含技術服務,請大家諒解!
7、源碼、模板等資源會隨著技術、壞境的升級而存在部分問題,還請慎重選擇。
PS.源碼均收集自網絡,如有侵犯閣下權益,請發信件至: admin@ipipn.com .
源站網 » Linux VPS使用Rclone掛載Google Drive為本地硬盤使用