阿里雲盤掛載為本地磁盤 Rclone+aria2+webdav


概要

思路:

  1. 利用webdav暴露阿里盤對外訪問地址,rclone掛載webdav間接實現掛載阿里盤。
  2. aria2下載目錄掛載到webdav目錄,實現aria2下載完成自動上傳阿里盤的。

需要:

  1. 服務器一只
  2. 阿里盤賬號一枚

阿里盤+webdav+rclone

1. 獲取阿里盤token

這一步網上教程較多,簡單地貼一張圖。原po
獲取token

2. 安裝webdav

工具地址aliyundriver
我使用docker的方式安裝webdav。當然,您也可以使用jar包直接運行,本文僅提供docker方式安裝的教程。

  1. 首先需要安裝docker。安裝docker
  2. 使用docker-compose一鍵啟動webdav
[root@iZwz9hmxhr8nh716gmser4Z webdav]# cat docker-compose.yml
version: "3.0"
services:
  webdav-aliyundriver:
    image: zx5253/webdav-aliyundriver
    container_name: aliyundriver
    environment:
      - TZ=Asia/Shanghai
      - ALIYUNDRIVE_REFRESH_TOKEN=${此處替換為自己的refresh_token}
      - ALIYUNDRIVE_AUTH_USER-NAME=${此處為你自定義的webdav用戶名}
      - ALIYUNDRIVE_AUTH_PASSWORD=${此處為你自定義的webdav密碼}
#      - JAVA_OPTS=-Xmx1g
    volumes:
      - /home/aliyun-driver/:/etc/aliyun-driver/
    ports:
      - 9798:8080  # 最終暴露到9798端口
    restart: always

# “refreshToken”請根據下文說明自行獲取。
# # “ALIYUNDRIVE_AUTH_USER-NAME”和“ALIYUNDRIVE_AUTH_PASSWORD”為連接用戶名和密碼,建議更改。
# # “/etc/aliyun-driver/:/etc/aliyun-driver/”,可以把冒號前改為指定目錄,比如“/homes/USER/docker/alidriver/:/etc/aliyun-driver/”。
# # 刪除了“/etc/localtime:/etc/localtime”,如有需要同步時間請自行添加在environment下。
# # 端口6666可自行按需更改,此端口為WebDAV連接端口,8080為容器內配置端口,修改請量力而為。
# # 建議不要保留這些中文注釋,以防報錯,比如QNAP
# 啟動
docker-compose up -d

掛載rclone到webdav

  1. 首先需要安裝rclone,這一步網上很多教程。。。
  2. rclone配置
點擊查看代碼
[root@localhost yum.repos.d]# rclone config
2021/08/12 16:28:35 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> aliyunwebdav
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 Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Compress a remote
   \ "compress"
10 / Dropbox
   \ "dropbox"
11 / Encrypt/Decrypt a remote
   \ "crypt"
12 / Enterprise File Fabric
   \ "filefabric"
13 / FTP Connection
   \ "ftp"
14 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
15 / Google Drive
   \ "drive"
16 / Google Photos
   \ "google photos"
17 / Hadoop distributed file system
   \ "hdfs"
18 / Hubic
   \ "hubic"
19 / In memory object storage system.
   \ "memory"
20 / Jottacloud
   \ "jottacloud"
21 / Koofr
   \ "koofr"
22 / Local Disk
   \ "local"
23 / Mail.ru Cloud
   \ "mailru"
24 / Mega
   \ "mega"
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
27 / OpenDrive
   \ "opendrive"
28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
29 / Pcloud
   \ "pcloud"
30 / Put.io
   \ "putio"
31 / QingCloud Object Storage
   \ "qingstor"
32 / SSH/SFTP Connection
   \ "sftp"
33 / Sugarsync
   \ "sugarsync"
34 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
35 / Transparently chunk/split large files
   \ "chunker"
36 / Union merges the contents of several upstream fs
   \ "union"
37 / Uptobox
   \ "uptobox"
38 / Webdav
   \ "webdav"
39 / Yandex Disk
   \ "yandex"
40 / Zoho
   \ "zoho"
41 / http Connection
   \ "http"
42 / premiumize.me
   \ "premiumizeme"
43 / seafile
   \ "seafile"
Storage> 38
URL of http host to connect to
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Connect to example.com
   \ "https://example.com"
url> http://127.0.0.1:9798
Name of the Webdav site/service/software you are using
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Nextcloud
   \ "nextcloud"
 2 / Owncloud
   \ "owncloud"
 3 / Sharepoint Online, authenticated by Microsoft account.
   \ "sharepoint"
 4 / Sharepoint with NTLM authentication. Usually self-hosted or on-premises.
   \ "sharepoint-ntlm"
 5 / Other site/service or software
   \ "other"
vendor> 5
User name. In case NTLM authentication is used, the username should be in the format 'Domain\User'.
Enter a string value. Press Enter for the default ("").
user> admin  # 這里是上一步yaml文件中設置的用戶名
Password.
y) Yes type in my own password 
g) Generate random password
n) No leave this optional password blank (default)
y/g/n> y # 這里要選擇y,然后輸入上一步yaml文件中設置的密碼
Enter the password:
password:
Confirm the password:
password:
Bearer token instead of user/pass (e.g. a Macaroon)
Enter a string value. Press Enter for the default ("").
bearer_token> 
Edit advanced config?
y) Yes
n) No (default)
y/n> 
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 
Current remotes:

Name                 Type
====                 ====
aliyunwebdav         webdav

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
  1. 掛載本地目錄
    DriverName是你在配置rclone的時候設置的名字,Folder沒有需要求的話填/即可,LocalFolder是你本地掛載的地址,/tmp比較特殊,上傳時緩存目錄,其他類型掛載一般時不需要這個參數的,默認/tmp地址即可,除非你的系統特殊
rclone mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty
# 例如
[root@iZwz9hmxhr8nh716gmser4Z cloud-disk]# cat mount.sh
rclone mount aliyunDrive:/aria2 /home/cloud-disk/cloud-driver/download/aria2-downloads --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty --daemon &

掛載aria2

  1. 完成上面的安裝操作,把aria2的下載地址掛到/home/cloud-disk/cloud-driver/download/aria2-downloads就可以了。
  2. 還有更高級的操作,即使用aria2的下載完成觸發腳本的功能,使用rclone sync命令立即同步文件到雲盤,然后再執行本地刪除操作,就可以節省服務器的空間。但是空間足夠,就不折騰了,僅為了實現阿里雲盤離線下載的功能

掛載到本地win10系統

效果圖

  1. 安裝winfsp
  2. 安裝rclone
  3. 啟動腳本

run.vbs

Option Explicit
Dim WMIService, Process, Processes, Flag, WS
Set WMIService = GetObject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
Set Processes = WMIService.ExecQuery("select * from win32_process")
Flag = true
for each Process in Processes
    if strcomp(Process.name, "rclone.exe") = 0 then
        Flag = false
        exit for
    end if
next
Set WMIService = nothing
if Flag then
    Set WS = Wscript.CreateObject("Wscript.Shell")
    WS.Run "D:\Program\rclone\rclone-v1.57.0-windows-amd64\rclone.exe mount aliyun-driver:/ x: --cache-dir D:\aliyun\tmp --vfs-cache-mode writes", 0
end if

參考

將阿里雲盤掛載為Webdav並使用rclone掛載到本地 - 南貓
Docker


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM