dify 源码部署操作记录

发布于:2025-03-15 ⋅ 阅读:(11) ⋅ 点赞:(0)

ps:我装的是 0.15.3 版本,拉取代码时
一定要拉取 tag,不要拉取 master 分支代码,不要拉取 master 分支代码!!

后端注意事项

  1. 根据官网步骤安装
    https://docs.dify.ai/getting-started/install-self-hosted/local-source-code
  2. 其中 pyenv 不是必须操作,如果有 conda 的话可以直接用conda安装,但conda有时候安不上,换个镜像就行了
    pyenv 会导致 conda 环境失效,建议使用 conda 安装
    conda create --name difyai -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge python=3.12
    
    剩下的就是 conda 激活对应的环境,然后
    poetry config virtualenvs.create false  # 让 poetry 不再额外创建 venv
    poetry install
    flask db upgrade 	# 执行数据库迁移
    flask run --host 0.0.0.0 --port=5001 --debugger   	# 启动 API 服务器
    
    # 启动 Worker 服务
    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace 
    

前端注意事项

前端好说了就,无非就是安装依赖、打包、启动

npm install  # 安装依赖
npm run build  # 打包
npm start # 打包后启动

但是后台运行 npm start时,关闭当前 ssh 连接后前端会自动停止:

在当shell中提示了nohup成功后,还需要按终端上键盘任意键退回到shell输入命令窗口,然后通过在shell中输入exit来退出终端;如果在nohup执行成功后直接点关闭程序按钮关闭终端的话,这时候会断掉该命令所对应的session,导致nohup对应的进程被通知需要一起shutdown,起不到关掉终端后调用程序继续后台运行的作用。

nohup npm start >./start.log 2>&1 &

在执行了上面的命令后,然后输入任意键回到shell中,使用 exit 命令退出,而不是直接关闭整个shell程序,即可保证程序要后端正常运行。