负载均衡器
中级
这是一个DevOps领域的自动化工作流,包含 12 个节点。主要使用 Code、Merge、Switch、DataTable、ManualTrigger 等节点。 使用数据表和轮询逻辑分发工作流执行
前置要求
- •无特殊前置要求,导入即可使用
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "Ec7D7cmLxrh1z03H",
"meta": {
"instanceId": "e7281588c6a5bfbbf1af86f0946485a3d9e2154b9b2973c88d730fb17289a5df"
},
"name": "负载均衡器",
"tags": [],
"nodes": [
{
"id": "37cad4dc-4a5e-4e32-9472-af8f3eb99e2e",
"name": "当点击“执行工作流”时",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-432,
-48
],
"parameters": {},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "2f22a244-b3d4-429e-aa3b-b0cf70d04553",
"name": "JavaScript 代码",
"type": "n8n-nodes-base.code",
"position": [
32,
40
],
"parameters": {
"jsCode": "// Get the input data\nconst items = $input.all();\n\n// Process each item\nreturn items.map(item => {\n const currentValue = item.json.Last_Used;\n \n // Increment by 1, or reset to 0 if current value is 3\n const newValue = currentValue === 3 ? 0 : currentValue + 1;\n \n // Return only the required fields\n return {\n json: {\n Last_Used: newValue,\n id: item.json.id\n }\n };\n});"
},
"typeVersion": 2
},
{
"id": "b7b808a8-68b6-4cf4-8a29-4127cfc9a295",
"name": "路由2",
"type": "n8n-nodes-base.noOp",
"position": [
1024,
-64
],
"parameters": {},
"typeVersion": 1
},
{
"id": "62130582-657d-4e72-abf7-6b3aa41ca7d7",
"name": "轮询路由器",
"type": "n8n-nodes-base.switch",
"position": [
704,
-48
],
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "97d76b5a-e6c0-40a8-9ddc-7007078b3cea",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.Last_Used }}",
"rightValue": 1
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "cdc26adb-91ea-4195-b3b0-d33b8405f048",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.Last_Used }}",
"rightValue": 2
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "1b161918-6d41-4fc9-8e61-a8aaf000348c",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.Last_Used }}",
"rightValue": 3
}
]
}
}
]
},
"options": {
"fallbackOutput": 0
}
},
"typeVersion": 3.3
},
{
"id": "021aea98-1458-4c1c-8d63-c1db8f6619d8",
"name": "路由1",
"type": "n8n-nodes-base.noOp",
"position": [
1024,
-224
],
"parameters": {},
"typeVersion": 1
},
{
"id": "ab72a82d-bed2-4541-a440-b557b9bb27bf",
"name": "路由3",
"type": "n8n-nodes-base.noOp",
"position": [
1024,
96
],
"parameters": {},
"typeVersion": 1
},
{
"id": "b9a2d1bc-c6ed-48ac-9f81-9b92448a4c0a",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
416,
-256
],
"parameters": {
"height": 432,
"content": "## 合并输入"
},
"typeVersion": 1
},
{
"id": "679c6ecd-4f29-42da-a3ea-2389cea5612c",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
896,
-256
],
"parameters": {
"color": 4,
"width": 368,
"height": 672,
"content": ""
},
"typeVersion": 1
},
{
"id": "7ceb2c37-5f0a-443b-8845-53e368b5b04f",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-448,
192
],
"parameters": {
"color": 5,
"width": 1328,
"height": 224,
"content": "## 轮询负载均衡器"
},
"typeVersion": 1
},
{
"id": "fd648340-f444-40bf-ae4c-311bed19118c",
"name": "计算要使用的下一个路由",
"type": "n8n-nodes-base.dataTable",
"position": [
-192,
40
],
"parameters": {
"filters": {
"conditions": [
{
"keyValue": "1"
}
]
},
"matchType": "allConditions",
"operation": "get",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "l3AW3b12ncdHyI35",
"cachedResultUrl": "/projects/BoXbNP1BVNpuJKk6/datatables/l3AW3b12ncdHyI35",
"cachedResultName": "Load Balancer"
}
},
"typeVersion": 1
},
{
"id": "699d30f1-89ce-42a1-bcaa-567e4b2330c1",
"name": "更新数据表中的 last_used",
"type": "n8n-nodes-base.dataTable",
"position": [
256,
40
],
"parameters": {
"columns": {
"value": {
"Last_Used": "={{ $json.Last_Used }}"
},
"schema": [
{
"id": "Last_Used",
"type": "number",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "Last_Used",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"Last_Used"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"filters": {
"conditions": [
{
"keyValue": "1"
}
]
},
"options": {},
"matchType": "allConditions",
"operation": "update",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "l3AW3b12ncdHyI35",
"cachedResultUrl": "/projects/BoXbNP1BVNpuJKk6/datatables/l3AW3b12ncdHyI35",
"cachedResultName": "Load Balancer"
}
},
"typeVersion": 1
},
{
"id": "63736019-79a6-4bfe-a2ff-670d1ef46f91",
"name": "合并触发器数据以传递给子工作流(如果需要)",
"type": "n8n-nodes-base.merge",
"position": [
480,
-32
],
"parameters": {},
"typeVersion": 3.2
}
],
"active": false,
"pinData": {
"When clicking ‘Execute workflow’": [
{
"json": {
"processInput": "some input"
}
}
]
},
"settings": {
"executionOrder": "v1"
},
"versionId": "e0b005ce-f1ca-4b28-8053-21828bd1d44f",
"connections": {
"Code in JavaScript": {
"main": [
[
{
"node": "Update last_used in the datatable",
"type": "main",
"index": 0
}
]
]
},
"Round Robin Router": {
"main": [
[
{
"node": "Route 1",
"type": "main",
"index": 0
}
],
[
{
"node": "Route 2",
"type": "main",
"index": 0
}
],
[
{
"node": "Route 3",
"type": "main",
"index": 0
}
]
]
},
"Calculate the next route to use": {
"main": [
[
{
"node": "Code in JavaScript",
"type": "main",
"index": 0
}
]
]
},
"Update last_used in the datatable": {
"main": [
[
{
"node": "Merge trigger data to pass to subworkflow if needed",
"type": "main",
"index": 1
}
]
]
},
"When clicking ‘Execute workflow’": {
"main": [
[
{
"node": "Calculate the next route to use",
"type": "main",
"index": 0
},
{
"node": "Merge trigger data to pass to subworkflow if needed",
"type": "main",
"index": 0
}
]
]
},
"Merge trigger data to pass to subworkflow if needed": {
"main": [
[
{
"node": "Round Robin Router",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个中级难度的工作流,适用于DevOps等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
自动化n8n工作流备份至GitHub并追踪删除
自动化n8n工作流备份至GitHub并追踪删除
If
N8n
Set
+13
31 节点Marcial Ambriz
DevOps
Typebot 流程与 GitHub 双向同步,使用 Typebot API
Typebot 流程与 GitHub 双向同步,使用 Typebot API
If
Set
Code
+12
31 节点Marcial Ambriz
DevOps
备份凭据到 GitHub
备份凭据到 GitHub
Set
Code
Cron
+8
18 节点Solomon
DevOps
高级 n8n 工作流与 GitHub 同步
使用 GitHub 的智能变更检测自动化工作流备份
If
N8n
Set
+10
38 节点Maksym Brashenko
DevOps
GitHub 同步仪表板 - V2
具有提交历史和回滚功能的 GitHub 工作流版本控制仪表板
If
N8n
Set
+20
94 节点Eduard
DevOps
INST安装程序
打包部署多个n8n工作流 - 含自动凭证映射
If
N8n
Set
+12
31 节点Wyeth
DevOps
工作流信息
难度等级
中级
节点数量12
分类1
节点类型7
作者
Adrian Kendall
@akendall1966Business process improvement and continuous improvement SME. Process automation advocate.
外部链接
在 n8n.io 上查看 →
分享此工作流