Ubuntu-Nas> 正文

Dufs一个灵活并功能强大的文件服务器

2024-08-18T20:21:33+08:00

  Dufs一个独特的文件服务器,支持静态文件、访问控制、上传、搜索和webdav功能。使用起来感觉比caddy-file-server方便一点

1、下载安装

下载地址

根据系统类型下载文件,解压后只有一个dufs单文件。

sudo tar dufs-v0.41.0-x86_64-unknown-linux-musl.tar.gz
sudo mv dufs /usr/local/bin/
sudo chmod +x /usr/local/bin/dufs

dufs命令行参数:

dufs --help
Dufs is a distinctive utility file server - https://github.com/sigoden/dufs

Usage: dufs [OPTIONS] [serve-path]

Arguments:
  [serve-path]  Specific path to serve [default: .]

Options:
  -c, --config <file>        Specify configuration file
  -b, --bind <addrs>         Specify bind address or unix socket
  -p, --port <port>          Specify port to listen on [default: 5000]
      --path-prefix <path>   Specify a path prefix
      --hidden <value>       Hide paths from directory listings, e.g. tmp,*.log,*.lock
  -a, --auth <rules>         Add auth roles, e.g. user:pass@/dir1:rw,/dir2
  -A, --allow-all            Allow all operations
      --allow-upload         Allow upload files/folders
      --allow-delete         Allow delete files/folders
      --allow-search         Allow search files/folders
      --allow-symlink        Allow symlink to files/folders outside root directory
      --allow-archive        Allow zip archive generation
      --enable-cors          Enable CORS, sets `Access-Control-Allow-Origin: *`
      --render-index         Serve index.html when requesting a directory, returns 404 if not
                             found index.html
      --render-try-index     Serve index.html when requesting a directory, returns directory
                             listing if not found index.html
      --render-spa           Serve SPA(Single Page Application)
      --assets <path>        Set the path to the assets directory for overriding the built-in
                             assets
      --log-format <format>  Customize http log format
      --log-file <file>      Specify the file to save logs to, other than stdout/stderr
      --compress <level>     Set zip compress level [default: low] [possible values: none, low,
                             medium, high]
      --completions <shell>  Print shell completion script for <shell> [possible values: bash,
                             elvish, fish, powershell, zsh]
      --tls-cert <path>      Path to an SSL/TLS certificate to serve with HTTPS
      --tls-key <path>       Path to the SSL/TLS certificate's private key
  -h, --help                 Print help
  -V, --version              Print version

使用实例:

dufs  -A -p 12123 /mnt/u_disk/downloads/completed/

# -A 允许所有操作权限,如上传、删除、搜索、新建、编辑等。
# /mnt/u_disk/downloads/completed/ 指定特定目录

# 指定端口 -p 12123

2、设置开机启动

增加开机启动服务: sudo vim /lib/systemd/system/dufs.service

dufs.service:

[Unit]
Description=dufs-server
Requires=network-online.target 
After=network-online.target

[Service]
Type=forking
ExecStart=/bin/bash /opt/dufs/start_dufs.sh 

[Install]
WantedBy=multi-user.target

/opt/dufs/start_dufs.sh:

#!/bin/bash
/usr/local/bin/dufs -A -p 12123 /mnt/u_disk/downloads/completed/
sudo chmod +x /opt/dufs/start_dufs.sh #给予可执行权限

sudo systemctl daemon-reload #修改配置文件后需要重加载配置

sudo systemctl enable dufs.service # 设置开机启动

sudo systemctl disable  dufs.service # 关闭开机启动

sudo systemctl status  dufs.service #查看启动的状态

3、Docker

sudo tee /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": ["https://docker.mrxn.net"]
}
EOF
# 配置完后需要重启 Docker 服务
sudo systemctl restart docker

docker pull sigoden/dufs:latest

docker run -d --name dufs-server --restart=always -v /mnt/u_disk/downloads/completed/:/data -p 12123:5000  sigoden/dufs /data -A

4、WEBDAV功能

win10:映射网络驱动器->添加网络位置

分享到:

Ranvane的日常记录

关于我们 客服中心 广告服务 法律声明