• docker 安装 sftpgo


    sftpgo 简介

    sftpgo 是一个功能齐全且高度可配置的 SFTP 服务器,具有可选的 HTTP/S、FTP/S 和 WebDAV 支持。支持多种存储后端:本地文件系统、加密本地文件系统、S3(兼容)对象存储、Google 云存储、Azure Blob 存储、SFTP。

    在这里插入图片描述

    官方网站:https://sftpgo.com/

    项目地址:https://github.com/drakkan/sftpgo

    sftpgo 安装

    准备一台linux服务器,以ubuntu 22.04 server为例,已安装docker环境。

    创建sftpgo数据存储目录

    mkdir -p /data/sftpgo/{data,home}
    chown -R 1000:1000 /data/sftpgo/
    
    • 1
    • 2

    说明:

    SFTPGo 使用两个主要卷:

    • /srv/sftpgo 处理持久数据。 SFTP/FTP/WebDAV 用户的默认主目录是 /srv/sftpgo/data/ 。
    • /var/lib/sftpgo 是容器内定义的 sftpgo 系统用户的主目录。这也是容器工作目录,使用默认配置时将在此处创建主机密钥。

    运行sftpgo容器

    docker run -d --name sftpgo \
        --restart always \
        -p 8080:8080 \
        -p 2022:2022 \
        -p 8090:8090 \
        --mount type=bind,source=/data/sftpgo/data,target=/srv/sftpgo \
        --mount type=bind,source=/data/sftpgo/home,target=/var/lib/sftpgo \
        -e TZ=Asia/Shanghai \
        -e SFTPGO_HTTPD__BINDINGS__0__PORT=8080 \
        -e SFTPGO_WEBDAVD__BINDINGS__0__PORT=8090 \
        drakkan/sftpgo:v2.5.4
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    SFTPGo 使用以下默认配置的 TCP 端口:

    • 2022 用于 SFTP 服务。
    • 8080 用于 Web 管理员用户界面。
    • 8090 用于webdav

    查看容器运行状态

    root@ubuntu:~# docker ps
    CONTAINER ID   IMAGE                            COMMAND                  CREATED        STATUS                PORTS                                                                                                                             NAMES
    44d9d989172c   drakkan/sftpgo:v2.5.4            "sftpgo serve"           3 hours ago    Up 3 hours            0.0.0.0:2022->2022/tcp, :::2022->2022/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:8090->8090/tcp, :::8090->8090/tcp   sftpgo
    
    • 1
    • 2
    • 3

    访问Web GUI

    访问其 Web GUI。为此,只需打开本地系统浏览器并将其指向已安装 SFTPGo 的服务器或桌面 IP 地址,端口号为 8080。

    例如:

    http://server-ip-addres:8080
    
    • 1

    创建管理员用户

    访问 Web GUI 后,它会要创建一个管理员帐户。

    在这里插入图片描述

    创建sftp新用户

    一旦拥有了 SFTPGo 的仪表板,就可以创建一个新用户来使用任何 Web 或本地客户端(例如 Filezilla)访问存储数据。单击“用户”选项。之后点击 + 图标。

    在这里插入图片描述

    添加要使用的用户名和密码。如果需要,还可以添加公钥。

    如果使用本地文件系统可以选择local,而其他选项(例如 AWS S3 和 Google 云存储)也可用。

    在这里插入图片描述

    不指定Home Dir时默认为/srv/sftpgo/data/admin1,这里保持默认。

    访问用户 Web 客户端界面

    在浏览器中访问以下网址,并使用新用户帐户详细信息登录

    http://192.168.72.16:8080/web/client
    
    • 1

    登录界面如下:
    在这里插入图片描述

    在这里用户可以轻松上传和下载文件。

    在这里插入图片描述

    测试sftp连接

    使用sftp命令测试连接

    现在测试新用户,linux操作系统默认自带sftp命令,在linux客户端测试连接sftpgo服务器。

    连接后可以执行help命令查看支持的参数,使用putget指令上传下载文件。

    root@ubuntu:~# sftp -P 2022 admin1@192.168.72.16
    The authenticity of host '[192.168.72.16]:2022 ([192.168.72.16]:2022)' can't be established.
    ED25519 key fingerprint is SHA256:Op+5ORK2iLBucnxiL6xRnfPl+D+wXURVS7qOk4WeUMM.
    This key is not known by any other names
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '[192.168.72.16]:2022' (ED25519) to the list of known hosts.
    (admin1@192.168.72.16) Password: 
    Connected to 192.168.72.16.
    sftp> 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    使用winscp客户端测试连接

    输入在SFTPGo上创建的用户名和密码,端口使用2022。示例配置如下:
    在这里插入图片描述

    使用raidrive客户端测试连接,该工具支持sftp、webdav等各种连接方式。

    在这里插入图片描述
    本地 windows 此电脑 中可以将sftp作为本地磁盘使用
    在这里插入图片描述

    SFTPGo挂载为WebDav

    那些想要像使用其他本地磁盘一样使用远程服务器存储文件系统的人可以在 SFTPGo 的帮助下将其挂载为 WebDav。

    在 Windows 上挂载 WebDav

    首先,在系统注册表中进行一些更改。按 Win+R 键并输入 regedit 打开注册表。切换到以下路径

    Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters
    
    • 1

    现在,双击“BasicAuthLevel”,将值 1 更改为 2。按确定按钮。

    重新启动 WebDav 服务:

    以管理员身份运行 PowerShell 并一一键入给定的命令。

    net stop webclient
    
    • 1
    net start webclient
    
    • 1

    转至此电脑或 Windows 上的我的电脑,然后从菜单中选择“映射网络驱动器”。

    在这里插入图片描述

    以下格式输入 SFTPGo 的地址以及端口号。

    http://server-ip:8090
    
    • 1

    当它要求输入用户名和密码时,请执行此操作。
    在这里插入图片描述

    很快就会像系统上的任何本地驱动器一样安装该驱动器。
    在这里插入图片描述

    在 Linux 上挂载 WebDav

    在linux客户端 安装davfs2, 以ubuntu 为例

    root@ubuntu:~# apt install -y davfs2
    root@ubuntu:~# mount.davfs -V
    
    • 1
    • 2

    创建挂载目录

    $ sudo mkdir /mnt/dav
    
    • 1

    使用 mount 命令挂载WebDAV 共享目录,提供 SFTPGo 上创建的用户名和密码

    mount -t davfs -o noexec http://192.168.72.40:8090 /mnt/dav/
    
    • 1

    查看挂载结果

    root@ubuntu:~# df -h|grep mnt
    http://192.168.72.40:8090     1.3T  763G  509G  61% /mnt/dav
    
    • 1
    • 2

    sftpgo 基于 restic 增量备份

    使用restic对某台linux服务器中的/data路径下的数据执行增量备份。

    在需要备份的linux服务器上安装restic,以ubuntu操作系统为例

    wget https://github.com/restic/restic/releases/download/v0.16.0/restic_0.16.0_linux_amd64.bz2
    bzip2 -d restic_0.16.0_linux_amd64.bz2 
    mv restic_0.16.0_linux_amd64 /usr/local/bin/restic
    chmod +x /usr/local/bin/restic
    
    • 1
    • 2
    • 3
    • 4

    使用restic命令在sftpgo服务端创建存储库

    root@ubuntu:~# export RESTIC_PASSWORD="123456"
    root@ubuntu:~# restic init -r sftp://admin1@[192.168.72.16]:2022//restic-repo
    The authenticity of host '[192.168.72.16]:2022 ([192.168.72.16]:2022)' can't be established.
    ED25519 key fingerprint is SHA256:Op+5ORK2iLBucnxiL6xRnfPl+D+wXURVS7qOk4WeUMM.
    This key is not known by any other names
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    subprocess ssh: Warning: Permanently added '[192.168.72.16]:2022' (ED25519) to the list of known hosts.
    (admin1@192.168.72.16) Password: 
    created restic repository 81e4c7ae2d at sftp://admin1@[192.168.72.16]:2022//restic-repo
    
    Please note that knowledge of your password is required to access
    the repository. Losing your password means that your data is
    irrecoverably lost.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    通过restic备份linux/data/目录所有数据到sftpgo

    root@ubuntu:~# export RESTIC_PASSWORD="123456"
    root@ubuntu:~# export RESTIC_REPOSITORY="sftp://admin1@[192.168.72.16]:2022//restic-repo"
    root@ubuntu:~# restic backup /data/
    (admin1@192.168.72.16) Password: 
    repository 81e4c7ae opened (version 2, compression level auto)
    created new cache in /root/.cache/restic
    no parent snapshot found, will read all files
    
    Files:        7197 new,     0 changed,     0 unmodified
    Dirs:         1886 new,     0 changed,     0 unmodified
    Added to the repository: 393.453 MiB (150.566 MiB stored)
    
    processed 7197 files, 395.592 MiB in 0:03
    snapshot a5be14c4 saved
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    登录sftpgo客户端查看备份数据
    在这里插入图片描述

    当/data/目录数据有变化时,重复执行以上命令,会持续创建增量快照,查看历史备份快照:

    root@ubuntu:~# restic snapshots
    (admin1@192.168.72.16) Password: 
    repository 81e4c7ae opened (version 2, compression level auto)
    ID        Time                 Host        Tags        Paths
    ------------------------------------------------------------
    a5be14c4  2023-10-21 18:11:44  ubuntu                  /data
    dcda67da  2023-10-21 18:13:57  ubuntu                  /data
    2eeff04f  2023-10-21 18:14:02  ubuntu                  /data
    ------------------------------------------------------------
    3 snapshots
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    选择某个快照,将数据还原到本地

    root@ubuntu:~# restic restore a5be14c4  --target /tmp/restor-data
    (admin1@192.168.72.16) Password: 
    repository 81e4c7ae opened (version 2, compression level auto)
    restoring <Snapshot a5be14c4 of [/data] at 2023-10-21 18:11:44.118135197 +0800 CST by root@ubuntu> to /tmp/restor-data
    Summary: Restored 9084 Files (395.592 MiB) in 0:03
    root@ubuntu:~# 
    root@ubuntu:~# ls /tmp/restor-data/
    data
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    基于java+ssm+vue+mysql的学生考勤管理系统
    vue项目中的js文件使用vuex
    (附源码)小程序 交通违法举报系统 毕业设计 242045
    将.py文件转化为.exe文件
    3D人脸扫描设备助推元宇宙虚拟人打造
    30天自制操作系统(第28天)
    教你剪辑视频替换封面
    数据结构笔记(王道考研) 第七章:查找
    小程序中如何查看会员的访问记录
    PDF合并和拆分软件 PDF Merge PDF Splitter mac中文版v6.3.9
  • 原文地址:https://blog.csdn.net/networken/article/details/133963932