本文档详细说明了 Mo Gateway 的配置选项。
server:
port: 8080
ssl:
enabled: false
key-store: classpath:keystore.p12
key-store-password: your-password
key-store-type: PKCS12
http2:
enabled: true
compression:
enabled: true
mime-types: application/json,application/xml,text/html,text/xml,text/plainspring:
application:
name: gateway-service
profiles:
active: devgateway:
ratelimit:
enabled: true
default-algorithm: tokenBucket
default-capacity: 1000
default-refill-rate: 100
default-window-size-ms: 60000
fail-open: true
service-strategies:
your-service:
capacity: 2000
refill-rate: 200
algorithm: slidingWindowgateway:
loadbalancer:
default-strategy: roundRobin
health-check-interval-ms: 30000
connection-timeout-ms: 5000
read-timeout-ms: 10000
enable-circuit-breaker: true
service-strategies:
your-service:
type: weightedRoundRobin
weights:
instance1: 2
instance2: 1gateway:
discovery:
type: kubernetes
kubernetes:
namespace: services
label-selector: gateway.enabled=true
service-port: 8080
health-check-path: /actuator/healthgateway:
discovery:
type: memory
services:
- name: your-service
instances:
- host: localhost
port: 8081
weight: 1
- host: localhost
port: 8082
weight: 2management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
show-details: always
metrics:
tags:
application: ${spring.application.name}logging:
level:
com.mo.gateway: INFO
org.springframework.web: INFO
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
file:
name: logs/gateway.log支持通过环境变量覆盖默认配置:
| 环境变量 | 说明 | 默认值 |
|---|---|---|
| SPRING_PROFILES_ACTIVE | 激活的配置文件 | dev |
| REDIS_HOST | Redis 主机地址 | localhost |
| REDIS_PORT | Redis 端口 | 6379 |
| GATEWAY_RATELIMIT_ENABLED | 是否启用限流 | true |
| GATEWAY_RATELIMIT_CAPACITY | 限流容量 | 1000 |
| GATEWAY_RATELIMIT_REFILL_RATE | 限流补充速率 | 100 |
| GATEWAY_DISCOVERY_TYPE | 服务发现类型 | memory |
| GATEWAY_LOG_LEVEL | 日志级别 | INFO |
- 根据服务容量设置合理的限流阈值
- 使用 fail-open 模式保证系统可用性
- 为不同服务配置不同的限流策略
- 根据服务特性选择合适的负载均衡算法
- 配置合理的健康检查间隔
- 设置适当的超时时间
- 启用详细的健康检查
- 配置合适的日志级别
- 添加必要的监控标签
访问配置检查端点:
curl http://localhost:8080/actuator/configprops访问环境变量端点:
curl http://localhost:8080/actuator/env- 检查配置文件位置是否正确
- 确认配置项名称是否正确
- 验证环境变量是否正确设置
- 检查不同配置文件中的配置项
- 确认配置优先级
- 查看配置合并结果