ubuntu16.04部署dify教程

文章目录

Dify 是一个基于 Docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。它通过容器化每个步骤,确保工作流的可复现性和环境一致性。Dify 支持自动化执行、日志记录和结果管理,适用于数据处理、模型训练和部署等场景。

Dify 主要支持以下三种模式:

Agent 模式:Dify 作为一个代理,通过配置和管理多种工作流,进行任务调度和执行。

知识库模式:用于存储和管理工作流相关的知识、数据库和模型,方便复用和共享。

工作流模式:Dify 通过定义工作流的各个步骤,自动化执行数据处理、模型训练、测试等任务,确保工作流的一致性和高效性。

安装 Dify 之前, 请确保机器已满足最低安装要求:

CPU >= 2 Core

RAM >= 4 GiB

1、克隆 Dify 源代码至本地环境

复制代码
git clone https://github.com/langgenius/dify.git

也可以手动下载到本地https://github.com/langgenius/dify/archive/refs/heads/main.zip,解压后移动到服务器上。

2、加速Dify镜像文件下载

详情见:https://github.com/imashen/docker-aio/tree/main

  • 安装脚本使用:curl -fsSL https://docker.13140521.xyz/install | bash -s docker --mirror Aliyun

  • Docker加速源使用:

  • 编辑Docker配置文件: 打开Docker的配置文件(通常位于/etc/docker/daemon.json):sudo vim /etc/docker/daemon.json

  • 添加或修改镜像源: 添加或修改配置文件中的registry-mirrors字段:

    {
    "registry-mirrors": [
    "https://docker.13140521.xyz"
    ]
    }

  • 重启Docker服务: 保存配置文件并重启Docker服务:

    sudo systemctl daemon-reload
    sudo systemctl restart docker

3、启动 Dify

进入 Dify 源代码的 Docker 目录cd dify/docker

复制环境配置文件cp .env.example .env

启动 Docker 容器

根据你系统上的 Docker Compose 版本,选择合适的命令来启动容器。你可以通过docker compose version命令检查版本,详细说明请参考 Docker 官方文档:

如果版本是 Docker Compose V2,使用以下命令:

复制代码
docker compose up -d

如果版本是 Docker Compose V1,使用以下命令:

复制代码
docker-compose up -d

运行命令后,你应该会看到类似以下的输出,显示所有容器的状态和端口映射:

复制代码
[+] Running 11/11
 ✔ Network docker_ssrf_proxy_network  Created                                                                 0.1s 
 ✔ Network docker_default             Created                                                                 0.0s 
 ✔ Container docker_redis_1           Started                                                                 2.4s 
 ✔ Container docker_ssrf_proxy_1      Started                                                                 2.8s 
 ✔ Container docker_sandbox_1         Started                                                                 2.7s 
 ✔ Container docker_web_1             Started                                                                 2.7s 
 ✔ Container docker_weaviate_1        Started                                                                 2.4s 
 ✔ Container docker_db_1              Started                                                                 2.7s 
 ✔ Container docker_api_1             Started                                                                 6.5s 
 ✔ Container docker_worker_1          Started                                                                 6.4s 
 ✔ Container docker_nginx_1           Started                                                                 7.1s

最后检查是否所有容器都正常运行:

复制代码
docker compose ps

NAME                  IMAGE                              COMMAND                   SERVICE      CREATED              STATUS                        PORTS
docker_api_1          langgenius/dify-api:0.6.13         "/bin/bash /entrypoi..."   api          About a minute ago   Up About a minute             5001/tcp
docker_db_1           postgres:15-alpine                 "docker-entrypoint.s..."   db           About a minute ago   Up About a minute (healthy)   5432/tcp
docker_nginx_1        nginx:latest                       "sh -c 'cp /docker-e..."   nginx        About a minute ago   Up About a minute             0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
docker_redis_1        redis:6-alpine                     "docker-entrypoint.s..."   redis        About a minute ago   Up About a minute (healthy)   6379/tcp
docker_sandbox_1      langgenius/dify-sandbox:0.2.1      "/main"                   sandbox      About a minute ago   Up About a minute             
docker_ssrf_proxy_1   ubuntu/squid:latest                "sh -c 'cp /docker-e..."   ssrf_proxy   About a minute ago   Up About a minute             3128/tcp
docker_weaviate_1     semitechnologies/weaviate:1.19.0   "/bin/weaviate --hos..."   weaviate     About a minute ago   Up About a minute             
docker_web_1          langgenius/dify-web:0.6.13         "/bin/sh ./entrypoin..."   web          About a minute ago   Up About a minute             3000/tcp
docker_worker_1       langgenius/dify-api:0.6.13         "/bin/bash /entrypoi..."   worker 

4、访问 Dify

你可以先前往管理员初始化页面设置管理员账户:

本地环境

复制代码
http://localhost/install

服务器环境

复制代码
http://your_server_ip/install

Dify 主页面:

本地环境

复制代码
http://localhost

服务器环境

复制代码
http://your_server_ip

5、更新 Dify

进入 dify 源代码的 docker 目录,按顺序执行以下命令:

复制代码
# 注意:以下方法只针对git clone方式下载的小伙伴
cd dify/docker
docker compose down
git pull origin main
docker compose pull
docker compose up -d

同步环境变量配置 (重要!)

如果 .env.example 文件有更新,请务必同步修改你本地的 .env 文件。

检查 .env 文件中的所有配置项,确保它们与你的实际运行环境相匹配。你可能需要将 .env.example 中的新变量添加到 .env 文件中,并更新已更改的任何值。

如果是通过下载dify压缩文件到本地的小伙伴,请重新下载最新的dify压缩文件并移动到服务器覆盖当前dify目录。接着进入 api 目录下,执行以下命令将数据库结构迁移至最新版本flask db upgrade。接着,运行docker-compose up -d即可。

6、常见问题及解决方案

(1)容器restarting

通过docker compose ps,如果出现个别容器一直restarting,使用docker logs -f查看容器日志,如果日志中出现如下错误:

复制代码
- OpenBLAS blas_thread_init: pthread_create failed for thread 47 of 48: Operation not permittedOpenBLAS blas_thread_init: RLIMIT_NPROC -1 current, -1 max

修改docker-compose.yaml文件,在每个镜像下增加privileged: true # 启用特权模式,如:

复制代码
api:
    image: langgenius/dify-api:0.13.1
    restart: always
    environment:
      # Use the shared environment variables.
      <<: *shared-api-worker-env
      # Startup mode, 'api' starts the API server.
      MODE: api
    depends_on:
      - db
      - redis
    volumes:
      # Mount the storage directory to the container, for storing user files.
      - ./volumes/app/storage:/app/api/storage
    networks:
      - ssrf_proxy_network
      - default
    privileged: true

通过docker-compose down停止所有正在运行的容器,然后docker-compose up -d重新启动所有dify镜像即可解决。

(2)日志文件上限

当前docker日志文件没有设置上限,会导致日志文件占用内存持续增长,可通过以下方式设置单个日志文件的上限:

复制代码
api:
    image: langgenius/dify-api:0.13.1
    restart: always
    environment:
      # Use the shared environment variables.
      <<: *shared-api-worker-env
      # Startup mode, 'api' starts the API server.
      MODE: api
    depends_on:
      - db
      - redis
    volumes:
      # Mount the storage directory to the container, for storing user files.
      - ./volumes/app/storage:/app/api/storage
    networks:
      - ssrf_proxy_network
      - default
    privileged: true
    logging:
      driver: "json-file"
      options:
        max-size: "10m"     # 每个日志文件最大 10MB
        max-file: "3" 

(3)重置管理员密码

如果你通过 Docker Compose 部署,你可以运行以下 Docker Compose 命令行重置密码。

复制代码
docker exec -it docker_api_1 flask reset-password

请按照提示输入邮箱地址和新密码,例如:

复制代码
dify@my-pc:~/hello/dify/docker$ docker compose up -d
[+] Running 9/9
 ✔ Container docker_web_1         Started                                                              0.1s 
 ✔ Container docker_sandbox_1     Started                                                              0.1s 
 ✔ Container docker_db_1          Started                                                              0.1s 
 ✔ Container docker_redis_1       Started                                                              0.1s 
 ✔ Container docker_weaviate_1    Started                                                              0.1s 
 ✔ Container docker_ssrf_proxy_1  Started                                                              0.1s 
 ✔ Container docker_api_1         Started                                                              0.1s 
 ✔ Container docker_worker_1      Started                                                              0.1s 
 ✔ Container docker_nginx_1       Started                                                              0.1s 
dify@my-pc:~/hello/dify/docker$ docker exec -it docker-api-1 flask reset-password
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml
sagemaker.config INFO - Not applying SDK defaults from location: /root/.config/sagemaker/config.yaml
Email: [email protected]
New password: newpassword4567
Password confirm: newpassword4567
Password reset successfully.

(4)修改页面端口

如果你使用 Docker Compose 部署,你可以通过修改.env配置来自定义 Dify 的访问端口。

你需要修改 Nginx 相关配置:

复制代码
EXPOSE_NGINX_PORT=80
EXPOSE_NGINX_SSL_PORT=443
相关推荐
Jackilina_Stone1 小时前
transformers:打造的先进的自然语言处理
人工智能·自然语言处理·transformers
2401_897930061 小时前
BERT 模型是什么
人工智能·深度学习·bert
最新快讯3 小时前
科技快讯 | 阿里云百炼MCP服务上线;英伟达官宣:CUDA 工具链将全面原生支持 Python
人工智能
__Benco4 小时前
OpenHarmony子系统开发 - 热管理(一)
人工智能·harmonyos
吴法刚5 小时前
14-Hugging Face 模型微调训练(基于 BERT 的中文评价情感分析(二分类))
人工智能·深度学习·自然语言处理·分类·langchain·bert·langgraph
碳基学AI6 小时前
北京大学DeepSeek内部研讨系列:AI在新媒体运营中的应用与挑战|122页PPT下载方法
大数据·人工智能·python·算法·ai·新媒体运营·产品运营
是店小二呀6 小时前
Llama 4革命性发布与绿色AI前沿研究
人工智能·llama
2301_799755346 小时前
文件内容课堂总结
人工智能
杰克逊的日记6 小时前
AI集群设计
人工智能·ai·gpu·ai集群·pytorach
技术程序猿华锋6 小时前
Zotero PDF Translate 翻译插件使用OpenAI API配置教程
人工智能·chatgpt·机器翻译