Skip to content

Commit 3090349

Browse files
authored
docs: add support for target address group to enable load balancing and high availability
1 parent 5260464 commit 3090349

File tree

4 files changed

+278
-15
lines changed

4 files changed

+278
-15
lines changed

docs/en/configuration.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,63 @@ nodepass "server://0.0.0.0:10101/0.0.0.0:8080?log=info&tls=1&proxy=1&rate=100"
264264
- The header format follows the HAProxy PROXY protocol v1 specification
265265
- If the target service doesn't support PROXY protocol, connections may fail or behave unexpectedly
266266

267+
## Target Address Groups and Load Balancing
268+
269+
NodePass supports configuring multiple target addresses to achieve high availability and load balancing. Target address groups are only applicable to the egress side (the final destination of traffic) and should not be used on the ingress side.
270+
271+
### Target Address Group Configuration
272+
273+
Target address groups are configured by separating multiple addresses with commas. NodePass automatically performs round-robin and failover across these addresses:
274+
275+
```bash
276+
# Server with multiple backend targets (forward mode, mode=2)
277+
nodepass "server://0.0.0.0:10101/backend1.example.com:8080,backend2.example.com:8080,backend3.example.com:8080?mode=2&tls=1"
278+
279+
# Client with multiple local services (single-end forwarding mode, mode=1)
280+
nodepass "client://127.0.0.1:1080/app1.local:8080,app2.local:8080?mode=1"
281+
```
282+
283+
### Rotation Strategy
284+
285+
NodePass employs a Round-Robin algorithm that combines failover and load balancing features:
286+
287+
- **Load Balancing**: After each successful connection establishment, automatically switches to the next target address for even traffic distribution
288+
- **Failover**: When a connection to an address fails, immediately tries the next address to ensure service availability
289+
- **Automatic Recovery**: Failed addresses are retried in subsequent rotation cycles and automatically resume receiving traffic after recovery
290+
291+
### Use Cases
292+
293+
Target address groups are suitable for the following scenarios:
294+
295+
- **High Availability Deployment**: Multiple backend servers for automatic failover
296+
- **Load Balancing**: Even traffic distribution across multiple backend instances
297+
- **Canary Releases**: Gradually shifting traffic to new service versions
298+
- **Geographic Distribution**: Selecting optimal paths based on network topology
299+
300+
### Important Notes
301+
302+
- **Egress Only**: Target address groups can only be configured at the final traffic destination
303+
- ✓ Server forward mode (mode=2): `server://0.0.0.0:10101/target1:80,target2:80`
304+
- ✓ Client single-end forwarding mode (mode=1): `client://127.0.0.1:1080/target1:80,target2:80`
305+
- ✗ Tunnel addresses do not support: Do not use multi-address configuration for tunnel addresses
306+
307+
- **Address Format**: All addresses must use the same port or explicitly specify the port for each address
308+
- **Protocol Consistency**: All addresses in the group must support the same protocol (TCP/UDP)
309+
- **Thread Safety**: Rotation index uses atomic operations, supporting high-concurrency scenarios
310+
311+
Example configurations:
312+
313+
```bash
314+
# Correct example: Server with 3 backend web servers
315+
nodepass "server://0.0.0.0:10101/web1.internal:8080,web2.internal:8080,web3.internal:8080?mode=2&log=info"
316+
317+
# Correct example: Client with 2 local database instances
318+
nodepass "client://127.0.0.1:3306/db-primary.local:3306,db-secondary.local:3306?mode=1&log=warn"
319+
320+
# Incorrect example: Do not use multi-address for tunnel addresses (will cause parsing errors)
321+
# nodepass "server://host1:10101,host2:10101/target:8080" # ✗ Wrong usage
322+
```
323+
267324
## URL Query Parameter Scope and Applicability
268325

269326
NodePass allows flexible configuration via URL query parameters. The following table shows which parameters are applicable in server, client, and master modes:

docs/en/examples.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,84 @@ This setup:
235235
- Enables developers to access environments without direct network exposure
236236
- Maps remote services to different local ports for easy identification
237237

238+
## High Availability and Load Balancing
239+
240+
### Example 14: Multi-Backend Server Load Balancing
241+
242+
Use target address groups for even traffic distribution and automatic failover:
243+
244+
```bash
245+
# Server side: Configure 3 backend web servers
246+
nodepass "server://0.0.0.0:10101/web1.internal:8080,web2.internal:8080,web3.internal:8080?mode=2&tls=1&log=info"
247+
248+
# Client side: Connect to server
249+
nodepass "client://server.example.com:10101/127.0.0.1:8080?log=info"
250+
```
251+
252+
This configuration:
253+
- Automatically distributes traffic across 3 backend servers using round-robin for load balancing
254+
- Automatically switches to other available servers when one backend fails
255+
- Automatically resumes sending traffic to recovered servers
256+
- Uses TLS encryption to secure the tunnel
257+
258+
### Example 15: Database Primary-Replica Failover
259+
260+
Configure primary and replica database instances for high availability access:
261+
262+
```bash
263+
# Client side: Configure primary and replica database addresses (single-end forwarding mode)
264+
nodepass "client://127.0.0.1:3306/db-primary.local:3306,db-secondary.local:3306?mode=1&log=warn"
265+
```
266+
267+
This setup:
268+
- Prioritizes connections to primary database, automatically switches to replica on primary failure
269+
- Single-end forwarding mode provides high-performance local proxy
270+
- Application requires no modification for transparent failover
271+
- Logs only warnings and errors to reduce output
272+
273+
### Example 16: API Gateway Backend Pool
274+
275+
Configure multiple backend service instances for an API gateway:
276+
277+
```bash
278+
# Server side: Configure 4 API service instances
279+
nodepass "server://0.0.0.0:10101/api1.backend:8080,api2.backend:8080,api3.backend:8080,api4.backend:8080?mode=2&tls=1&rate=200&slot=5000"
280+
281+
# Client side: Connect from API gateway
282+
nodepass "client://apigateway.example.com:10101/127.0.0.1:8080?rate=100&slot=2000"
283+
```
284+
285+
This configuration:
286+
- 4 API service instances form backend pool with round-robin request distribution
287+
- Server limits bandwidth to 200 Mbps with maximum 5000 concurrent connections
288+
- Client limits bandwidth to 100 Mbps with maximum 2000 concurrent connections
289+
- Single instance failure doesn't affect overall service availability
290+
291+
### Example 17: Geo-Distributed Services
292+
293+
Configure multi-region service nodes to optimize network latency:
294+
295+
```bash
296+
# Server side: Configure multi-region nodes
297+
nodepass "server://0.0.0.0:10101/us-west.service:8080,us-east.service:8080,eu-central.service:8080?mode=2&log=debug"
298+
```
299+
300+
This setup:
301+
- Configures 3 service nodes in different regions
302+
- Round-robin algorithm automatically distributes traffic across regions
303+
- Debug logging helps analyze traffic distribution and failure scenarios
304+
- Suitable for globally distributed application scenarios
305+
306+
**Target Address Group Best Practices:**
307+
- **Address Count**: Recommend configuring 2-5 addresses; too many increases failure detection time
308+
- **Health Checks**: Ensure backend services have their own health check mechanisms
309+
- **Port Consistency**: All addresses use the same port or explicitly specify port for each address
310+
- **Monitoring & Alerts**: Configure monitoring systems to track failover events
311+
- **Testing & Validation**: Verify failover and load balancing behavior in test environments before deployment
312+
238313
## PROXY Protocol Integration
239314

240-
### Example 14: Load Balancer Integration with PROXY Protocol
315+
### Example 18: Load Balancer Integration with PROXY Protocol
241316

242317
Enable PROXY protocol support for integration with load balancers and reverse proxies:
243318

@@ -256,7 +331,7 @@ This configuration:
256331
- Compatible with HAProxy, Nginx, and other PROXY protocol aware services
257332
- Useful for maintaining accurate access logs and IP-based access controls
258333

259-
### Example 15: Reverse Proxy Support for Web Applications
334+
### Example 19: Reverse Proxy Support for Web Applications
260335

261336
Enable web applications behind NodePass to receive original client information:
262337

@@ -280,7 +355,7 @@ This setup:
280355
- Supports compliance requirements for connection auditing
281356
- Works with web servers that support PROXY protocol (Nginx, HAProxy, etc.)
282357

283-
### Example 16: Database Access with Client IP Preservation
358+
### Example 20: Database Access with Client IP Preservation
284359

285360
Maintain client IP information for database access logging and security:
286361

@@ -307,7 +382,7 @@ Benefits:
307382

308383
## Container Deployment
309384

310-
### Example 17: Containerized NodePass
385+
### Example 21: Containerized NodePass
311386

312387
Deploy NodePass in a Docker environment:
313388

@@ -342,7 +417,7 @@ This configuration:
342417

343418
## Master API Management
344419

345-
### Example 18: Centralized Management
420+
### Example 22: Centralized Management
346421

347422
Set up a central controller for multiple NodePass instances:
348423

@@ -379,7 +454,7 @@ This setup:
379454
- Offers a RESTful API for automation and integration
380455
- Includes a built-in Swagger UI at http://localhost:9090/api/v1/docs
381456

382-
### Example 19: Custom API Prefix
457+
### Example 23: Custom API Prefix
383458

384459
Use a custom API prefix for the master mode:
385460

@@ -398,7 +473,7 @@ This allows:
398473
- Custom URL paths for security or organizational purposes
399474
- Swagger UI access at http://localhost:9090/admin/v1/docs
400475

401-
### Example 20: Real-time Connection and Traffic Monitoring
476+
### Example 24: Real-time Connection and Traffic Monitoring
402477

403478
Monitor instance connection counts and traffic statistics through the master API:
404479

docs/zh/configuration.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,63 @@ nodepass "server://0.0.0.0:10101/0.0.0.0:8080?log=info&tls=1&proxy=1&rate=100"
264264
- 头部格式遵循HAProxy PROXY协议v1规范
265265
- 如果目标服务不支持PROXY协议,将导致连接失败
266266

267+
## 目标地址组与负载均衡
268+
269+
NodePass支持配置多个目标地址以实现高可用性和负载均衡。目标地址组功能仅适用于出口端(流量最终到达的目的地),不应在入口端使用。
270+
271+
### 目标地址组配置
272+
273+
目标地址组通过逗号分隔多个地址来配置,NodePass会自动在这些地址之间进行轮询和故障转移:
274+
275+
```bash
276+
# 服务端配置多个后端目标(正向模式,mode=2)
277+
nodepass "server://0.0.0.0:10101/backend1.example.com:8080,backend2.example.com:8080,backend3.example.com:8080?mode=2&tls=1"
278+
279+
# 客户端配置多个本地服务(单端转发模式,mode=1)
280+
nodepass "client://127.0.0.1:1080/app1.local:8080,app2.local:8080?mode=1"
281+
```
282+
283+
### 轮询策略
284+
285+
NodePass采用轮询(Round-Robin)算法,结合故障转移和负载均衡特性:
286+
287+
- **负载均衡**:每次成功建立连接后,自动切换到下一个目标地址,实现流量均匀分布
288+
- **故障转移**:当某个地址连接失败时,立即尝试下一个地址,确保服务高可用
289+
- **自动恢复**:失败的地址会在轮询周期中重新尝试,故障恢复后自动接入流量
290+
291+
### 使用场景
292+
293+
目标地址组适用于以下场景:
294+
295+
- **高可用性部署**:多个后端服务器实现故障自动切换
296+
- **负载均衡**:流量均匀分布到多个后端实例
297+
- **灰度发布**:逐步将流量切换到新版本服务
298+
- **地域分布**:根据网络拓扑选择最优路径
299+
300+
### 重要说明
301+
302+
- **仅适用于出口**:目标地址组只能配置在流量的最终目的地
303+
- ✓ 服务端正向模式(mode=2):`server://0.0.0.0:10101/target1:80,target2:80`
304+
- ✓ 客户端单端转发模式(mode=1):`client://127.0.0.1:1080/target1:80,target2:80`
305+
- ✗ 隧道地址不支持:不要在隧道地址使用多地址配置
306+
307+
- **地址格式**:所有地址必须使用相同的端口或明确指定每个地址的端口
308+
- **协议一致性**:地址组中的所有地址必须支持相同的协议(TCP/UDP)
309+
- **线程安全**:轮询索引使用原子操作,支持高并发场景
310+
311+
示例配置:
312+
313+
```bash
314+
# 正确示例:服务端配置3个后端Web服务器
315+
nodepass "server://0.0.0.0:10101/web1.internal:8080,web2.internal:8080,web3.internal:8080?mode=2&log=info"
316+
317+
# 正确示例:客户端配置2个本地数据库实例
318+
nodepass "client://127.0.0.1:3306/db-primary.local:3306,db-secondary.local:3306?mode=1&log=warn"
319+
320+
# 错误示例:不要在隧道地址使用多地址(会导致解析错误)
321+
# nodepass "server://host1:10101,host2:10101/target:8080" # ✗ 错误用法
322+
```
323+
267324
## URL查询参数配置及作用范围
268325

269326
NodePass支持通过URL查询参数进行灵活配置,不同参数在 server、client、master 模式下的适用性如下表:
@@ -282,7 +339,6 @@ NodePass支持通过URL查询参数进行灵活配置,不同参数在 server
282339
| `slot` | 最大连接数限制 | `65536` | O | O | X |
283340
| `proxy` | PROXY协议支持 | `0` | O | O | X |
284341

285-
286342
- O:参数有效,推荐根据实际场景配置
287343
- X:参数无效,忽略设置
288344

0 commit comments

Comments
 (0)