跳转到内容

配置说明

Monibuca 采用多层配置系统,优先级从高到低依次为:

Runtime(API 动态修改) > Database(数据库持久化) > Env(环境变量) > File(配置文件) > Default(默认值)
优先级来源说明
最高Runtime通过 HTTP API 在运行时修改
Database从数据库加载的持久化配置
Environment环境变量 M7S_{PLUGIN}_{FIELD}
Fileconfig.yaml 配置文件
最低Default代码中定义的默认值

高优先级的配置会覆盖低优先级的同名配置项。

# =============================================
# 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

全局 publishsubscribe 配置会被所有插件继承。插件可以覆盖这些值:

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.loglevelM7S_GLOBAL_LOGLEVEL
global.http.listenaddrM7S_GLOBAL_HTTP_LISTENADDR
rtmp.tcp.listenaddrM7S_RTMP_TCP_LISTENADDR
rtmp.tcp.nodelayM7S_RTMP_TCP_NODELAY
global.publish.ringsizeM7S_GLOBAL_PUBLISH_RINGSIZE
webrtc.iceserversM7S_WEBRTC_ICESERVERS

数组类型的值使用逗号分隔:

Terminal window
# 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"
Terminal window
# 开发环境
M7S_GLOBAL_LOGLEVEL=debug ./monibuca -c config.yaml
# 生产环境覆盖端口
M7S_RTMP_TCP_LISTENADDR=":11935" \
M7S_GLOBAL_HTTP_LISTENADDR=":80" \
./monibuca -c config.yaml

Monibuca 支持将配置持久化到数据库,实现重启后配置不丢失。

数据库DSN 格式Feature Flag
SQLitesqlite:m7s.db?mode=rwc默认内置
MySQLmysql://user:pass@host:3306/dbmysql
PostgreSQLpostgres://user:pass@host:5432/dbpostgres
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 镜像:

Terminal window
# Docker 镜像默认包含 MySQL 和 PostgreSQL 支持
docker run -d \
-e M7S_GLOBAL_DB_DSN="mysql://root:password@host:3306/monibuca" \
langhuihui/monibuca:v6

通过 HTTP API 可以在运行时动态修改配置,修改后的值具有最高优先级。

Terminal window
# 获取全局配置
curl http://localhost:8180/api/config/global
# 获取指定插件配置
curl http://localhost:8180/api/config/rtmp
Terminal window
# 修改插件配置
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 触发配置文件重载,使最新的文件配置生效:

Terminal window
# 重载配置
curl -X POST http://localhost:8180/api/config/reload
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: true
docker-compose.yml
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 频道二维码
QQ 群:751639168 QQ 群二维码