阿里云盘挂载为本地磁盘 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

原文地址:https://www.cnblogs.com/xiaojiluben/p/15578474.html