Skip to content
WONGCW 網誌
  • 首頁
  • 論壇
  • 微博
  • 壁紙下載
  • 免費圖床
  • 視頻下載
  • 聊天室
  • SEO工具
  • 支援中心
  • 表格製作
  • More
    • 在線名片
    • 網頁搜索
    • 天氣預報
    • 二維碼生成器
  • Search Icon

WONGCW 網誌

記錄生活經驗與點滴

使用Rclone掛載Google Drive到雲主機/VPS 擴容硬盤

使用Rclone掛載Google Drive到雲主機/VPS 擴容硬盤

2019-05-24 Comments 0 Comment

Rclone是一個Github 上面的一個開源項目,專門開髮用來在Linux 上面同步文件/文件夾,上傳的一個命令行工具。目前很多人喜歡用VPS 做離線下載,不過由於有的服務器硬盤太小了,我們可以通過掛載Google Drive網盤的方法,實現擴容。(Google Drive 有15G 免費的空間,也可以去某寶購買一個無限空間的賬號,理論上能夠實現無限存儲)

羊毛黨之家#教程# 使用Rclone掛載Google Drive到雲主機/VPS 擴容硬盤https://yangmaodang.org

本教程僅在CentOS 7 下測試成功,其他版本並未測試僅供參考;

首先安裝EPEL 源:

  1. yum – y install epel – release

接下來安裝一些基本組件和依賴:

  1. yum – y install wget unzip screen fuse fuse – devel

下載Rclone-解壓-重命名文件夾-進入文件夾

  1. cd / usr / local
  2. wget wget https : //downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.zip
  3. unzip rclone-v1.47.0-linux-amd64.zip
  4. mv rclone-v1.47.0-linux-amd64 rclone
  5. cd rclone

目前最新版本是 1.47.0,rclone 会随时间推移而更新,可以到 rclone 官网 查看最新版本然后替换地址即可;

运行 Rclone 开始配置:

  1. chmod +x rclone
  2. ./rclone config

第一步选择 n(新建),然后回车输入一个 name(名字),例如:这里我创建的名字为 gd

  1. No remotes found – make a new one
  2. n) New remote
  3. s) Set configuration password
  4. q) Quit config
  5. n/s/q> n
  6. name> gd

这里选择你需要配置的存储类型,我这里选择 12(Google Drive),根据版本变化选择的序号会不同看清楚 Google Drive 再选择,如果要挂载其他的选填数字即可:

  1. Type of storage to configure.
  2. Enter a string value. Press Enter for the default (“”).
  3. Choose a number from below, or type in your own value
  4. 1 / A stackable unification remote, which can appear to merge the contents of several remotes
  5. \ “union”
  6. 2 / Alias for a existing remote
  7. \ “alias”
  8. 3 / Amazon Drive
  9. \ “amazon cloud drive”
  10. 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean,Dreamhost, IBM COS, Minio, etc)
  11. \ “s3”
  12. 5 / Backblaze B2
  13. \ “b2”
  14. 6 / Box
  15. \ “box”
  16. 7 / Cache a remote
  17. \ “cache”
  18. 8 / Dropbox
  19. \ “dropbox”
  20. 9 / Encrypt/Decrypt a remote
  21. \ “crypt”
  22. 10 / FTP Connection
  23. \ “ftp”
  24. 11 / Google Cloud Storage (this is not Google Drive)
  25. \ “google cloud storage”
  26. 12 / Google Drive
  27. \ “drive”
  28. 13 / Hubic
  29. \ “hubic”
  30. 14 / JottaCloud
  31. \ “jottacloud”
  32. 15 / Local Disk
  33. \ “local”
  34. 16 / Mega
  35. \ “mega”
  36. 17 / Microsoft Azure Blob Storage
  37. \ “azureblob”
  38. 18 / Microsoft OneDrive
  39. \ “onedrive”
  40. 19 / OpenDrive
  41. \ “opendrive”
  42. 20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
  43. \ “swift”
  44. 21 / Pcloud
  45. \ “pcloud”
  46. 22 / QingCloud Object Storage
  47. \ “qingstor”
  48. 23 / SSH/SFTP Connection
  49. \ “sftp”
  50. 24 / Webdav
  51. \ “webdav”
  52. 25 / Yandex Disk
  53. \ “yandex”
  54. 26 / http Connection
  55. \ “http”
  56. Storage> 12

接下来会叫选填 Google Application Client ID 和,这里 2 项都留空回车即可:

  1. Google Application Client Id
  2. Leave blank normally.
  3. Enter a string value. Press Enter for the default (“”).
  4. client_id>
  5. Google Application Client Secret
  6. Leave blank normally.
  7. Enter a string value. Press Enter for the default (“”).
  8. client_secret>

rclone 在请求从驱动器访问时应使用的范围,这里选 1 即可

  1. Scope that rclone should use when requesting access from drive.
  2. Enter a string value. Press Enter for the default (“”).
  3. Choose a number from below, or type in your own value
  4. 1 / Full access all files, excluding Application Data Folder.
  5. \ “drive”
  6. 2 / Read-only access to file metadata and file contents.
  7. \ “drive.readonly”
  8. / Access to files created by rclone only.
  9. 3 | These are visible in the drive website.
  10. | File authorization is revoked when the user deauthorizes the app.
  11. \ “drive.file”
  12. / Allows read and write access to the Application Data folder.
  13. 4 | This is not visible in the drive website.
  14. \ “drive.appfolder”
  15. / Allows read-only access to file metadata but
  16. 5 | does not allow any access to read or download file content.
  17. \ “drive.metadata.readonly”
  18. scope> 1

选填文件夹 ID 和帐户凭据 JSON 文件路径,这里我都留空回车的

  1. ID of the root folder
  2. Leave blank normally.
  3. Fill in to access “Computers” folders. (see docs).
  4. Enter a string value. Press Enter for the default (“”).
  5. root_folder_id>
  6. Service Account Credentials JSON file path
  7. Leave blank normally.
  8. Needed only if you want use SA instead of interactive login.
  9. Enter a string value. Press Enter for the default (“”).
  10. service_account_file>

问你是否要编辑高级配置,这里我选择 N

  1. Edit advanced config? (y/n)
  2. y) Yes
  3. n) No
  4. y/n> n

是否自动远程配置,这里选择 N,因为你在手动远程配置

  1. Remote config
  2. Use auto config?
  3. * Say Y if not sure
  4. * Say N if you are working on a remote or headless machine
  5. y) Yes
  6. n) No
  7. y/n> n

接下来会给出 Google Drive 的授权地址,把它复制到浏览器打开,按提示登陆,复制获取到的代码,然后返回 SSH 粘贴后回车

  1. If your browser doesn’t open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=55663e7e07382e3dddb9025c86de4f
  2. Log in and authorize rclone for access
  3. Enter verification code> 4/UQGiRz375eb-OixO5EUtZMxBhJwAQ4zOyvA1wtJWKq2Ocmzh3zNYE

问你是不是将其配置为团队网盘,这里选 N

  1. Configure this as a team drive?
  2. y) Yes
  3. n) No
  4. y/n> n

列出你上面修改的配置信息,问你是否删除、编辑或者确定配置信息,这里选择确定 y

  1. ——————–
  2. [gd]
  3. type = drive
  4. scope = drive
  5. token = {“access_token”:”ya29.GlsQByNiBURlXoPpe-bDpa2kF99Jo4rrmjicBXdWIT6loPUhS7SJ9XWUIk2LP4vO231nra_zpUwHn6no0Y_LBbXYFZvyVf0gRthepF2VuPFdhBFEKY7XYJaelt”,”token_type”:”Bearer”,”refresh_token”:”1/ry1JGhRiqqE6-PqRN-S2icZ_Oz9uOTXfSNxWA85zUnjU5gEm-6TejL6o-hjyuY”,”expiry”:”2019-05-21T04:36:23.300542043-04:00″}
  6. ——————–
  7. y) Yes this is OK
  8. e) Edit this remote
  9. d) Delete this remote
  10. y/e/d> y

问你是否修改、删除、退出配置编辑,这里选择退出 q

  1. Current remotes:
  2.  
  3. Name Type
  4. ==== ====
  5. gd drive
  6.  
  7. e) Edit existing remote
  8. n) New remote
  9. d) Delete remote
  10. r) Rename remote
  11. c) Copy remote
  12. s) Set configuration password
  13. q) Quit config
  14. e/n/d/r/c/s/q> q

到这里结束配置 rclone,下面要把 Google Drive 网盘挂载到云主机/Vps 上和设置开机自启,自动挂载 Google Drive 网盘

新建一个你要挂载的目录,例如我要挂载到/home/gdrive

  1. mkdir -p /home/gdrive

再执行挂载命令:

  1. ./rclone mount gd: /home/gdrive –allow-other –allow-non-empty –vfs-cache-mode writes

gd 为 Rclone 的配置名称,比如你在创建配置 rclone 的时候 Name 填的 gd,/home/gdrive 为本地路径;

这里还可以自定义设置网盘里的文件夹路径,例如:

  1. ./rclone mount gd:backup /home/gdrive –allow-other –allow-non-empty –vfs-cache-mode writes

gd:backup gd 为 Rclone 的配置名称:backup 为网盘里的目录名

卸载 Google Drive 磁盘

  1. fusermount -qzu /home/gdrive

挂载只要几秒钟,但终端不会返回成功信息,关闭 SSH 重连即可。

重连后查看是否挂载成功:

  1. df -h

有看到 gd,15G 硬盘,使用量和本本地主机路径即成功挂载

  1. gd: 15G 1.1M 15G 1% /home/gdrive

接下来设置开机自动挂载,先把 rclone 的可执行文件复制到/usr/bin:

  1. cp /usr/local/rclone/rclone /usr/bin/rclone

新建一个/usr/lib/systemd/system/rclone.service 文件内容为:

  1. [Unit]
  2. Description=rclone
  3.  
  4. [Service]
  5. User=root
  6. ExecStart=/usr/bin/rclone mount gd: /home/gdrive –allow-other –allow-non-empty –vfs-cache-mode writes
  7. Restart = on – abort
  8.  
  9. [ Install ]
  10. WantedBy = multi – user . target

注意修改掛載命令為你主機的路徑

重載daemon,讓新的服務文件生效:

  1. systemctl daemon – reload

用systemctl 來啟動rclone

  1. systemctl start rclone

設置開機啟動:

  1. systemctl enable rclone

停止、查看狀態可以用:

  1. systemctl stop rclone
  2. systemctl status rclone

重啟你的雲主機/VPS:

  1. reboot

重啟後查看一下rclone 的服務是否啟動,GoogleDrive 是否正常掛載

  1. systemctl status rclone
  2. df – h

OK ! 完成.

把文件上傳到Google Drive

為什麼不直接把文件目錄設置成掛載目錄?如果直接把文件目錄指定到掛載目錄,會出現各種莫名其妙的錯誤,比如:文件無法寫入、讀取、保存到Googlr Drive 的文件不完整等等奇葩的問題。

這裡可以用同步命令,本地目錄/home/backup 同步到網盤的backup 目錄

  1. rclone sync / home / backup gd : backup

相反,把目錄調整下,就是把網盤backup 目錄同步到VPS 目錄/home/backup

  1. rclone sync gd : backup / home / backup

通過添加此參數–ignore-existing 可以忽略在網盤上已備份的文件,這相當於增量備份

  1. rclone copy — ignore – existing / home / backup gd : backup

如果掛載2 個網盤的話,可以同步配置名gd2 的網盤裡的backup 目錄,到配置名為gd 的網盤的backup 目錄,反之亦然

  1. rclone sync gd : backup gd : backup

其他問題請參考rclone幫助文檔  https://rclone.org/googlecloudstorage/

分享此文:

  • 按一下即可分享至 X(在新視窗中開啟) X
  • 按一下以分享至 Facebook(在新視窗中開啟) Facebook
  • 分享到 WhatsApp(在新視窗中開啟) WhatsApp
  • 按一下以分享到 Telegram(在新視窗中開啟) Telegram
  • 分享到 Pinterest(在新視窗中開啟) Pinterest
  • 分享到 Reddit(在新視窗中開啟) Reddit
  • 按一下即可以電子郵件傳送連結給朋友(在新視窗中開啟) 電子郵件
  • 點這裡列印(在新視窗中開啟) 列印

相關


教學資源

Post navigation

PREVIOUS
Volocopter今年將在新加坡建造一個飛行出租車原型站點
NEXT
文本編輯器EmEditor v18.9.4

發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料。

More results...

Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt
Filter by 分類
網站公告
Featured
限時免費
Windows 軟件下載
系統軟件
辦公軟件
圖像處理
影音媒體
網絡軟件
應用軟件
Mac 軟件下載
安卓軟件下載
網絡資訊
Mac資訊
Linux資訊
VPS資訊
NASA資訊
WordPress資訊
WeChat資訊
PHP資訊
教學資源
開源程序
網頁工具
SEO工具
醫療健康
其他資訊
Content from
Content to
2019 年 5 月
一 二 三 四 五 六 日
 12345
6789101112
13141516171819
20212223242526
2728293031  
« 4 月   6 月 »

分類

  • 網站公告
  • 限時免費
  • Windows 軟件下載
  • 系統軟件
  • 辦公軟件
  • 圖像處理
  • 影音媒體
  • 網絡軟件
  • 應用軟件
  • Mac 軟件下載
  • 安卓軟件下載
  • 網絡資訊
  • Mac資訊
  • Linux資訊
  • VPS資訊
  • NASA資訊
  • WordPress資訊
  • WeChat資訊
  • PHP資訊
  • 教學資源
  • 開源程序
  • 網頁工具
  • SEO工具
  • 醫療健康
  • 其他資訊

彙整

近期文章

  • 蘋果智慧家庭中心配備類似Pad的顯示器和機械手臂售價或達1000美元 2025-05-13
  • 研究發現人體手指皮膚浸水後產生的皺紋存在圖案的重複性 2025-05-13
  • 數十家歐盟公司起訴Google 要求其賠償120億歐元 2025-05-13
  • 華為Pura 80工程機鏡頭膜首曝仍是三角排列 2025-05-13
  • 在建大壩成功取出12層樓高混凝土芯樣 2025-05-13
  • Windows 11測試「進階設定」項目以加強對檔案總管等的控制 2025-05-13
  • SonyXperia 1 VII發布:1080P螢幕+驍龍8 Elite 售價過萬 2025-05-13
  • 研究證明有些人就是愛“抬槓” 2025-05-13
  • 消息稱日產將暫停日本部分工廠運營 2025-05-13
  • 《異塵餘生》真人劇第二季前導預告前往拉斯維加斯、已續訂第三季 2025-05-13

熱門文章與頁面︰

  • 您可以在Windows 11 24H2 中找回WordPad
  • 巴西總統盧拉見證美團簽署10億美元投資協議Keeta宣布進入巴西市場
  • 台積電美國三座新廠產能預訂一空蘋果、NVIDIA、AMD搶著要
  • 2024全球晶片公司排行:NVIDIA居首英飛凌、義法半導體跌出前十
  • 蘋果今年將為台積電貢獻1兆新台幣營收
  • Manus回應開放註冊:海外用戶已取消等候名單國內產品尚未發布
  • 特斯拉AI代理商上線:幫助客戶更輕鬆接觸公司高層
  • 摩根大通分析師預測金價到2029年或達到6000美元
  • 美國疑出現可變形UFO盤旋15分鐘專家釋疑
  • 美前財長薩默斯痛批川普擬接受卡達豪華飛機:“香蕉共和國層級的腐敗”

投遞稿件

歡迎各界人士投遞稿件到admin@wongcw.com

請提供以下資料:

1.你的名字

2.你的電郵

3.分類目錄

4.文章標題

5.文章摘要

6.文章內容

7.文章來源

 

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

快帆

MALUS

極度掃描

DMCA.com Protection Status

WONGCW 網誌

  • 免責聲明
  • 捐助我們
  • ThemeNcode PDF Viewer
  • ThemeNcode PDF Viewer SC
  • Events

服務器提供

本站使用之服務器由ikoula提供。

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

© 2025   All Rights Reserved.