AI摘要:在Debian 12上使用rclone挂载WebDAV服务,需先安装rclone,配置rclone连接WebDAV服务器,创建挂载点,然后挂载并设置权限,可配置自动挂载脚本实现定时挂载。
Powered by AISummary.
使用 rclone 挂载 WebDAV 的详细步骤如下:
步骤 1:安装 rclone
首先确保系统上安装了 rclone:
sudo apt update
sudo apt install rclone
步骤 2:配置 rclone 以连接 WebDAV
运行以下命令启动 rclone 的配置界面:
rclone config
这会进入一个交互式配置环境,接下来按照以下步骤配置 WebDAV:
创建新的 Remote:
选择 n 来创建一个新的 remote。
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
命名你的 Remote:
为你的 WebDAV 连接起一个名称,例如 mywebdav。
name> mywebdav
选择 Storage 类型:
选择 webdav 作为存储类型。你需要输入 webdav 并回车。
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value
...
XX / WebDAV
\ "webdav"
Storage> webdav
输入 WebDAV 服务器 URL:
输入你的 WebDAV 服务器地址,按照你的地址填写:
URL of http host to connect to.
Choose a number from below, or type in your own value
...
url> 你的webdav地址
选择 WebDAV 的 Vendor 类型:
这里选择 other,输入 other 并回车。
Vendor
Choose a number from below, or type in your own value.
1 / Other
...
vendor> other
输入用户名:
输入你的 WebDAV 服务器的用户名
User name.
user> 你的用户名
输入密码:
输入密码,Rclone 会加密存储密码。
Option to enter a password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank
y/g/n> y
Enter the password> 你的密码
其他选项可以保持默认,例如 bearer_token 可以留空。
测试配置:
在配置完成后,rclone 会询问你是否需要测试该连接,选择 y。
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
此时,rclone 配置文件已经完成,WebDAV 服务器的连接信息已经保存。
步骤 3:挂载 WebDAV 文件系统
挂载前,先创建一个挂载点目录,例如 /mnt/webdav:
sudo mkdir /mnt/webdav
使用以下命令挂载 WebDAV 服务器:
rclone mount mywebdav:/ /mnt/webdav --allow-other --dir-cache-time 1m --poll-interval 30s --vfs-cache-mode full --uid=1000 --gid=1000 --umask=002
这里 mywebdav 是你在步骤 2 中配置的 remote 名称。命令成功执行后,你应该可以像访问本地文件系统一样访问 /mnt/webdav,操作 WebDAV 上的文件。
注意:挂载后,rclone 会在前台运行,并保持该挂载连接。如果你希望将其作为后台任务运行,可以加上 --daemon 参数:
rclone mount mywebdav:/ /mnt/webdav --allow-other --dir-cache-time 1m --poll-interval 30s --daemon --vfs-cache-mode full --uid=1000 --gid=1000 --umask=002
注意:权限问题 (--allow-other)
--allow-other 选项允许非挂载进程的用户访问挂载的文件系统,但它要求文件系统中启用了 user_allow_other。如果没有配置,使用 --allow-other 会导致挂载失败。
解决办法:
检查 /etc/fuse.conf 文件中的 user_allow_other 是否被注释掉。可以通过以下命令编辑该文件:
sudo nano /etc/fuse.conf
确保 user_allow_other 行没有被注释(没有 # 号),然后保存文件。
# Allow non-root users to specify the 'allow_other' mount option.
user_allow_other
步骤 4:卸载 WebDAV 文件系统
当你不再需要访问 WebDAV 服务器时,可以使用以下命令卸载:
fusermount -u /mnt/webdav
步骤 5:配置自动挂载脚本
可以使用以下逻辑来配置一个自动挂载脚本:
当系统可以访问网络时,自动挂载webdav服务
nano ~/.ssh/wedav_mount.sh
复制如下脚本:
#!/bin/bash
TARGET="www.baidu.com"
RCLONE_CMD="rclone mount mywebdav:/ /mnt/webdav --allow-other --dir-cache-time 1m --poll-interval 30s --daemon --vfs-cache-mode full --uid=1000 --gid=1000 --umask=002"
MOUNT_POINT="/mnt/webdav"
# ping百度,如果通则检查挂载情况,否则退出
if ping -c 1 $TARGET &> /dev/null
then
# 检查是否已经挂载
if ! mount | grep "$MOUNT_POINT" > /dev/null; then
# 未挂载时,执行挂载
$RCLONE_CMD
# 挂载后再检查一次是否成功
mount | grep "$MOUNT_POINT" > /dev/null || exit 1
fi
fi
ctrl+o 保存
ctrl+x 退出
配置计划任务:
crontab -e
输入如下内容:
*/5 * * * * ~/.ssh/mount_webdav.sh >/dev/null 2>&1
系统会每5分钟运行一次这个脚本,并实现自动挂载。