配置
MynaDB 通过 config.toml 文件进行配置。如果该文件不存在,将使用默认值。本指南详细介绍所有可用选项。
完整示例
# config.toml - MynaDB Configuration
[server]
http_port = 7000
flight_port = 7001
[storage]
data_dir = "/data0/stats/data"
[schema]
strategy = "service_as_schema"
tag_keys = ["MONITOR.service", "hierarchy_2", "service"]
default_name = "default"
prefix_numeric = true
[cache]
flush_interval_secs = 30
[compaction]
min_files = 4
max_level = 5
max_concurrent_compactions = 8
full_compaction_max_concurrent = 2
[retention]
enabled = true
default_days = 7
interval_secs = 3600
exclude_databases = ["_system"]
服务器
网络和服务器设置。
[server]
http_port = 7000 # HTTP REST API port
flight_port = 7001 # Arrow Flight gRPC port
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
http_port |
整数 | 7000 | HTTP REST API 端口 |
flight_port |
整数 | 7001 | Arrow Flight gRPC 端口 |
存储
数据存储位置。
[storage]
data_dir = "/data0/stats/data" # Root directory for data
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
data_dir |
字符串 | "./data" | Parquet 文件的根目录 |
⚠ 重要提示
请确保数据目录有足够的磁盘空间和适当的权限。使用 SSD 存储可获得最佳性能。
Schema 映射
控制 InfluxDB 数据如何映射到 catalog.schema.table 结构。
[schema]
strategy = "service_as_schema" # or "service_as_table"
tag_keys = ["MONITOR.service", "hierarchy_2", "service"]
default_name = "default"
prefix_numeric = true
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
strategy |
字符串 | "service_as_schema" | 命名策略(详见下方) |
tag_keys |
数组 | ["service"] | 用于提取服务名的标签键 |
default_name |
字符串 | "default" | 默认 schema/table 名称 |
prefix_numeric |
布尔值 | true | 为数字值添加 "service_" 前缀 |
策略:service_as_schema
- Schema = 服务标签值
- Table = 指标名称(measurement)
- 适用于多租户场景
示例:cpu,service=web → mydb.web.cpu
策略:service_as_table
- Schema = "default"(固定)
- Table = 服务标签值
- 指标名称存储为列
示例:cpu,service=web → mydb.default.web
缓存
内存写入缓冲区设置。
[cache]
flush_interval_secs = 30 # Flush to disk every 30 seconds
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
flush_interval_secs |
整数 | 30 | 自动刷盘间隔(秒) |
💡 提示
较小的值可减少数据丢失风险,但会增加 I/O 负载。较大的值可提高写入性能,但会增加内存使用。
压缩合并
LSM 风格的压缩合并设置。
[compaction]
min_files = 4 # Trigger when 4+ files at a level
max_level = 5 # Maximum compaction level (L0-L5)
max_concurrent_compactions = 8 # Parallel LSM compactions
full_compaction_max_concurrent = 2 # Parallel full compactions
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
min_files |
整数 | 4 | 触发压缩合并所需的文件数 |
max_level |
整数 | 5 | 最大压缩合并级别 |
max_concurrent_compactions |
整数 | 8 | 并行 LSM 压缩合并数 |
full_compaction_max_concurrent |
整数 | 2 | 并行全量压缩合并数(降低以避免 OOM) |
数据保留
自动数据过期设置。
[retention]
enabled = true # Enable background retention
default_days = 7 # Delete data older than 7 days
interval_secs = 3600 # Check every hour
exclude_databases = ["_system"] # Skip these databases
exclude_tables = ["mydb.default.important"] # Skip these tables
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enabled |
布尔值 | true | 启用自动数据保留 |
default_days |
整数 | 7 | 数据保留天数 |
interval_secs |
整数 | 3600 | 检查间隔(秒) |
exclude_databases |
数组 | [] | 跳过的数据库 |
exclude_tables |
数组 | [] | 跳过的表(catalog.schema.table 格式) |
OpenTelemetry (OTLP)
原生 OpenTelemetry 接入设置。详见 OTLP 文档。
[otlp]
enabled = false # Enable OTLP ingestion
grpc_port = 4317 # OTLP gRPC port
http_enabled = true # Enable OTLP HTTP endpoints
metrics_database = "otel_metrics" # Target database for metrics
logs_database = "otel_logs" # Target database for logs
traces_database = "otel_traces" # Target database for traces
Apache Iceberg
Iceberg REST Catalog API 设置。详见 Iceberg 文档。
[iceberg]
enabled = false # Enable Iceberg REST Catalog
catalog_name = "mynadb" # Catalog name exposed to engines
sync_interval_secs = 60 # Metadata sync interval
metadata_location = "data/iceberg" # Iceberg metadata directory
流式查询
实时查询订阅设置。详见流式查询文档。
[streaming]
enabled = false # Enable streaming queries
max_subscriptions = 100 # Max concurrent subscriptions
heartbeat_interval_secs = 30 # WebSocket heartbeat interval
buffer_size = 1000 # Event buffer size per subscription
持续聚合
物化视图和降采样设置。详见持续聚合文档。
[continuous_aggregates]
enabled = false # Enable continuous aggregates
refresh_check_interval_secs = 60 # Check for refresh every 60s
max_concurrent_refreshes = 4 # Parallel refresh jobs
query_rewriting_enabled = true # Auto-rewrite queries to use aggregates
TLS / SSL
传输层安全设置。详见安全文档。
[tls]
enabled = false # Enable TLS
cert_file = "/etc/mynadb/tls/cert.pem"
key_file = "/etc/mynadb/tls/key.pem"
ca_file = "/etc/mynadb/tls/ca.pem" # For mutual TLS (optional)
mutual_auth = false # Require client certificates
审计日志
用于合规的审计追踪设置。详见安全文档。
[audit]
enabled = false # Enable audit logging
log_file = "/var/log/mynadb/audit.log"
rotation = "daily" # "daily", "hourly", or "size"
max_files = 30 # Rotated files to keep
管理控制台
基于 Web 的管理界面设置。详见管理控制台文档。
[admin]
enabled = false # Enable admin console
port = 18080 # Admin HTTP port
meta_endpoints = ["localhost:6001"] # Meta service endpoints for cluster mode
环境变量
配置也可以通过环境变量设置:
export STATS_HTTP_PORT=7000
export STATS_FLIGHT_PORT=7001
export STATS_DATA_DIR=/data/stats
配置优先级
- 环境变量(最高优先级)
- config.toml 文件
- 默认值(最低优先级)
推荐的生产环境配置
# Production config.toml
[server]
http_port = 7000
flight_port = 7001
[storage]
data_dir = "/data/stats" # Use dedicated SSD
[cache]
flush_interval_secs = 30 # Balance durability/performance
[compaction]
min_files = 4
max_level = 5
max_concurrent_compactions = 4 # Adjust based on CPU cores
full_compaction_max_concurrent = 1 # Low to prevent OOM
[retention]
enabled = true
default_days = 30 # 30 days retention
interval_secs = 3600 # Check hourly