下载启动dify

git clone git@gitee.com:dify_ai/dify.git

cd dify/docker
cp .env.example  .env

docker compose up -d

此时可能 报错

failed to launch plugin: failed to install dependencies: failed to install dependencies: signal: killed, output: DEBUG uv 0.9.26 DEBUG Acquired shared lock for `/root/.cache/uv` DEBUG Found project root: `/app/storage/cwd/langgenius/ollama-0.1.3@66e156c4f612964c131c49168882e78c2cdfe366879506b97ad855b23c5d6d98` DEBUG No workspace root found, using project root DEBUG Acquired exclusive lock for `/app/storage/cwd/langgenius/ollama-0.1.3@66e156c4f612964c131c49168882e78c2cdfe366879506b97ad855b23c5d6d98` DEBUG No...r: https://files.pythonhosted.org/packages/11/79/479e2194c9096b92aecdf33634ae948d2be306c6011673e98ee1917f32c2/dpkt-1.9.8-py3-none-any.whl DEBUG Sending fresh GET request for: https://files.pythonhosted.org/packages/11/79/479e2194c9096b92aecdf33634ae948d2be306c6011673e98ee1917f32c2/dpkt-1.9.8-py3-none-any.whl Downloading pydantic-core (2.0MiB) Downloading numpy (15.3MiB) Downloading tiktoken (1.1MiB) Downloading gevent (2.0MiB) init process exited due to no activity for 120 seconds failed to init environment

解决方法

cd dify/docker
vi .env


修改
# 1. (关键) 更换 PIP 镜像源为国内源,这是解决下载慢最有效的办法
PIP_MIRROR_URL=https://pypi.tuna.tsinghua.edu.cn/simple

# 2. 大幅增加插件环境初始化超时时间(单位:秒),从默认的120增加到360或更高
PLUGIN_PYTHON_ENV_INIT_TIMEOUT=360

# 3. (可选) 如果担心其他步骤也超时,可以一并增加插件最大执行超时时间
PLUGIN_MAX_EXECUTION_TIMEOUT=1800

安装ollama 

curl -fsSL https://ollama.com/install.sh | sh

如果在ubuntu 上 可以

sudo snap install ollama

ollama 常用命令

ollama run qwen:7b

ollama list

ollama rm <模型名>

snap 修改ollama 环境变量

snap set ollama host="0.0.0.0:11434" 后,请运行 snap get ollama

在 Dify 中连接 Ollama

配置生效后,在 Dify 的 Ollama 插件设置中:

配置项
Base URL http://host.docker.internal:11434
模型名称 deepseek-r1:1.5b

查看ollama 启动的模型

curl http://host.docker.internal:11434/api/tags

ollama 启动多个模型

通过 Windows 图形界面设置

这种方式最直观,适合大多数用户。

具体步骤:

  1. 打开系统环境变量设置

    • 按下 Win + S,在搜索框中输入 “编辑系统环境变量” 或 “环境变量”

    • 点击搜索结果中的“编辑系统环境变量”

  2. 进入环境变量编辑界面

    • 在弹出的“系统属性”窗口中,点击右下角的 “环境变量” 按钮

  3. 新建环境变量

    • 在“系统变量”区域(建议选这个,对所有用户生效),点击 “新建”

    • 分别添加以下两个变量:

变量名 变量值 说明
OLLAMA_MAX_LOADED_MODELS 2 同时最多加载 2 个模型到显存中
OLLAMA_NUM_PARALLEL 4 每个模型同时处理 4 个并发请求
  1. 保存设置

    • 依次点击“确定”关闭所有窗口

  2. 重启 Ollama 服务

    • 在系统托盘中找到 Ollama 图标(右下角)

    • 右键点击 → 选择 “Quit” 退出

验证设置是否生效

设置完成后,可以通过以下方式确认环境变量已生效:

  1. 打开一个新的 PowerShell 窗口(必须是新的,否则不会加载新变量)

  2. 查看变量值

    powershell

    # 查看所有 Ollama 相关的环境变量
    Get-ChildItem Env: | Where-Object Name -like "OLLAMA*"

    应该能看到类似这样的输出:

    text

    OLLAMA_MAX_LOADED_MODELS    2
    OLLAMA_NUM_PARALLEL          4
  3. 使用 ollama ps 验证多模型加载

    bash

    ollama pull deepseek-r1:7b
    ollama pull bge-m3:latest
    
    # 向两个模型各发一个请求
    curl http://localhost:11434/api/generate -d '{"model":"deepseek-r1:7b","prompt":"Hi"}'
    curl http://localhost:11434/api/embed -d '{"model":"bge-m3:latest","input":["test"]}'
    
    # 查看当前加载的模型(应该看到两个)
    ollama ps
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐