mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
* docs(self-host): supplement missing `workflow_based_app_execution` queue for Worker service in local startup docs Update Chinese, English and Japanese versions of self-hosted documentation by adding the missing `workflow_based_app_execution` queue to the Celery worker startup command. * add missing `dataset_summary` and `retention` queues to worker startup command * add missing `dataset_summary` and `retention` queues to worker startup command * add missing `dataset_summary` and `retention` queues to worker startup command --------- Co-authored-by: Riskey <36894937+RiskeyL@users.noreply.github.com>
297 lines
15 KiB
Plaintext
297 lines
15 KiB
Plaintext
---
|
||
title: ローカルソースコードからの起動
|
||
---
|
||
|
||
<Note> ⚠️ このドキュメントはAIによって自動翻訳されています。不正確な部分がある場合は、[英語版](/en/self-host/advanced-deployments/local-source-code)を参照してください。</Note>
|
||
|
||
## 前提条件
|
||
|
||
### Docker と Docker Compose のセットアップ
|
||
|
||
> Dify をインストールする前に、マシンが以下の最小システム要件を満たしていることを確認してください:
|
||
>
|
||
> * CPU >= 2 コア
|
||
> * RAM >= 4 GiB
|
||
|
||
| OS | ソフトウェア | 説明 |
|
||
| ------------------ | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
| macOS 10.14 以降 | Docker Desktop | Docker 仮想マシン(VM)が最低 2 つの仮想 CPU(vCPU)と 8 GB の初期メモリを使用するように設定してください。そうしないと、インストールが失敗する可能性があります。詳細については、[Mac 用 Docker Desktop インストールガイド](https://docs.docker.com/desktop/mac/install/)を参照してください。 |
|
||
| Linux プラットフォーム | Docker 19.03 以降 Docker Compose 1.25.1 以降 | Docker と Docker Compose のインストール方法については、それぞれ[Docker インストールガイド](https://docs.docker.com/engine/install/)と[Docker Compose インストールガイド](https://docs.docker.com/compose/install/)を参照してください。 |
|
||
| WSL 2 が有効な Windows | Docker Desktop | Linux コンテナにバインドされるソースコードやその他のデータは、Windows ファイルシステムではなく Linux ファイルシステムに保存することをお勧めします。詳細については、[Windows での WSL 2 バックエンドを使用した Docker Desktop インストールガイド](https://docs.docker.com/desktop/windows/install/#wsl-2-backend)を参照してください。 |
|
||
|
||
> OpenAI TTS を使用する必要がある場合は、正常に機能するためにシステムに `FFmpeg` がインストールされている必要があります。詳細については、[リンク](https://docs.dify.ai/getting-started/install-self-hosted/install-faq#id-14.-what-to-do-if-this-error-occurs-in-text-to-speech)を参照してください。
|
||
|
||
### Dify リポジトリのクローン
|
||
|
||
git コマンドを実行して [Dify リポジトリ](https://github.com/langgenius/dify) をクローンします。
|
||
|
||
```Bash
|
||
git clone https://github.com/langgenius/dify.git
|
||
```
|
||
|
||
### Docker Compose でミドルウェアを起動する
|
||
|
||
ストレージ用(PostgreSQL / Redis / Weaviate(ローカルで利用できない場合))や拡張機能用(Dify の [sandbox](https://github.com/langgenius/dify-sandbox) や [plugin-daemon](https://github.com/langgenius/dify-plugin-daemon) サービスなど)の一連のミドルウェアが Dify バックエンドサービスで必要です。次のコマンドを実行して Docker Compose でミドルウェアを起動します:
|
||
|
||
```Bash
|
||
cd docker
|
||
|
||
cp middleware.env.example middleware.env
|
||
|
||
# postgresql を使用していない場合は profile を mysql に変更してください
|
||
# weaviate を使用していない場合は profile を他のベクターデータベースに変更してください
|
||
docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -d
|
||
```
|
||
|
||
***
|
||
|
||
## バックエンドサービスのセットアップ
|
||
|
||
バックエンドサービスには以下が含まれます
|
||
|
||
1. API サービス:フロントエンドサービスと API アクセス用の API リクエストを提供
|
||
2. Worker サービス:データセット処理、ワークスペース、クリーンアップなどの非同期タスクを提供
|
||
|
||
|
||
### API サービスの起動
|
||
|
||
1. `api` ディレクトリに移動します:
|
||
|
||
```
|
||
cd api
|
||
```
|
||
|
||
2. 環境変数設定ファイルを準備します:
|
||
|
||
```
|
||
cp .env.example .env
|
||
```
|
||
|
||
<Note>
|
||
フロントエンドとバックエンドが異なるサブドメインで動作する場合は、`.env` ファイルで `COOKIE_DOMAIN` をサイトのトップレベルドメイン(例:`example.com`)に設定してください。
|
||
|
||
フロントエンドとバックエンドは、認証 Cookie を共有するために同じトップレベルドメイン下にある必要があります。
|
||
</Note>
|
||
|
||
3. ランダムな秘密鍵を生成し、`.env` ファイルの SECRET_KEY の値を置き換えます:
|
||
|
||
```
|
||
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
|
||
```
|
||
|
||
4. 依存関係のインストール:
|
||
|
||
依存関係の管理には [uv](https://docs.astral.sh/uv/getting-started/installation/) を使用します。
|
||
`uv` で必要な依存関係をインストールするには、次のコマンドを実行します:
|
||
```
|
||
uv sync --dev
|
||
```
|
||
> macOS の場合:`brew install libmagic` で libmagic をインストールしてください。
|
||
|
||
5. データベースの移行を実行する:
|
||
|
||
データベースを最新バージョンに移行します:
|
||
|
||
```
|
||
uv run flask db upgrade
|
||
```
|
||
|
||
6. API サービスを起動する:
|
||
|
||
```
|
||
uv run flask run --host 0.0.0.0 --port=5001 --debug
|
||
```
|
||
|
||
期待される出力:
|
||
```
|
||
* 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 サービスの起動
|
||
|
||
データセットファイルのインポートやデータセットドキュメントの更新などのキューからの非同期タスクを処理するには、以下の手順に従って Worker サービスを起動します
|
||
|
||
- macOS または Linux の場合
|
||
```
|
||
uv run celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,dataset_summary,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention,workflow_based_app_execution
|
||
```
|
||
|
||
Windows システムで Worker サービスを起動する場合は、代わりに次のコマンドを使用してください:
|
||
|
||
- Windows の場合
|
||
```
|
||
uv run celery -A app.celery worker -P solo --without-gossip --without-mingle --loglevel INFO -Q dataset,dataset_summary,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention,workflow_based_app_execution
|
||
```
|
||
|
||
期待される出力:
|
||
|
||
```
|
||
-------------- celery@bwdeMacBook-Pro-2.local v5.4.0 (opalescent)
|
||
--- ***** -----
|
||
-- ******* ---- macOS-15.4.1-arm64-arm-64bit 2025-04-28 17:07:14
|
||
- *** --- * ---
|
||
- ** ---------- [config]
|
||
- ** ---------- .> app: app_factory:0x1439e8590
|
||
- ** ---------- .> transport: redis://:**@localhost:6379/1
|
||
- ** ---------- .> results: postgresql://postgres:**@localhost:5432/dify
|
||
- *** --- * --- .> concurrency: 1 (gevent)
|
||
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
|
||
--- ***** -----
|
||
-------------- [queues]
|
||
.> dataset exchange=dataset(direct) key=dataset
|
||
.> generation exchange=generation(direct) key=generation
|
||
.> mail exchange=mail(direct) key=mail
|
||
.> ops_trace exchange=ops_trace(direct) key=ops_trace
|
||
|
||
[tasks]
|
||
. schedule.clean_embedding_cache_task.clean_embedding_cache_task
|
||
. schedule.clean_messages.clean_messages
|
||
. schedule.clean_unused_datasets_task.clean_unused_datasets_task
|
||
. schedule.create_tidb_serverless_task.create_tidb_serverless_task
|
||
. schedule.mail_clean_document_notify_task.mail_clean_document_notify_task
|
||
. schedule.update_tidb_serverless_status_task.update_tidb_serverless_status_task
|
||
. tasks.add_document_to_index_task.add_document_to_index_task
|
||
. tasks.annotation.add_annotation_to_index_task.add_annotation_to_index_task
|
||
. tasks.annotation.batch_import_annotations_task.batch_import_annotations_task
|
||
. tasks.annotation.delete_annotation_index_task.delete_annotation_index_task
|
||
. tasks.annotation.disable_annotation_reply_task.disable_annotation_reply_task
|
||
. tasks.annotation.enable_annotation_reply_task.enable_annotation_reply_task
|
||
. tasks.annotation.update_annotation_to_index_task.update_annotation_to_index_task
|
||
. tasks.batch_clean_document_task.batch_clean_document_task
|
||
. tasks.batch_create_segment_to_index_task.batch_create_segment_to_index_task
|
||
. tasks.clean_dataset_task.clean_dataset_task
|
||
. tasks.clean_document_task.clean_document_task
|
||
. tasks.clean_notion_document_task.clean_notion_document_task
|
||
. tasks.deal_dataset_vector_index_task.deal_dataset_vector_index_task
|
||
. tasks.delete_account_task.delete_account_task
|
||
. tasks.delete_segment_from_index_task.delete_segment_from_index_task
|
||
. tasks.disable_segment_from_index_task.disable_segment_from_index_task
|
||
. tasks.disable_segments_from_index_task.disable_segments_from_index_task
|
||
. tasks.document_indexing_sync_task.document_indexing_sync_task
|
||
. tasks.document_indexing_task.document_indexing_task
|
||
. tasks.document_indexing_update_task.document_indexing_update_task
|
||
. tasks.duplicate_document_indexing_task.duplicate_document_indexing_task
|
||
. tasks.enable_segments_to_index_task.enable_segments_to_index_task
|
||
. tasks.mail_account_deletion_task.send_account_deletion_verification_code
|
||
. tasks.mail_account_deletion_task.send_deletion_success_task
|
||
. tasks.mail_email_code_login.send_email_code_login_mail_task
|
||
. tasks.mail_invite_member_task.send_invite_member_mail_task
|
||
. tasks.mail_reset_password_task.send_reset_password_mail_task
|
||
. tasks.ops_trace_task.process_trace_tasks
|
||
. tasks.recover_document_indexing_task.recover_document_indexing_task
|
||
. tasks.remove_app_and_related_data_task.remove_app_and_related_data_task
|
||
. tasks.remove_document_from_index_task.remove_document_from_index_task
|
||
. tasks.retry_document_indexing_task.retry_document_indexing_task
|
||
. tasks.sync_website_document_indexing_task.sync_website_document_indexing_task
|
||
|
||
2025-04-28 17:07:14,681 INFO [connection.py:22] Connected to redis://:**@localhost:6379/1
|
||
2025-04-28 17:07:14,684 INFO [mingle.py:40] mingle: searching for neighbors
|
||
2025-04-28 17:07:15,704 INFO [mingle.py:49] mingle: all alone
|
||
2025-04-28 17:07:15,733 INFO [worker.py:175] celery@bwdeMacBook-Pro-2.local ready.
|
||
2025-04-28 17:07:15,742 INFO [pidbox.py:111] pidbox: Connected to redis://:**@localhost:6379/1.
|
||
```
|
||
|
||
### Beat サービスの起動
|
||
|
||
さらに、Celery のスケジュールタスクをデバッグしたり、Schedule Trigger ノードを実行したい場合は、別のターミナルで以下のコマンドを実行して Beat サービスを起動できます:
|
||
|
||
```bash
|
||
uv run celery -A app.celery beat
|
||
```
|
||
|
||
---
|
||
|
||
## Web サービスのセットアップ
|
||
|
||
フロントエンドページ用の Web サービスを起動します。
|
||
|
||
### 環境の準備
|
||
|
||
Web フロントエンドサービスを起動するには、[Node.js v22 (LTS)](http://nodejs.org/) と [PNPM v10](https://pnpm.io/) が必要です。
|
||
|
||
- NodeJS のインストール
|
||
|
||
[https://nodejs.org/en/download](https://nodejs.org/en/download) にアクセスし、v18.x 以上のお使いのオペレーティングシステム用のインストールパッケージを選択してください。一般的な使用には LTS バージョンをお勧めします。
|
||
|
||
- PNPM のインストール
|
||
|
||
[インストールガイド](https://pnpm.io/installation) に従って PNPM をインストールします。または、以下のコマンドで `npm` を使用して `pnpm` をインストールできます。
|
||
```
|
||
npm i -g pnpm
|
||
```
|
||
|
||
### Web サービスの起動
|
||
|
||
1. web ディレクトリに移動します:
|
||
|
||
```
|
||
cd web
|
||
```
|
||
|
||
2. 依存関係をインストールします:
|
||
|
||
```
|
||
pnpm install --frozen-lockfile
|
||
```
|
||
|
||
3. 環境変数設定ファイルを準備します\
|
||
現在のディレクトリに `.env.local` というファイルを作成し、`.env.example` の内容をコピーします。必要に応じてこれらの環境変数の値を変更します:
|
||
|
||
```
|
||
# 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
|
||
|
||
# When the frontend and backend run on different subdomains, set NEXT_PUBLIC_COOKIE_DOMAIN=1.
|
||
NEXT_PUBLIC_COOKIE_DOMAIN=
|
||
|
||
# SENTRY
|
||
NEXT_PUBLIC_SENTRY_DSN=
|
||
NEXT_PUBLIC_SENTRY_ORG=
|
||
NEXT_PUBLIC_SENTRY_PROJECT=
|
||
```
|
||
|
||
4. Web サービスをビルドします:
|
||
|
||
```
|
||
pnpm build
|
||
```
|
||
|
||
5. Web サービスを起動します:
|
||
|
||
```
|
||
pnpm start
|
||
```
|
||
|
||
期待される出力:
|
||
```
|
||
▲ Next.js 15
|
||
- Local: http://localhost:3000
|
||
- Network: http://0.0.0.0:3000
|
||
|
||
✓ Starting...
|
||
✓ Ready in 73ms
|
||
```
|
||
|
||
### Dify にアクセスする
|
||
|
||
ブラウザで [http://127.0.0.1:3000](http://127.0.0.1:3000/) にアクセスして、Dify のすべての機能をお楽しみください。
|
||
乾杯!🍻
|