--- title: "传输层连接超时配置" date: 2026-01-06 lastmod: 2026-01-06 description: "控制传输层连接超时时间的配置项说明" tags: ["网络配置", "超时设置", "集群通信"] summary: "配置项作用 # transport.connect_timeout 配置项控制传输层客户端连接到其他节点的超时时间。当节点尝试连接到集群中的其他节点时,如果在此时间内未能建立连接,连接尝试将失败。此配置是已弃用的 transport.tcp.connect_timeout 配置的新名称。 配置项类型 # 该配置项为静态配置,需要在启动时设置,修改后需要重启节点才能生效。 默认值 # 30s 是否必需 # 可选配置项(有默认值) 取值范围 # 时间格式配置(如 1s, 30s, 1m) 配置格式 # # 默认配置 transport.connect_timeout: 30s # 缩短超时时间 transport.connect_timeout: 10s # 延长超时时间 transport.connect_timeout: 60s # 旧配置名称(已弃用) transport.tcp.connect_timeout: 30s 相关配置项 # 配置项 默认值 说明 transport.connect_timeout 30s 连接超时 transport.tcp.connect_timeout 30s 已弃用的连接超时 cluster.fault_detection.leader_check.timeout 10s 主节点检查超时 cluster." --- ## 配置项作用 `transport.connect_timeout` 配置项控制传输层客户端连接到其他节点的超时时间。当节点尝试连接到集群中的其他节点时,如果在此时间内未能建立连接,连接尝试将失败。此配置是已弃用的 `transport.tcp.connect_timeout` 配置的新名称。 ## 配置项类型 该配置项为**静态配置**,需要在启动时设置,修改后需要重启节点才能生效。 ## 默认值 ``` 30s ``` ## 是否必需 **可选配置项**(有默认值) ## 取值范围 ``` 时间格式配置(如 1s, 30s, 1m) ``` ## 配置格式 ```yaml # 默认配置 transport.connect_timeout: 30s # 缩短超时时间 transport.connect_timeout: 10s # 延长超时时间 transport.connect_timeout: 60s # 旧配置名称(已弃用) transport.tcp.connect_timeout: 30s ``` ## 相关配置项 | 配置项 | 默认值 | 说明 | |-------|-------|------| | `transport.connect_timeout` | 30s | 连接超时 | | `transport.tcp.connect_timeout` | 30s | 已弃用的连接超时 | | `cluster.fault_detection.leader_check.timeout` | 10s | 主节点检查超时 | | `cluster.fault_detection.follower_check.timeout` | 10s | 跟随节点检查超时 | ## 工作原理 连接超时机制: ``` ┌─────────────────────────────────────────────────────────────────┐ │ 传输层连接超时检测 │ └─────────────────────────────────────────────────────────────────┘ 节点 A 尝试连接节点 B │ ├── 开始计时 │ ├── 尝试建立 TCP 连接 │ │ │ ├── 网络延迟 │ ├── 防火墙处理 │ └── 路由跳数 │ ├── 时间 < connect_timeout │ │ │ └── 连接成功 ✓ │ └── 时间 >= connect_timeout │ └── 抛出 ConnectTimeoutException ✗ │ └── 连接失败 ``` ## 连接超时影响因素 ``` 影响连接时间的因素: 1. 网络延迟 本地网络: < 1ms 同城网络: 1-10ms 跨省网络: 10-100ms 跨国网络: 100-500ms 2. 防火墙 规则处理: 1-100ms 连接跟踪: 1-50ms NAT 转换: 1-100ms 3. 系统负载 CPU 负载高: 延迟增加 内存不足: 延迟增加 网络队列满: 延迟增加 4. 网络质量 丢包重传: 显著增加延迟 拥塞控制: 增加延迟 路由变化: 增加延迟 ``` ## 使用场景 ### 1. 默认配置(推荐) ```yaml transport.connect_timeout: 30s ``` 适用于大多数集群配置,提供合理的容错能力。 ### 2. 快速失败环境 ```yaml transport.connect_timeout: 10s ``` **适用场景:** - 高可用性要求 - 快速故障检测 - 节点快速切换 - 稳定网络环境 ### 3. 慢速网络环境 ```yaml transport.connect_timeout: 60s ``` **适用场景:** - 跨地域集群 - 网络不稳定 - 高延迟网络 - 复杂网络拓扑 ### 4. 最小超时 ```yaml transport.connect_timeout: 5s ``` **适用场景:** - 本地测试 - 高性能网络 - 快速故障检测 ## 推荐设置建议 | 网络环境 | 推荐值 | 说明 | |---------|-------|------| | 本地网络 | 10-30s | 快速连接 | | 同城集群 | 30s | 默认配置 | | 跨省集群 | 30-60s | 考虑延迟 | | 跨国集群 | 60-120s | 高延迟网络 | | 不稳定网络 | 60s+ | 容错优先 | ## 超时时间影响分析 ``` 短超时(10s): 优点: ✓ 快速检测故障 ✓ 快速切换节点 ✓ 减少等待时间 缺点: ✗ 可能误判正常节点 ✗ 网络抖动时容易超时 ✗ 高延迟环境不适合 长超时(60s): 优点: ✓ 容忍网络延迟 ✓ 减少误判 ✓ 适合不稳定网络 缺点: ✗ 故障检测慢 ✗ 恢复时间长 ✗ 可能影响可用性 ``` ## 故障场景分析 ``` 场景 1: 节点宕机 transport.connect_timeout: 30s 实际连接时间: 永远超时 结果: 30s 后超时 ✓ 合理 场景 2: 网络拥塞 transport.connect_timeout: 30s 实际连接时间: 25s 结果: 连接成功 ✓ 合理 场景 3: 跨国网络 transport.connect_timeout: 30s 实际连接时间: 45s 结果: 超时 ✗ 需要调整 场景 4: 防火墙延迟 transport.connect_timeout: 30s 实际连接时间: 20s 结果: 连接成功 ✓ 合理 ``` ## 连接超时与其他超时配置 ``` 超时配置体系: 1. transport.connect_timeout (30s) - 客户端连接超时 - TCP 连接建立阶段 - 首次连接检测 2. cluster.fault_detection.leader_check.timeout (10s) - 主节点检测超时 - 心跳检测 - 定期健康检查 3. cluster.fault_detection.follower_check.timeout (10s) - 跟随节点检测超时 - 主节点检查跟随者 - 定期健康检查 4. cluster.join.timeout (60s) - 节点加入集群超时 - 初始加入阶段 - 一次性操作 建议: connect_timeout 应该是最长的 给予网络连接足够时间 其他检测可以更激进 ``` ## 配置示例 ```yaml # 场景 1: 本地高性能集群 cluster.name: local-cluster network.host: 192.168.1.10 transport.connect_timeout: 10s # 场景 2: 跨地域集群 cluster.name: geo-cluster network.host: 10.0.0.10 transport.connect_timeout: 60s # 场景 3: 不稳定网络环境 cluster.name: wan-cluster network.host: 192.168.1.10 transport.connect_timeout: 90s ``` ## 监控建议 ```bash # 查看当前配置 GET /_nodes/settings?filter_path=nodes.*.transport # 查看连接统计 GET /_nodes/stats/transport # 查看节点连接信息 GET /_cat/nodes?v&h=name,transport* # 查看集群健康 GET /_cluster/health ``` ## 故障排查 ``` 连接超时问题排查: 1. 检查网络连通性 ping <目标节点> telnet <目标节点> 9300 2. 检查防火墙规则 iptables -L -n firewall-cmd --list-all 3. 检查端口监听 netstat -tuln | grep 9300 4. 检查系统日志 journalctl -u easysearch grep "ConnectTimeoutException" 5. 调整超时配置 如果网络确实较慢,适当增加超时时间 ``` ## 注意事项 1. **静态配置**:修改需要重启节点 2. **网络环境**:根据实际网络延迟调整 3. **误判风险**:过短的超时可能导致误判 4. **故障恢复**:过长的超时影响恢复速度 5. **测试验证**:实际环境中测试连接时间 6. **配置一致性**:集群内所有节点应保持一致