将阿里云盘挂载为Webdav并使用rclone挂载到本地

阿里云盘推出“挂载盘”新功能:便捷性堪比本地硬盘-快科技-科技改变生活

准备工作

获取 refreshToken

1. https://media.cooluc.com/decode_token/ 在此网页进行获取, 但是我在搭建的时候报错, 如果报错可以使用第二种方法

2. https://www.aliyundrive.com/sign/ 登录网页版 按 f12 打开控制台—application—local storage—token,即可查看 refresh token

 

安装 webdav 工具

编译安装

确保你的服务器 拥有 jdk 和 maven 如果没有进行安装

yum list java*
yum install java-1.8.0-openjdk.x86_64 #上一条指令会搜索包含 java 的软件列表,挑选最新的下载几个
yum install maven

下载源代码

https://github.com/zxbu/webdav-aliyundriver.git

编译代码

cd webdav-aliyundriver

# 编译

mvn clean package -Dmaven.test.skip=true

# 编译之后的文件在 target 文件夹,webdav*.jar

cd target
mv webdav*.jar webdav.jar

# 运行程序

java -jar webdav.jar --aliyundrive.refresh-token="your refreshToken"

参数说明

--aliyundrive.refresh-token
阿里云盘的 refreshToken,获取方式见下文
--server.port
非必填,服务器端口号,默认为 8080
--aliyundrive.auth.enable=true
是否开启 WebDav 账户验证,默认开启
--aliyundrive.auth.user-name=admin
WebDav 账户,默认 admin
--aliyundrive.auth.password=admin
WebDav 密码,默认 admin

如果你不想自行编译使用的话 我会将编译好的 jar 上传到我的网盘 https://tools.southcat.net 届时您自行下载直接运行程序即可。

 

Docker 运行

docker 配置方便, 并且会自动开机自启, 相对于编译使用个人更推荐使用 docker.

docker 安装

yum install docker

容器运行

docker run -d --name=webdav-aliyundriver --restart=always -p 8080:8080 -v /etc/localtime:/etc/localtime -v /etc/aliyun-driver/:/etc/aliyun-driver/ -e TZ="Asia/Shanghai" -e ALIYUNDRIVE_REFRESH_TOKEN="your refreshToken" -e ALIYUNDRIVE_AUTH_PASSWORD="admin" -e JAVA_OPTS="-Xmx1g" zx5253/webdav-aliyundriver

参数说明和上面编译运行的是一样的.

 

安装 Rclone 进行挂载

安装 rclone

curl https://rclone.org/install.sh | sudo bash 容 

配置 rclone

rclone config

配置过程代码

[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:8080
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 'DomainUser'.
Enter a string value. Press Enter for the default ("").
user> admin
Password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank (default)
y/g/n> y
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>
--------------------
[aliyunwebdav]
type = webdav
url = http://127.0.0.1:8080
vendor = other
user = admin
pass = *** ENCRYPTED ***
--------------------
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

name 请自行替换

密码需要输入两遍进行确认, 建议上面运行 webdav 程序的时候不设置密码, 这里就不需要进行设置, 直接选择无密码选项

挂载到本地
#新建本地文件夹, 位置可以自己选

mkdir /data/aliyunwebdav

# 挂载

rclone mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty

DriverName 是你在配置 rclone 的时候设置的名字,Folder 没有需要求的话填 / 即可,LocalFolder 是你本地挂载的地址,/tmp 比较特殊, 上传时缓存目录, 其他类型挂载一般时不需要这个参数的, 默认 /tmp 地址即可, 除非你的系统特殊

执行完之后即可访问本地挂载的文件夹查看文件了.

设置开机自启
#将后面修改成你上面手动运行命令中,除了 rclone 的全部参数

command="mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty"[/t-dark]
#以下是一整条命令,一起复制到 SSH 客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target
[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root
[Install]
WantedBy=default.target
EOF

开始启动:

systemctl start rclone

设置开机自启:

systemctl enable rclone

其他命令:

 重启:systemctl restart rclone
停止:systemctl stop rclone
状态:systemctl status rclone

 

版权声明:
作者:admin
链接:https://jkboy.com/archives/5605.html
来源:随风的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
将阿里云盘挂载为Webdav并使用rclone挂载到本地
准备工作 获取 refreshToken 1. https://media.cooluc.com/decode_token/ 在此网页进行获取, 但是我在搭建的时候报错, 如果报错可以使用第二种方法 2. https:……
<<上一篇
下一篇>>
文章目录
关闭
目 录