配置说明
Monibuca 采用多层配置系统,优先级从高到低依次为:
Runtime(API 动态修改) > Database(数据库持久化) > Env(环境变量) > File(配置文件) > Default(默认值)| 优先级 | 来源 | 说明 |
|---|---|---|
| 最高 | Runtime | 通过 HTTP API 在运行时修改 |
| 高 | Database | 从数据库加载的持久化配置 |
| 中 | Environment | 环境变量 M7S_{PLUGIN}_{FIELD} |
| 低 | File | config.yaml 配置文件 |
| 最低 | Default | 代码中定义的默认值 |
高优先级的配置会覆盖低优先级的同名配置项。
YAML 配置文件
Section titled “YAML 配置文件”# =============================================# Monibuca V6 配置文件# =============================================
# 全局配置 - 可被各插件继承global: # 日志级别: trace, debug, info, warn, error loglevel: info
# 禁用所有插件(需要各插件手动 enable: true) disableall: false
# 公网 IP(用于 NAT 穿透,留空自动检测) publicip: "" publicipv6: ""
# 认证开关 enableauth: false
# HTTP 服务配置(所有 HTTP 类插件共享) http: listenaddr: ":8180" cors: true corsorigins: - "*" readtimeout: 30 writetimeout: 30 idletimeout: 120
# TCP 服务配置(gRPC 等) tcp: listenaddr: ":50051"
# 发布默认配置 publish: pubtimeout: 10 # 发布超时(秒) waitclosetimeout: 0 # 等待关闭超时(秒) delayclosetime: 0 # 延迟关闭时间(秒) kick: false # 是否踢掉同名流 ringsize: 256 # RingBuffer 大小 maxfps: 0 # 最大帧率限制(0=不限制)
# 订阅默认配置 subscribe: subtimeout: 10 # 订阅超时(秒) waittimeout: 10 # 等待流超时(秒) buffertime: 2000 # 缓冲时间(毫秒) internalbuffersize: 10 subvideo: true # 是否订阅视频 subaudio: true # 是否订阅音频
# 数据库配置 db: dsn: "sqlite:m7s.db?mode=rwc"
# 管理面板 admin: enablelogin: false username: admin password: admin
# =============================================# 协议插件# =============================================
# RTMP 协议rtmp: enable: true tcp: listenaddr: ":1935" readbuffersize: 65536 writebuffersize: 65536 nodelay: true chunksize: 4096
# RTSP 协议rtsp: enable: true tcp: listenaddr: ":8554" udpportstart: 10000 udpportend: 20000
# HLS 协议hls: enable: true segmentduration: 6 maxsegments: 5 outputdir: "./hls" writetodisk: true
# WebRTC 协议(WHIP/WHEP)webrtc: enable: true portrange: "udp:9000-9100" publicip: ""
# SRT 协议srt: enable: true listenaddr: ":6000" latency_ms: 120 # passphrase: "your_passphrase" # 可选,10-79 个字符
# GB28181 国标协议gb28181: enable: false sip: - domain: "3402000000" domain_id: "34020000002000000001" lan_ip: "0.0.0.0" wan_ip: "" port: 5060 network: udp rtp_port_min: 10000 rtp_port_max: 20000 heartbeat_timeout: 60 register_timeout: 300
# =============================================# 功能插件# =============================================
# 日志轮转logrotate: enable: false logdir: "./logs" filenamepattern: "monibuca-%Y%m%d.log" maxsize: 104857600 # 100MB maxbackups: 7 maxage: 30 compress: true rotationinterval: daily
# 房间系统room: enable: true app_name: "room" max_users_per_room: 100 ping_interval: 30 ping_timeout: 60全局 publish 和 subscribe 配置会被所有插件继承。插件可以覆盖这些值:
global: publish: ringsize: 256 # 全局默认 RingBuffer 大小
rtmp: enable: true publish: ringsize: 512 # RTMP 插件使用更大的 RingBuffer最小配置:
global: enableauth: true publish: key: "your-publish-key" subscribe: key: "your-subscribe-key"更多(签名算法、参数、支持协议、自定义鉴权处理器)请参考:
环境变量遵循 M7S_{PLUGIN}_{FIELD} 命名规则,所有字母大写,嵌套字段用下划线分隔。
M7S_{插件名}_{字段路径}| 配置项 | 环境变量 |
|---|---|
global.loglevel | M7S_GLOBAL_LOGLEVEL |
global.http.listenaddr | M7S_GLOBAL_HTTP_LISTENADDR |
rtmp.tcp.listenaddr | M7S_RTMP_TCP_LISTENADDR |
rtmp.tcp.nodelay | M7S_RTMP_TCP_NODELAY |
global.publish.ringsize | M7S_GLOBAL_PUBLISH_RINGSIZE |
webrtc.iceservers | M7S_WEBRTC_ICESERVERS |
数组类型的值使用逗号分隔:
# ICE 服务器列表export M7S_WEBRTC_ICESERVERS="stun:stun1.example.com,stun:stun2.example.com"
# CORS 允许的来源export M7S_GLOBAL_HTTP_CORSORIGINS="https://a.com,https://b.com"# 开发环境M7S_GLOBAL_LOGLEVEL=debug ./monibuca -c config.yaml
# 生产环境覆盖端口M7S_RTMP_TCP_LISTENADDR=":11935" \M7S_GLOBAL_HTTP_LISTENADDR=":80" \./monibuca -c config.yaml数据库持久化
Section titled “数据库持久化”Monibuca 支持将配置持久化到数据库,实现重启后配置不丢失。
支持的数据库
Section titled “支持的数据库”| 数据库 | DSN 格式 | Feature Flag |
|---|---|---|
| SQLite | sqlite:m7s.db?mode=rwc | 默认内置 |
| MySQL | mysql://user:pass@host:3306/db | mysql |
| PostgreSQL | postgres://user:pass@host:5432/db | postgres |
global: db: # SQLite(默认,零配置) dsn: "sqlite:m7s.db?mode=rwc"
# MySQL # dsn: "mysql://root:password@localhost:3306/monibuca"
# PostgreSQL # dsn: "postgres://postgres:password@localhost:5432/monibuca"如需使用 MySQL 或 PostgreSQL,请使用对应的预编译版本或 Docker 镜像:
# Docker 镜像默认包含 MySQL 和 PostgreSQL 支持docker run -d \ -e M7S_GLOBAL_DB_DSN="mysql://root:password@host:3306/monibuca" \ langhuihui/monibuca:v6HTTP API 动态配置
Section titled “HTTP API 动态配置”通过 HTTP API 可以在运行时动态修改配置,修改后的值具有最高优先级。
查询当前配置
Section titled “查询当前配置”# 获取全局配置curl http://localhost:8180/api/config/global
# 获取指定插件配置curl http://localhost:8180/api/config/rtmp# 修改插件配置curl -X POST http://localhost:8180/api/config/rtmp \ -H "Content-Type: application/json" \ -d '{"chunksize": 8192}'
# 修改全局配置curl -X POST http://localhost:8180/api/config/global \ -H "Content-Type: application/json" \ -d '{"loglevel": "debug"}'通过 API 触发配置文件重载,使最新的文件配置生效:
# 重载配置curl -X POST http://localhost:8180/api/config/reload配置最佳实践
Section titled “配置最佳实践”global: loglevel: debug admin: enablelogin: false
rtmp: enable: true tcp: listenaddr: ":1935"global: loglevel: warn enableauth: true http: listenaddr: ":8180" cors: true corsorigins: - "https://your-domain.com" publish: ringsize: 512 kick: false subscribe: buffertime: 3000 db: dsn: "postgres://user:pass@db-host:5432/monibuca" admin: enablelogin: true username: admin password: your_secure_password
rtmp: enable: true tcp: listenaddr: ":1935"
hls: enable: true segmentduration: 4 maxsegments: 6
logrotate: enable: true logdir: "/var/log/monibuca" maxbackups: 30 compress: trueDocker Compose 环境
Section titled “Docker Compose 环境”services: monibuca: image: langhuihui/monibuca:v6 ports: - "8180:8180" - "8443:8443" - "1935:1935" - "8554:8554" - "50051:50051" - "6000:6000/udp" - "9000-9100:9000-9100/udp" volumes: - ./config.yaml:/etc/monibuca/config.yaml - ./data:/monibuca/data environment: - M7S_GLOBAL_LOGLEVEL=info - M7S_GLOBAL_PUBLICIP=your.public.ip restart: unless-stopped更多关于系统架构的深入介绍,请参阅 系统架构。
联系我们
微信公众号:不卡科技
腾讯频道:流媒体技术
QQ 频道:p0qq0crz08
QQ 群:751639168