Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Running n8n in production: queue mode, workers, and the settings that keep it alive

说明与用途

本文详细介绍了如何配置 n8n 的队列模式以提高可靠性和可扩展性。问题通过分离角色来解决:主实例处理 Webhook 和 UI,而 Worker 从 Redis 队列中执行任务。执行历史清理和数据库备份验证也至关重要。

问题

Self-hosted n8n experiences failure modes where the editor stops loading, webhooks time out, and workflows silently stop. This is typically caused by single-instance execution (where heavy tasks starve the UI) or an unbounded executions table that grows until Postgres becomes a bottleneck or the disk fills.

结果

The system is now resilient to heavy executions, webhooks remain responsive, and the database remains stable due to pruning. The architecture supports horizontal scaling by adding worker replicas without state loss.

工作流

  • Configure the main instance with shared settings (DB, N8N_ENCRYPTION_KEY, EXECUTIONS_MODE=queue, QUEUE_BULL_REDIS_HOST, QUEUE_BULL_REDIS_PORT, QUEUE_BULL_REDIS_PASSWORD).
  • Set N8N_WEBHOOK_URL and OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true on the main instance.
  • Start worker processes using 'n8n worker' with QUEUE_HEALTH_CHECK_ACTIVE=true.
  • Configure execution pruning with EXECUTIONS_DATA_PRUNE=true, EXECUTIONS_DATA_MAX_AGE=336, and EXECUTIONS_DATA_PRUNE_MAX_COUNT=50000.
  • Set up a compressed nightly pg_dump backup to an S3-compatible bucket and verify restores.
  • Disable diagnostics (N8N_DIAGNOSTICS_ENABLED=false) and pin the n8n image version and digest.
  • Scale horizontally by adding more worker replicas as load increases.

证据

In queue mode, n8n splits into two roles: The main instance serves the editor UI, receives webhooks, and manages schedules — but executes nothing. When a workflow should run, it pushes a job onto a Redis queue (Bull). One or more workers pull jobs from the queue and execute them.

来源

EXECUTIONS_DATA_PRUNE=true EXECUTIONS_DATA_MAX_AGE=336 # keep 14 days EXECUTIONS_DATA_PRUNE_MAX_COUNT=50000

来源

A backup you've never restored is a hope, not a backup.

来源

  • 记录日期: 2026-09-09T00:32:19.255Z