OpenLoadBalancer/olb
GitHub: OpenLoadBalancer/olb
一款用Go编写的高性能零依赖L4/L7负载均衡器,集成WAF防护和AI驱动的MCP管理能力。
Stars: 16 | Forks: 3
# OpenLoadBalancer
## E2E 验证
56 个端到端测试证明每个功能在真实代理场景中均有效:
| 类别 | 已验证 |
|----------|----------|
| **代理** | HTTP, HTTPS/TLS, WebSocket, SSE, TCP, UDP |
| **算法** | RR, WRR, LC, IPHash, CH, Maglev, P2C, Random, RingHash |
| **中间件** | 限速 (429), CORS, gzip (98% 压缩率), WAF 6 层 (SQLi/XSS/CMDi/路径遍历 → 403, 限速 → 429, 监控模式, 安全标头, 机器人检测, IP ACL, 数据脱敏), IP 过滤, 断路器, 缓存 (HIT/MISS), 标头, 重试 |
| **运维** | 健康检查 (宕机/恢复), 配置重载, 加权分配, 会话亲和, 优雅故障转移 (0 宕机时间) |
| **基础设施** | Admin API, Web UI, Prometheus, MCP server, 多监听器 |
| **性能** | 15K RPS, 137µs 代理开销, 100% 成功率 |
## 算法
| 算法 | 配置名称 | 用例 |
|-----------|------------|----------|
| Round Robin | `round_robin` | 默认,后端同等 |
| Weighted Round Robin | `weighted_round_robin` | 后端容量不均 |
| Least Connections | `least_connections` | 长连接 |
| Least Response Time | `least_response_time` | 延迟敏感 |
| IP Hash | `ip_hash` | 按 IP 的会话亲和 |
| Consistent Hash | `consistent_hash` | 缓存局部性 |
| Maglev | `maglev` | Google 风格哈希 |
| Ring Hash | `ring_hash` | 带虚拟节点的一致性哈希 |
| Power of Two | `power_of_two` | 平衡随机 |
| Random | `random` | 简单,无状态 |
## 配置
支持 **YAML**, **JSON**, **TOML**, 和 **HCL**,并支持 `${ENV_VAR}` 替换。
```
admin:
address: "127.0.0.1:8081"
middleware:
rate_limit:
enabled: true
requests_per_second: 1000
cors:
enabled: true
allowed_origins: ["*"]
compression:
enabled: true
waf:
enabled: true
mode: enforce
detection:
enabled: true
threshold: {block: 50, log: 25}
bot_detection: {enabled: true, mode: monitor}
response:
security_headers: {enabled: true}
listeners:
- name: http
address: ":8080"
routes:
- path: /api
pool: api-pool
- path: /
pool: web-pool
pools:
- name: web-pool
algorithm: round_robin
backends:
- address: "10.0.1.10:8080"
- address: "10.0.1.11:8080"
health_check:
type: http
path: /health
interval: 5s
- name: api-pool
algorithm: least_connections
backends:
- address: "10.0.2.10:8080"
weight: 3
- address: "10.0.2.11:8080"
weight: 2
```
参见 [docs/configuration.md](docs/configuration.md) 获取所有选项。
### Geo-DNS 路由示例
```
geodns:
enabled: true
default_pool: default-pool
rules:
- id: us-traffic
country: US
pool: us-pool
fallback: default-pool
- id: eu-traffic
country: EU
pool: eu-pool
- id: asia-traffic
country: JP
region: Tokyo
pool: asia-pool
```
### 请求影子化示例
```
shadow:
enabled: true
percentage: 10.0 # Mirror 10% of traffic
copy_headers: true
copy_body: false
timeout: 30s
targets:
- pool: staging-pool
percentage: 100.0
```
### 分布式限速示例
```
waf:
enabled: true
rate_limit:
enabled: true
store:
type: redis
address: "localhost:6379"
database: 0
rules:
- id: per-ip
scope: ip
limit: 1000
window: 1m
```
## CLI
```
olb start --config olb.yaml # Start proxy
olb stop # Graceful shutdown
olb reload # Hot-reload config
olb status # Server status
olb top # Live TUI dashboard
olb backend list # List backends
olb backend drain web-pool 10.0.1.10:8080
olb health show # Health check status
olb config validate olb.yaml # Validate config
olb cluster status # Cluster info
```
## 架构
```
┌─────────────────────────────────────────────────┐
│ OpenLoadBalancer │
Clients ─────────┤ │
HTTP/S, WS, │ Listeners → Middleware → Router → Balancer → Backends
gRPC, TCP, UDP │ (L4/L7) (16 types) (trie) (14 algos) │
│ │
│ WAF (6 layers) │ TLS │ Cluster │ MCP │ Web UI │
│ GeoDNS │ Shadow │ Discovery │ Prometheus │
└─────────────────────────────────────────────────┘
```
## 文档
| 指南 | 描述 |
|-------|-------------|
| [Getting Started](docs/getting-started.md) | 5 分钟快速开始 |
| [Configuration](docs/configuration.md) | 所有配置选项 |
| [Production Deployment](docs/production-deployment.md) | 生产部署指南 |
| [Troubleshooting](docs/troubleshooting.md) | 故障排除手册 |
| [Algorithms](docs/algorithms.md) | 算法详情 |
| [API Reference](docs/api.md) | Admin REST API |
| [Clustering](docs/clustering.md) | 多节点设置 |
| [WAF](docs/waf.md) | Web Application Firewall (6 层防御) |
| [MCP / AI](docs/mcp.md) | AI 集成 |
| [Benchmarks](docs/benchmark-report.md) | 性能数据 |
| [Specification](docs/SPECIFICATION.md) | 技术规范 |
## 贡献
参见 [CONTRIBUTING.md](CONTRIBUTING.md)。关键规则:
1. **零外部依赖** — 仅限 stdlib
2. **必须包含测试** — 90% 覆盖率,不要降低它
3. **所有功能已连接** — engine.go 中无死代码
4. **gofmt + go vet** — CI 强制执行
## 许可证
Apache 2.0 — [LICENSE](LICENSE)
算法比较(1000 请求, 50 并发)
| 算法 | RPS | 平均延迟 | 分布 | |-----------|-----|-------------|-------------| | random | 12,913 | 3.5ms | 32/34/34% | | maglev | 11,597 | 3.8ms | 68/2/30% | | ip_hash | 11,062 | 4.0ms | 75/12/13% | | power_of_two | 10,708 | 4.0ms | 34/33/33% | | least_connections | 10,119 | 4.4ms | 33/33/34% | | consistent_hash | 8,897 | 4.6ms | 0/0/100% | | weighted_rr | 8,042 | 5.6ms | 33/33/34% | | round_robin | 7,320 | 6.3ms | 35/33/32% |完整基准测试报告
参见 [docs/benchmark-report.md](docs/benchmark-report.md) 获取完整报告,包括并发扩展、后端延迟影响和中间件开销测量。标签:AI集成, Docker, EVTX分析, Go语言, HTTP代理, L4负载均衡, L7负载均衡, MCP, Python工具, Web管理界面, 健康检查, 单二进制, 反向代理, 安全防御评估, 密码管理, 开源, 日志审计, 流量管理, 程序破解, 系统工具, 网络基础设施, 自定义请求头, 请求拦截, 负载均衡, 轮询算法, 配置错误, 集群, 零依赖