工具blog|Docker配置Webdav实现Zotero同步-阿里云服务器

Docker配置Webdav实现Zotero同步-阿里云服务器

  • 前置环境声明
  • 安装docker
    • 卸载旧版本
    • 使用yum安装(国内源)
    • 安装Docker
    • 启动Docker
    • 测试Docker是否安装正确
    • 拉取镜像
    • 启动
      • 设置防火墙
      • 通过Docker启动
      • 停止容器(在你需要重新创建的时候才需要使用,不是正常流程必须)
      • 访问共享文件夹
      • Zotero验证

        Zotero多端同步可以有效地在不同设备随时访问文献,极大地方便论文阅读和共享。本文章介绍如何配置Zotero的服务器,用来支持多端同步。

        换了新服务器,先是配置了Webdav,设置了config文件。但是Zotero连接一直报错(如下图所示)。于是怒换Docker实现文件同步。

        前置环境声明

        服务器:阿里云2核2G轻量云服务器

        linux: CentOS 7.9

        [root@xxxx]# lsb_release -a
        LSB Version:    :core-4.1-amd64:core-4.1-noarch
        Distributor ID: CentOS
        Description:    CentOS Linux release 7.9.2009 (Core)
        Release:        7.9.2009
        Codename:       Core
        

        安装docker

        卸载旧版本

        $ sudo yum remove docker \
                          docker-client \
                          docker-client-latest \
                          docker-common \
                          docker-latest \
                          docker-latest-logrotate \
                          docker-logrotate \
                          docker-selinux \
                          docker-engine-selinux \
                          docker-engine
        

        使用yum安装(国内源)

        $ sudo yum install -y yum-utils
        $ sudo yum-config-manager \
            --add-repo \
            https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
        $ sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
        # 官方源
        # $ sudo yum-config-manager \
        #     --add-repo \
        #     https://download.docker.com/linux/centos/docker-ce.repo
        

        安装Docker

        $ sudo yum install docker-ce docker-ce-cli containerd.io
        

        启动Docker

        $ sudo systemctl enable docker
        $ sudo systemctl start docker
        

        测试Docker是否安装正确

        $ docker run --rm hello-world
        Unable to find image 'hello-world:latest' locally
        latest: Pulling from library/hello-world
        b8dfde127a29: Pull complete
        Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
        Status: Downloaded newer image for hello-world:latest
        Hello from Docker!
        This message shows that your installation appears to be working correctly.
        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
            (amd64)
         3. The Docker daemon created a new container from that image which runs the
            executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent it
            to your terminal.
        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash
        Share images, automate workflows, and more with a free Docker ID:
         https://hub.docker.com/
        For more examples and ideas, visit:
         https://docs.docker.com/get-started/
        

        若能正常输出以上信息,则说明安装成功。

        拉取镜像

        $ docker pull bytemark/webdav
        

        启动

        设置防火墙

        首先规划你所需要的端口。笔者使用7777作为端口。

        第一步,打开阿里云防火墙界面,将端口如下图所示添加:

        第二步,打开linux界面,使用下面的命令开启端口:

        # 查看开启端口
        firewall-cmd --list-all
        # 开启指定端口
        firewall-cmd --zone=public --add-port=7777/tcp --permanent
        # 更新防火墙
        firewall-cmd --reload
        

        开启和更新防火墙成功后会输出”success"信息。

        通过Docker启动

        首先规划Zotero存放论文的文件夹。

        笔者使用/home/webdav/zotero/存放。有blog说需要把该文件夹放到docker安装的文件夹下,在我看来不是必要的。

        docker run --restart always -v /home/webdav/zotero:/var/lib/dav/data \
            -e AUTH_TYPE=Digest -e USERNAME=your_DIY_usr_name -e PASSWORD=your_DIY_pwd \
            --publish your_DIY_port(eg:7777):80 --name your_DIY_name \
            -e LOCATION=/webdav/zotero -d bytemark/webdav
        

        笔者使用的命令示例:

        docker run --restart always -v /home/webdav/zotero:/var/lib/dav/data \
            -e AUTH_TYPE=Digest -e USERNAME=your_usr_name -e PASSWORD=your_DIY_pwd \
            --publish 7777:80 --name webdav \
            -e LOCATION=/webdav/zotero -d bytemark/webdav
        
        • -v orig_path:/var/lib/dav/data 指的是将你的orig_path映射到/var/lib/dav/data共享文件夹。
        • –publish 7777:80 是将7777端口作为访问端口。

          LOCATION=/webdav/zotero 是将该路径作为访问路径。注意由于Zotero限制,该LOCATION一定要以/zotero结尾。

          停止容器(在你需要重新创建的时候才需要使用,不是正常流程必须)

          docker stop webdav
          

          访问共享文件夹

          通过刚才设定的publish和LOCATION,使用下面格式的链接访问共享文件夹。

          http://your_server_public_IP:your_port/your_LOCATION/
          

          笔者使用的命令为:

          http://ServerIP:7777/webdav/zotero/
          

          首次访问需要登陆,使用刚才设定的user_name和password即可访问。成功后如下图所示:

          Zotero验证

          打开Zotero-编辑-首选项-同步,按照下图所示选择。 其中port和后面的路径根据需要可以更换。

          然后显示验证通过,可以愉快地实现文件同步啦~

          参考博客:

          [1]: https://blog.csdn.net/u011459717/article/details/128758573 写得比较抽象,需要摸索踩坑

          [2]: https://yeasy.gitbook.io/docker_practice/install/centos

          [3]: http://nas.zwbcc.cn:8090/archives/1679725710280 需要鉴别里面的有效信息