|
| 1 | +# Cascade Feature |
| 2 | + |
| 3 | +The cascade feature is an advanced capability of Monibuca that enables multiple Monibuca instances to establish cascading relationships, facilitating distributed deployment and load sharing of streaming media. Through the cascade feature, you can build multi-tier streaming media distribution networks, improving system scalability and reliability. |
| 4 | + |
| 5 | +## Key Features |
| 6 | + |
| 7 | +- **QUIC Protocol Communication**: High-performance, low-latency data transmission based on QUIC protocol |
| 8 | +- **Automatic Registration**: Lower-level nodes can automatically register with upper-level nodes |
| 9 | +- **Security Authentication**: Support for key-based security authentication mechanism |
| 10 | +- **Stream Forwarding**: Support for upstream and downstream forwarding of streaming media data |
| 11 | +- **Status Management**: Real-time monitoring of cascade node online status |
| 12 | +- **HTTP Proxy**: Support for cascaded forwarding of HTTP API requests |
| 13 | +- **Database Storage**: Persistent storage of cascade configuration information |
| 14 | +- **Access Control**: Fine-grained access control mechanism |
| 15 | + |
| 16 | +## Architecture Overview |
| 17 | + |
| 18 | +The cascade feature consists of two core components: |
| 19 | + |
| 20 | +### Cascade Server (CascadeServerPlugin) |
| 21 | +- Acts as an upper-level node, accepting connections from lower-level nodes |
| 22 | +- Manages registration and status of lower-level nodes |
| 23 | +- Provides stream forwarding and API proxy services |
| 24 | +- Supports automatic registration of lower-level nodes |
| 25 | + |
| 26 | +### Cascade Client (CascadeClientPlugin) |
| 27 | +- Acts as a lower-level node, connecting to upper-level nodes |
| 28 | +- Supports automatic stream pushing to upper-level nodes |
| 29 | +- Provides pull proxy functionality |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +### Cascade Server Configuration |
| 34 | + |
| 35 | +Configure the cascade server in the configuration file: |
| 36 | + |
| 37 | +```yaml |
| 38 | +cascade-server: |
| 39 | + # QUIC listening address configuration |
| 40 | + quic: |
| 41 | + listenaddr: ":44944" # Cascade server listening port |
| 42 | + |
| 43 | + # Whether to allow automatic registration of lower-level nodes |
| 44 | + autoregister: true # Default is true, allowing automatic registration |
| 45 | + |
| 46 | + # Access control configuration |
| 47 | + relayapi: |
| 48 | + enable: true # Whether to enable API forwarding |
| 49 | + whitelist: # IP whitelist |
| 50 | + - "192.168.1.0/24" |
| 51 | + - "10.0.0.0/8" |
| 52 | +``` |
| 53 | +
|
| 54 | +### Cascade Client Configuration |
| 55 | +
|
| 56 | +Configure the cascade client in the configuration file: |
| 57 | +
|
| 58 | +```yaml |
| 59 | +cascade-client: |
| 60 | + # Upper-level server address |
| 61 | + server: "192.168.1.100:44944" |
| 62 | + |
| 63 | + # Connection secret (optional) |
| 64 | + secret: "your-secret-key" |
| 65 | + |
| 66 | + # Whether to automatically push streams to upper level |
| 67 | + autopush: true |
| 68 | + |
| 69 | + # Access control configuration |
| 70 | + relayapi: |
| 71 | + enable: true |
| 72 | + whitelist: |
| 73 | + - "192.168.1.0/24" |
| 74 | +``` |
| 75 | +
|
| 76 | +### Detailed Configuration Options |
| 77 | +
|
| 78 | +#### Cascade Server Configuration Options |
| 79 | +
|
| 80 | +| Option | Type | Required | Default | Description | |
| 81 | +|--------|------|----------|---------|-------------| |
| 82 | +| quic.listenaddr | string | Yes | ":44944" | QUIC protocol listening address and port | |
| 83 | +| autoregister | boolean | No | true | Whether to allow automatic registration of lower-level nodes | |
| 84 | +| relayapi.enable | boolean | No | false | Whether to enable API forwarding functionality | |
| 85 | +| relayapi.whitelist | string array | No | [] | IP address whitelist for access | |
| 86 | +
|
| 87 | +#### Cascade Client Configuration Options |
| 88 | +
|
| 89 | +| Option | Type | Required | Default | Description | |
| 90 | +|--------|------|----------|---------|-------------| |
| 91 | +| server | string | Yes | - | Upper-level server address (IP:port) | |
| 92 | +| secret | string | No | - | Connection secret for authentication | |
| 93 | +| autopush | boolean | No | false | Whether to automatically push streams to upper-level node | |
| 94 | +| relayapi.enable | boolean | No | false | Whether to enable API forwarding functionality | |
| 95 | +| relayapi.whitelist | string array | No | [] | IP address whitelist for access | |
| 96 | +
|
| 97 | +## Deployment Architecture Examples |
| 98 | +
|
| 99 | +### Simple Two-Level Cascade |
| 100 | +
|
| 101 | +``` |
| 102 | +Upper Node (192.168.1.100:44944) |
| 103 | +├── Lower Node A (192.168.1.101) |
| 104 | +├── Lower Node B (192.168.1.102) |
| 105 | +└── Lower Node C (192.168.1.103) |
| 106 | +``` |
| 107 | + |
| 108 | +Configuration example: |
| 109 | + |
| 110 | +**Upper Node Configuration:** |
| 111 | +```yaml |
| 112 | +cascade-server: |
| 113 | + quic: |
| 114 | + listenaddr: ":44944" |
| 115 | + autoregister: true |
| 116 | +``` |
| 117 | +
|
| 118 | +**Lower Node Configuration:** |
| 119 | +```yaml |
| 120 | +cascade-client: |
| 121 | + server: "192.168.1.100:44944" |
| 122 | + autopush: true |
| 123 | +``` |
| 124 | +
|
| 125 | +### Multi-Level Cascade Architecture |
| 126 | +
|
| 127 | +``` |
| 128 | +Headquarters Node (HQ) |
| 129 | +├── Regional Node A (Region-A) |
| 130 | +│ ├── Edge Node A1 |
| 131 | +│ └── Edge Node A2 |
| 132 | +└── Regional Node B (Region-B) |
| 133 | + ├── Edge Node B1 |
| 134 | + └── Edge Node B2 |
| 135 | +``` |
| 136 | + |
| 137 | +## Feature Usage |
| 138 | + |
| 139 | +### Stream Forwarding |
| 140 | + |
| 141 | +When a lower-level node is configured with `autopush: true`, all streams published to the lower-level node will be automatically forwarded to the upper-level node. |
| 142 | + |
| 143 | +#### Manual Pull |
| 144 | + |
| 145 | +Lower-level nodes can also pull specific streams from upper-level nodes: |
| 146 | + |
| 147 | +```yaml |
| 148 | +cascade-client: |
| 149 | + server: "192.168.1.100:44944" |
| 150 | + # Configure pull rules |
| 151 | + pull: |
| 152 | + - streampath: "live/camera1" |
| 153 | + pullurl: "cascade://live/camera1" |
| 154 | +``` |
| 155 | +
|
| 156 | +### API Forwarding |
| 157 | +
|
| 158 | +After enabling API forwarding functionality, you can access lower-level node APIs through the cascade server: |
| 159 | +
|
| 160 | +```http |
| 161 | +GET /api/relay/{instanceId}/api/stream/list |
| 162 | +``` |
| 163 | + |
| 164 | +Where `{instanceId}` is the instance ID of the lower-level node. |
| 165 | + |
| 166 | +## API Interfaces |
| 167 | + |
| 168 | +The cascade server provides comprehensive management APIs: |
| 169 | + |
| 170 | +### Get Lower-Level Node List |
| 171 | + |
| 172 | +```http |
| 173 | +GET /api/cascade/clients |
| 174 | +``` |
| 175 | + |
| 176 | +**Response Example:** |
| 177 | +```json |
| 178 | +{ |
| 179 | + "code": 0, |
| 180 | + "message": "success", |
| 181 | + "data": [ |
| 182 | + { |
| 183 | + "id": 1, |
| 184 | + "name": "edge-node-1", |
| 185 | + "ip": "192.168.1.101", |
| 186 | + "online": true, |
| 187 | + "created_time": "2025-01-01T00:00:00Z", |
| 188 | + "updated_time": "2025-01-01T12:00:00Z" |
| 189 | + } |
| 190 | + ] |
| 191 | +} |
| 192 | +``` |
| 193 | + |
| 194 | +### Create Lower-Level Node |
| 195 | + |
| 196 | +```http |
| 197 | +POST /api/cascade/clients |
| 198 | +Content-Type: application/json |
| 199 | +
|
| 200 | +{ |
| 201 | + "name": "edge-node-2", |
| 202 | + "secret": "node-secret-key" |
| 203 | +} |
| 204 | +``` |
| 205 | + |
| 206 | +### Update Lower-Level Node |
| 207 | + |
| 208 | +```http |
| 209 | +PUT /api/cascade/clients/{id} |
| 210 | +Content-Type: application/json |
| 211 | +
|
| 212 | +{ |
| 213 | + "name": "updated-node-name", |
| 214 | + "secret": "new-secret-key" |
| 215 | +} |
| 216 | +``` |
| 217 | + |
| 218 | +### Delete Lower-Level Node |
| 219 | + |
| 220 | +```http |
| 221 | +DELETE /api/cascade/clients/{id} |
| 222 | +``` |
| 223 | + |
| 224 | +## Security Configuration |
| 225 | + |
| 226 | +### Key Authentication |
| 227 | + |
| 228 | +For enhanced security, it's recommended to configure unique keys for each lower-level node: |
| 229 | + |
| 230 | +**Server-side client creation:** |
| 231 | +```bash |
| 232 | +curl -X POST http://server:8080/api/cascade/clients \ |
| 233 | + -H "Content-Type: application/json" \ |
| 234 | + -d '{"name": "edge-node-1", "secret": "unique-secret-key"}' |
| 235 | +``` |
| 236 | + |
| 237 | +**Client-side corresponding key configuration:** |
| 238 | +```yaml |
| 239 | +cascade-client: |
| 240 | + server: "server:44944" |
| 241 | + secret: "unique-secret-key" |
| 242 | +``` |
| 243 | +
|
| 244 | +### Network Security |
| 245 | +
|
| 246 | +1. **Firewall Configuration**: Ensure only necessary ports are open |
| 247 | +2. **VPN/Dedicated Lines**: Use VPN or dedicated connections in public network environments |
| 248 | +3. **IP Whitelist**: Configure access control whitelists |
| 249 | +
|
| 250 | +## Monitoring and Operations |
| 251 | +
|
| 252 | +### Status Monitoring |
| 253 | +
|
| 254 | +Real-time cascade status monitoring through API interfaces: |
| 255 | +
|
| 256 | +```bash |
| 257 | +# Check all lower-level node status |
| 258 | +curl http://server:8080/api/cascade/clients |
| 259 | + |
| 260 | +# Access lower-level node APIs through proxy |
| 261 | +curl http://server:8080/api/relay/1/api/stream/list |
| 262 | +``` |
| 263 | + |
| 264 | +### Log Monitoring |
| 265 | + |
| 266 | +Cascade-related logs will include the following key information: |
| 267 | +- Node connection and disconnection events |
| 268 | +- Authentication success and failure records |
| 269 | +- Stream forwarding status |
| 270 | +- Error and exception information |
| 271 | + |
| 272 | +### Performance Tuning |
| 273 | + |
| 274 | +1. **QUIC Parameter Tuning**: Adjust QUIC connection parameters based on network environment |
| 275 | +2. **Concurrency Control**: Set reasonable maximum connection limits |
| 276 | +3. **Buffer Optimization**: Adjust buffer sizes based on bandwidth |
| 277 | + |
| 278 | +## Troubleshooting |
| 279 | + |
| 280 | +### Common Issues |
| 281 | + |
| 282 | +1. **Connection Failure** |
| 283 | + - Check network connectivity |
| 284 | + - Confirm if ports are open |
| 285 | + - Verify key configuration |
| 286 | + |
| 287 | +2. **Authentication Failure** |
| 288 | + - Check if key is correct |
| 289 | + - Confirm if server allows automatic registration |
| 290 | + |
| 291 | +3. **Stream Forwarding Issues** |
| 292 | + - Check stream path configuration |
| 293 | + - Confirm if network bandwidth is sufficient |
| 294 | + - Review related error logs |
| 295 | + |
| 296 | +### Debug Mode |
| 297 | + |
| 298 | +Enable debug logging for more detailed information: |
| 299 | + |
| 300 | +```yaml |
| 301 | +log: |
| 302 | + level: debug |
| 303 | +``` |
| 304 | +
|
| 305 | +## Best Practices |
| 306 | +
|
| 307 | +1. **Network Planning**: Plan cascade network topology reasonably to avoid single points of failure |
| 308 | +2. **Load Balancing**: Distribute load across multiple upper-level nodes |
| 309 | +3. **Monitoring and Alerting**: Set up node status monitoring and alerting mechanisms |
| 310 | +4. **Regular Maintenance**: Regularly clean up offline nodes and expired data |
| 311 | +5. **Security Updates**: Update keys and security configurations timely |
| 312 | +
|
| 313 | +## Important Notes |
| 314 | +
|
| 315 | +1. **Version Compatibility**: Ensure upper and lower nodes use compatible Monibuca versions |
| 316 | +2. **Clock Synchronization**: Keep node clocks synchronized to avoid timestamp issues |
| 317 | +3. **Resource Limits**: Configure resource limits reasonably to prevent cascade storms |
| 318 | +4. **Data Consistency**: Pay attention to data consistency in multi-level cascades |
| 319 | +
|
| 320 | +Through the cascade feature, Monibuca can build large-scale, highly available distributed streaming media networks to meet deployment requirements in various scenarios. |
0 commit comments