【无标题】nohup flask run --host 0.0.0.0 --port=5001 --debug > flask.log 2>&1 &nohup celery -A app.celer

Server Deployment API Interface Service Worker Asynchronous Queue Consumption Service Installation of the basic environment: Server startup requires Python 3.10.x. It is recommended to use pyenv for quick installation of the Python environment. To install additional Python versions, use pyenv install. pyenv install 3.10 To switch to the "3.10" Python environment, use the following command: pyenv global 3.10 Follow these steps : Navigate to the "api" directory: cd api Copy the environment variable configuration file: cp .env.example .env Generate a random secret key and replace the value of SECRET_KEY in the .env file: openssl rand -base64 42 sed -i 's/SECRET_KEY=.*/SECRET_KEY=/' .env Install the required dependencies: Dify API service uses Poetry to manage dependencies. You can execute poetry shell to activate the environment. poetry env use 3.10 poetry install Perform the database migration Perform database migration to the latest version: poetry shell flask db upgrade Start the API server: flask run --host 0.0.0.0 --port=5001 --debug output: * Debug mode: on INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5001 INFO:werkzeug:Press CTRL+C to quit INFO:werkzeug: * Restarting with stat WARNING:werkzeug: * Debugger is active! INFO:werkzeug: * Debugger PIN: 695-801-919 start the Worker service To consume asynchronous tasks from the queue, such as dataset file import and dataset document updates, follow these steps to start the Worker service on Linux or macOS: celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace Start the web frontend client page service Installation of the basic environment: To start the web frontend service, you will need Node.js v18.x (LTS) and NPM version 8.x.x or Yarn. Install NodeJS + NPM Please visit https://nodejs.org/en/download and choose the installation package for your respective operating system that is v18.x or higher. It is recommended to download the stable version, which includes NPM by default. Follow these steps : Enter the web directory cd web Install the dependencies. npm install Configure the environment variables. Create a file named .env.local in the current directory and copy the contents from .env.example. Modify the values of these environment variables according to your requirements: # For production release, change this to PRODUCTION NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT # The deployment edition, SELF_HOSTED or CLOUD NEXT_PUBLIC_EDITION=SELF_HOSTED # The base URL of console application, refers to the Console base URL of WEB service if console domain is # different from api or web app domain. # example: http://cloud.dify.ai/console/api NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from # console or api domain. # example: http://udify.app/api NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api # SENTRY NEXT_PUBLIC_SENTRY_DSN= NEXT_PUBLIC_SENTRY_ORG= NEXT_PUBLIC_SENTRY_PROJECT= Build the code npm run build Start the web service: npm run start 下面的三个都要运行 flask run --host 0.0.0.0 --port=5001 --debug start the Worker service npm run start

Certainly! Here’s a consolidated guide to deploy your API interface service, worker asynchronous queue consumption service, and web frontend client page service. Ensure you follow each step carefully to avoid any issues.

Installation of the Basic Environment

Python Environment Setup
  1. Install Python 3.10.x using pyenv:

    pyenv install 3.10
    
              

    复制

  2. Switch to Python 3.10 environment:

    pyenv global 3.10
    
              

    复制

API Interface Service

  1. Navigate to the api directory:

    cd api
    
              

    复制

  2. Copy the environment variable configuration file:

    cp .env.example .env
    
              

    复制

  3. Generate a random secret key and replace the value of SECRET_KEY in the .env file:

    openssl rand -base64 42
    sed -i 's/SECRET_KEY=.*/SECRET_KEY=<your_value>/' .env
    
              

    复制

  4. Install dependencies using Poetry:

    poetry env use 3.10
    poetry install
    
              

    复制

  5. Perform database migration:

    poetry shell
    flask db upgrade
    
              

    复制

  6. Start the API server:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

    You should see output similar to:

    * Debug mode: on
    INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
     * Running on all addresses (0.0.0.0)
     * Running on http://127.0.0.1:5001
    INFO:werkzeug:Press CTRL+C to quit
    INFO:werkzeug: * Restarting with stat
    WARNING:werkzeug: * Debugger is active!
    INFO:werkzeug: * Debugger PIN: 695-801-919
    
          

    复制

Worker Asynchronous Queue Consumption Service

  1. Start the Worker service:
    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
    
              

    复制

Web Frontend Client Page Service

Node.js Environment Setup
  1. Install Node.js and NPM:
    • Visit Node.js download page and choose the installation package for your OS that is v18.x or higher (LTS recommended).
Web Service Setup
  1. Navigate to the web directory:

    cd web
    
              

    复制

  2. Install the dependencies:

    npm install
    
              

    复制

  3. Configure the environment variables:

    • Create a file named .env.local in the current directory:
      cp .env.example .env.local
      
                

      复制

    • Modify the values in .env.local as per your requirements:
      # For production release, change this to PRODUCTION
      NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
      # The deployment edition, SELF_HOSTED or CLOUD
      NEXT_PUBLIC_EDITION=SELF_HOSTED
      # The base URL of console application
      NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api
      # The URL for Web APP
      NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api
      # SENTRY (if used)
      NEXT_PUBLIC_SENTRY_DSN=
      NEXT_PUBLIC_SENTRY_ORG=
      NEXT_PUBLIC_SENTRY_PROJECT=
      
                

      复制

  4. Build the code:

    npm run build
    
              

    复制

  5. Start the web service:

    npm run start
    
              

    复制

Running All Services

Ensure that the following three commands are running in separate terminals or background processes:

  1. API Server:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

  2. Worker Service:

    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
    
              

    复制

  3. Web Service:

    npm run start
    
              

    复制

By following these steps, you should have all three services up and running on your server.

可以在一个终端中运行吗?

在一个终端中同时运行多个服务并不是最佳实践,因为一旦终端被关闭或者出现错误,所有运行的服务都会被终止。然而,如果你确实需要在一个终端中运行多个服务,可以使用一些技术手段来实现,比如在同一个终端中使用后台进程或者利用 tmuxscreen 等工具。

以下是几种方法来实现这个需求:

方法一:使用 & 符号在后台运行多个命令

你可以使用 & 符号将每个命令放在后台运行:

# 启动 API 服务
flask run --host 0.0.0.0 --port=5001 --debug &

# 启动 Worker 服务
celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace &

# 启动 Web 服务
npm run start &

          

复制

这种方法简单直接,但是如果你想要监控所有服务的输出,会比较麻烦。

方法二:使用 tmuxscreen

tmuxscreen 是终端复用器,可以在一个终端会话中创建多个窗口。

使用 tmux
  1. 安装 tmux

    sudo apt-get install tmux  # 对于基于 Debian 的系统,如 Ubuntu
    sudo yum install tmux      # 对于基于 Red Hat 的系统,如 CentOS
    
              

    复制

  2. 创建一个新的 tmux 会话:

    tmux new -s my_session
    
              

    复制

  3. 在 tmux 会话中,按 Ctrl+b 然后按 c 创建一个新窗口。

  4. 在每个窗口中运行不同的服务。例如,在第一个窗口中运行 API 服务:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

  5. 按 Ctrl+b 然后按 c 创建另一个窗口,运行 Worker 服务:

    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
    
              

    复制

  6. 再次按 Ctrl+b 然后按 c 创建另一个窗口,运行 Web 服务:

    npm run start
    
              

    复制

  7. 你可以通过按 Ctrl+b 然后按窗口编号(如 123)在不同窗口之间切换。

使用 screen
  1. 安装 screen

    sudo apt-get install screen  # 对于基于 Debian 的系统,如 Ubuntu
    sudo yum install screen      # 对于基于 Red Hat 的系统,如 CentOS
    
              

    复制

  2. 创建一个新的 screen 会话:

    screen -S my_session
    
              

    复制

  3. 按 Ctrl+a 然后按 c 创建一个新窗口。

  4. 在每个窗口中运行不同的服务。例如,在第一个窗口中运行 API 服务:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

  5. 按 Ctrl+a 然后按 c 创建另一个窗口,运行 Worker 服务:

    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
    
              

    复制

  6. 再次按 Ctrl+a 然后按 c 创建另一个窗口,运行 Web 服务:

    npm run start
    
              

    复制

  7. 你可以通过按 Ctrl+a 然后按窗口编号(如 123)在不同窗口之间切换。

方法三:使用 nohup

你可以使用 nohup 命令来确保进程在终端关闭后继续运行,并将输出重定向到文件:

nohup flask run --host 0.0.0.0 --port=5001 --debug > flask.log 2>&1 &
nohup celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace > celery.log 2>&1 &
nohup npm run start > npm_start.log 2>&1 &

          

复制

这种方法会将每个服务的方法都有其优缺点,具体选择哪种方法取决于你的实际需求和使用习惯。

sun@sun-virtual-machine:~/dify_s/web$ poetry shell Poetry could not find a pyproject.toml file in /home/sun/dify_s/web or its parents

看起来你在 web 目录中运行了 poetry shell,但是 poetry 没有找到 pyproject.toml 文件。通常,pyproject.toml 文件是用来管理 Python 项目的依赖关系和配置的,因此它应该在你的 api 目录中,而不是在 web 目录中。

根据你提供的步骤,似乎你在 api 目录中使用 poetry 来管理依赖,而在 web 目录中使用 npm 来管理前端依赖。因此,你需要在 api 目录中运行 poetry 相关的命令,而在 web 目录中运行 npm 相关的命令。

以下是完整的步骤,确保你在正确的目录中运行正确的命令:

API 服务

  1. 导航到 api 目录:

    cd api
    
              

    复制

  2. 复制环境变量配置文件:

    cp .env.example .env
    
              

    复制

  3. 生成随机的 SECRET_KEY 并替换 .env 文件中的值:

    openssl rand -base64 42
    sed -i 's/SECRET_KEY=.*/SECRET_KEY=<your_value>/' .env
    
              

    复制

  4. 使用 poetry 安装依赖:

    poetry env use 3.10
    poetry install
    
              

    复制

  5. 进行数据库迁移:

    poetry shell
    flask db upgrade
    
              

    复制

  6. 启动 API 服务:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

Worker 服务

  1. 在新的终端窗口或会话中,启动 Worker 服务:
    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
    
              

    复制

Web 前端服务

  1. 导航到 web 目录:

    cd web
    
              

    复制

  2. 安装依赖:

    npm install
    
              

    复制

  3. 配置环境变量:

    • 创建一个名为 .env.local 的文件:
      cp .env.example .env.local
      
                

      复制

    • 修改 .env.local 文件中的值:
      # For production release, change this to PRODUCTION
      NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
      # The deployment edition, SELF_HOSTED or CLOUD
      NEXT_PUBLIC_EDITION=SELF_HOSTED
      # The base URL of console application
      NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api
      # The URL for Web APP
      NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api
      # SENTRY (if used)
      NEXT_PUBLIC_SENTRY_DSN=
      NEXT_PUBLIC_SENTRY_ORG=
      NEXT_PUBLIC_SENTRY_PROJECT=
      
                

      复制

  4. 构建代码:

    npm run build
    
              

    复制

  5. 启动 Web 服务:

    npm run start
    
              

    复制

运行所有服务

确保以下三个命令在不同的终端窗口或会话中运行:

  1. API 服务:

    flask run --host 0.0.0.0 --port=5001 --debug
    
              

    复制

  2. Worker 服务:

    celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation
    
              

    复制

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunnf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值