将阿里云盘挂载为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 'Domain\User'.
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

[alert size="0" icon="" type="default"]

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

[/alert]
挂载到本地
#新建本地文件夹,位置可以自己选
mkdir /data/aliyunwebdav
#挂载
rclone mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty
[alert size="0" icon="" type="default"]

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

[/alert]

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

设置开机自启
#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty"
#以下是一整条命令,一起复制到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

  • 9
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 32
    评论
WebDAV挂载阿里云盘是通过将阿里云盘转换为支持WebDAV协议的云盘,以便可以在群晖中直接使用。具体的部署方法可以参考《docker部署aliyundrive-webdav实现阿里云盘WebDAV服务》一文,该文提供了详细的步骤和指导,可以帮助你完成挂载阿里云盘到群晖文件系统的操作。通过这种方式,你可以在群晖中实现与阿里云盘的文件交互,例如将文件从阿里云盘拷贝到群晖中,或者通过NAS系统进行文件管理和同步。这个方法是基于一个开源项目实现的,该项目可以将阿里云盘转变为支持WebDAV协议的文件服务器,使得你可以将阿里云盘挂载为Windows、Linux、Mac系统的磁盘。这样你就可以通过各种操作系统进行文件的管理和同步,并且可以实现自动备份网站数据等功能。这个项目经过了测试,可以完美实现宝塔自动备份网站、服务器重启自动挂载阿里云盘的功能,同时在宝塔中可以进行文件的复制和删除。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [群晖通过WebDAV挂载阿里云盘](https://blog.csdn.net/bigbear00007/article/details/123617259)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [宝塔环境挂载阿里云盘webdav协议)给服务器扩容自动备份网站数据!](https://blog.csdn.net/weizuer123/article/details/126324008)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 32
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值