Janus 1.4.3 常用 CLI 命令与工具详解

汇总 Janus 1.4.3 运维命令入口:janus 启动参数全解(官方 --help 实拍)、janus-cfgconv 配置校验转换、systemd 管理命令族与 curl HTTP API 命令族,附真实回显与 403/458 错误码实测。

JanusJanusWebRTC流媒体2026/10/26

Janus 1.4.3 常用 CLI 命令与工具详解

目标:汇总 Janus 1.4.3(全称 janus-gateway)日常运维的全部命令入口:janus 主程序的启动参数全解(附官方 --help 实拍)、janus-cfgconv 配置转换工具、systemd 管理命令族,以及驱动服务器的 curl HTTP API 命令族(每条附实测回显与真实错误码)。安装背景见《Debian 12 安装 Janus 1.4.3 指南》,参数语义见《Janus 1.4.3 配置参数详解》。

一、命令工具总览

工具/入口位置用途
janus/opt/janus/bin/janus服务器主程序,全部启动参数都在这里
janus-cfgconv/opt/janus/bin/janus-cfgconv配置格式转换与解析校验(cfg ↔ jcfg)
janus.service/etc/systemd/system/janus.service生产托管入口(推荐,参数写在单元文件里)
HTTP APIhttp://<IP>:8088/janus运行时唯一控制面,curl 即可驱动全流程
Admin APIhttp://<IP>:7088/admin增强 API(需在 http.jcfg 打开 admin_http),查句柄/动态调参
Demo 静态页/opt/janus/share/janus/html/demos/浏览器测试页(需自行用静态服务器发布,8088 不托管页面)

二、janus 启动参数全解

janus --help 官方原文(v1.4.3 实拍):

Usage:
  janus [OPTION?]

Help Options:
  -h, --help                               Show help options

Application Options:
  -b, --daemon                             Launch Janus in background as a daemon
  -p, --pid-file=path                      Open the specified PID file when starting Janus (default=none)
  -N, --disable-stdout                     Disable stdout based logging
  --log-stdout                             Log to stdout, even when the process is daemonized
  -L, --log-file=path                      Log to the specified file (default=stdout only)
  -R, --log-rotate-sig=signal              Signal to trigger log reloading (e.g. SIGUSR1) (default=none)
  -l, --check-openfiles-limits=value       Check if the current limit on the maximum number of allowed open file descriptors matches this value (if not, Janus will close with a failure; default=none)
  -H, --cwd-path=path                      Working directory for Janus daemon process (default=/)
  -i, --interface=ipaddress                Interface to use (will be the public IP)
  -P, --plugins-folder=path                Plugins folder (default=./plugins)
  -C, --config=filename                    Configuration file to use
  -F, --configs-folder=path                Configuration files folder (default=./conf)
  -c, --cert-pem=filename                  DTLS certificate
  -k, --cert-key=filename                  DTLS certificate key
  -K, --cert-pwd=text                      DTLS certificate key passphrase (if needed)
  -S, --stun-server=address:port           STUN server(:port) to use, if needed (e.g., Janus behind NAT, default=none)
  -1, --nat-1-1=ips                        Comma-separated list of public IPs to put in all host candidates, assuming a 1:1 NAT is in place (e.g., Amazon EC2 instances, default=none)
  -2, --keep-private-host                  When nat-1-1 is used (e.g., Amazon EC2 instances), don't remove the private host, but keep both to simulate STUN
  -E, --ice-enforce-list=list              Comma-separated list of the only interfaces to use for ICE gathering; partial strings are supported (e.g., eth0 or eno1,wlan0, default=none)
  -X, --ice-ignore-list=list               Comma-separated list of interfaces or IP addresses to ignore for ICE gathering; partial strings are supported (e.g., vmnet8,192.168.0.1,10.0.0.1 or vmnet,192.168., default=vmnet)
  -6, --ipv6-candidates                    Whether to enable IPv6 candidates or not
  -O, --ipv6-link-local                    Whether IPv6 link-local candidates should be gathered as well
  -f, --full-trickle                       Do full-trickle instead of half-trickle
  -I, --ice-lite                           Whether to enable the ICE Lite mode or not
  -T, --ice-tcp                            Whether to enable ICE-TCP or not (warning: only works with ICE Lite)
  -Q, --min-nack-queue=number              Minimum size of the NACK queue (in ms) per user for retransmissions, no matter the RTT
  -t, --no-media-timer=number              Time (in s) that should pass with no media (audio or video) being received before Janus notifies you about this
  -W, --slowlink-threshold=number          Number of lost packets (per s) that should trigger a 'slowlink' Janus API event to users (default=0, feature disabled)
  -r, --rtp-port-range=min-max             Port range to use for RTP/RTCP
  -B, --twcc-period=number                 How often (in ms) to send TWCC feedback back to senders, if negotiated (default=200ms)
  -n, --server-name=name                   Public name of this Janus instance (default=MyJanusInstance)
  -s, --session-timeout=number             Session timeout value, in seconds (default=60)
  -m, --reclaim-session-timeout=number     Reclaim session timeout value, in seconds (default=0)
  -d, --debug-level=1-7                    Debug/logging level (0=disable debugging, 7=maximum debug level; default=4)
  -D, --debug-timestamps                   Enable debug/logging timestamps
  -o, --disable-colors                     Disable color in the logging
  -M, --debug-locks                        Enable debugging of locks/mutexes (very verbose!)
  -a, --apisecret=randomstring             API secret all requests need to pass in order to be accepted by Janus (useful when wrapping Janus API requests in a server, none by default)
  -A, --token-auth                         Enable token-based authentication for all requests
  --token-auth-secret=randomstring         Secret to verify HMAC-signed tokens with, to be used with -A
  --restrict-info-api                      Restrict the "info" endpoint to authenticated requests only (requires api_secret or token)
  -e, --event-handlers                     Enable event handlers
  -w, --no-webrtc-encryption               Disable WebRTC encryption, so no DTLS or SRTP (only for debugging!)
  -V, --version                            Print version and exit

Janus version: 1403 (1.4.3)
Janus commit: not-a-git-repo
Compiled on:  Mon Oct 26 05:43:19 UTC 2026

按用途分组解读:

分组参数要点
运行方式-b -p -H-b 后台守护(配置文件里 daemonize=true 的等价物);systemd 托管时不要加 -b,保持前台让 systemd 看住进程
配置定位-C -F-F 指定配置目录(安装后默认为 prefix/etc/janus);-C 指定单个主配置文件名(相对 -F),传绝对路径会启动失败
日志-N -L -R -D -o -M-L 落文件、-R SIGUSR1 滚动;-D 加时间戳;-M 锁调试(极啰嗦,仅死锁排查用)
ICE/NAT-i -S -1 -2 -E -X -6 -f -I -T-1 即配置文件的 nat_1_1_mapping(EC2 类 1:1 NAT 场景);-X 默认忽略 vmnet;-f 全 trickle;-I ICE-Lite(配合 -T ICE-TCP)
媒体-Q -t -W -r -B与 janus.jcfg media 段一一对应,命令行优先级更高
鉴权-a -A --token-auth-secret --restrict-info-api-a 全局口令;-A token 鉴权;--restrict-info-api 收紧 info 端点
会话-n -s -m-s 会话超时秒数(默认 60,见 6.5 节排障);-m 会话回收宽限
调试-d -e -w-d 7 最高调试级;-e 启用事件处理器;-w 关闭 DTLS/SRTP 加密仅限本地抓包排障,严禁上生产
版本-V打印版本号与编译信息

2.1 常用启动组合

生产(systemd 单元内的 ExecStart):

ExecStart=/opt/janus/bin/janus --configs-folder=/opt/janus/etc/janus

前台深度排障(ICE/DTLS 全量日志 + 时间戳 + 关色,接 tee 落盘):

/opt/janus/bin/janus -F /opt/janus/etc/janus -d 7 -D -o 2>&1 | tee /tmp/janus-debug.log

多网卡服务器钉住候选网卡并通告公网 IP:

/opt/janus/bin/janus -F /opt/janus/etc/janus -E eth0 -1 203.0.113.10

限制 RTP 端口段(配合防火墙精准放行):

/opt/janus/bin/janus -F /opt/janus/etc/janus -r 20000-20100

版本确认:

$ /opt/janus/bin/janus -V
Janus version: 1403 (1.4.3)
Janus commit: not-a-git-repo
Compiled on:  Mon Oct 26 05:43:19 UTC 2026

三、janus-cfgconv:配置转换与校验

用法(janus-cfgconv 无参运行实拍):

Usage: /opt/janus/bin/janus-cfgconv source.[cfg|jcfg] destination.[cfg|jcfg]
       /opt/janus/bin/janus-cfgconv --parse source.[cfg|jcfg]

两个用途:

# 语法校验:--parse 只解析不输出文件,报错即配置有语法问题
/opt/janus/bin/janus-cfgconv --parse /opt/janus/etc/janus/janus.jcfg

# 格式互转:新版 jcfg 与旧版 cfg 来回转(迁移老教程配置时有用)
/opt/janus/bin/janus-cfgconv /opt/janus/etc/janus/janus.jcfg /tmp/janus.cfg

四、systemd 管理命令族

生产托管下的日常操作(各命令实测可用,status 输出见安装篇第七节):

systemctl start janus        # 启动
systemctl stop janus         # 停止
systemctl restart janus      # 重启(改配置后的标准动作,Janus 无热加载)
systemctl status janus       # 状态与最近日志
systemctl is-active janus    # 脚本化判断:active / inactive
systemctl is-enabled janus   # 开机自启确认:enabled
systemctl enable janus       # 设置开机自启
journalctl -u janus -f       # 实时跟踪日志(等价 tail -f)
journalctl -u janus --since "10 min ago"   # 最近 10 分钟日志

排障经验:systemctl start 长时间不返回时,先 systemctl list-jobs 看有没有作业卡在 waiting(开机链依赖未就绪会阻塞新作业),systemctl cancel 清掉积压后再单独 start。

五、curl HTTP API 命令族

运行期的 Janus 完全由 API 驱动。以下全部命令在本机 8088 实测通过,回显照录(<session>/<handle> 为上一条返回的 id;示例启用了 api_secret,未启用时去掉 apisecret 字段即可)。

5.1 server_info:查服务器信息

curl -s http://127.0.0.1:8088/janus/info

实测回显(节选):

{
   "janus": "server_info",
   "transaction": "4o17kNeopgB",
   "name": "Janus WebRTC Server",
   "version": 1403,
   "version_string": "1.4.3",
   "author": "Meetecho s.r.l.",
   ...

info 包含已加载插件(实测 10 个)与 transport(实测 2 个)清单,是健康检查与版本巡检的首选。注意:info 默认免鉴权(api_secret 已启用时依然可匿名访问),要收紧需在启动参数加 --restrict-info-api 或配置文件同名单独项。

5.2 create:建会话

curl -s -X POST http://127.0.0.1:8088/janus -H "Content-Type: application/json" \
     -d '{"janus":"create","transaction":"d1create0001","apisecret":"q1w2e3r4"}'
{"janus":"success","transaction":"d1create0001","data":{"id":6708051054784432}}

5.3 attach:挂插件得 handle

curl -s -X POST http://127.0.0.1:8088/janus/6708051054784432 -H "Content-Type: application/json" \
     -d '{"janus":"attach","transaction":"d1attch0001","plugin":"janus.plugin.echotest","apisecret":"q1w2e3r4"}'
{"janus":"success","session_id":6708051054784432,"transaction":"d1attch0001","data":{"id":4625299469112602}}

常用插件名:janus.plugin.echotest(回声自检)、janus.plugin.videoroom、janus.plugin.streaming、janus.plugin.audiobridge、janus.plugin.videocall、janus.plugin.sip、janus.plugin.textroom、janus.plugin.recordplay、janus.plugin.nosip、janus.plugin.lua。

5.4 message:发业务请求(带 JSEP)

请求体建议落文件再 curl -d @file(SDP 内含 \r\n 需转义,命令行内联易错):

curl -s -X POST http://127.0.0.1:8088/janus/<session>/<handle> \
     -H "Content-Type: application/json" -d @/tmp/offer.json

受理回显(异步处理,结果走事件通道):

{"janus":"ack","session_id":7699435502130401,"transaction":"b1msg000000001","hint":"I'm taking my time!"}

5.5 长轮询取事件

curl -s "http://127.0.0.1:8088/janus/<session>?maxev=1"

返回 janus:"event",插件应答在 plugindata.data,SDP 在 jsep(echotest 的完整 answer 实拍见安装篇 9.4)。HTTP 模式下客户端必须循环调用本命令形成长轮询;WebSockets 模式则由服务端主动推。

5.6 keepalive:会话保活

curl -s -X POST http://127.0.0.1:8088/janus/<session> -H "Content-Type: application/json" \
     -d '{"janus":"keepalive","transaction":"d1keep00001","apisecret":"q1w2e3r4"}'
{"janus":"ack","session_id":7699435502130401,"transaction":"b1keep0000001"}

5.7 destroy:销毁会话

curl -s -X POST http://127.0.0.1:8088/janus/<session> -H "Content-Type: application/json" \
     -d '{"janus":"destroy","transaction":"d1dstry001","apisecret":"q1w2e3r4"}'
{"janus":"success","session_id":7699435502130401,"transaction":"b1dstry000001"}

5.8 两个必须认识的错误码(实测回显)

403(鉴权失败,api_secret/token 语境):

{"janus":"error","transaction":"c1nosec00001","error":{"code":403,"reason":"Unauthorized request (wrong or missing secret/token)"}}

458(会话不存在:destroy 后或 60 秒无 keepalive 超时回收后):

{"janus":"error","session_id":7699435502130401,"transaction":"b1gone0000001","error":{"code":458,"reason":"No such session 7699435502130401"}}

服务端对应日志:

Timeout expired for session 213764637636828...
Destroying session 213764637636828; 0x79eddc000d40

长轮询客户端轮询间隔应小于 60 秒(默认 session-timeout),或启动时用 -s 300 调大。

六、调试与排障速查

症状命令/手段
启动即失败journalctl -u janus -n 50;先 janus-cfgconv --parse 校验配置语法
API 无响应`ss -ltn
鉴权 403核对 apisecret 拼写(请求字段是 apisecret,配置项是 api_secret——名字不同是官方设计)
会话莫名消失458 + 超时日志(见 5.8),客户端加 keepalive 或 -s 调大超时
ICE 打不通-d 7 -D 前台复现,看 candidate 交换;公网核对 -1/nat_1_1_mapping 与 UDP 段放行
疑似死锁/挂起-M 锁调试重启复现(日志量巨大,勿长期开)
插件没加载启动日志逐个看 Loading plugin ...;Lua 报 module json not found 见安装篇 Q2

七、验收清单

  • janus -V 显示 1403 (1.4.3)
  • systemctl is-active janus → active,is-enabled → enabled
  • janus-cfgconv --parse /opt/janus/etc/janus/janus.jcfg 无报错
  • curl /janus/info 返回 version_string: 1.4.3 且插件/transport 数量符合预期
  • create/attach/message/keepalive/destroy 五连全部成功
  • 403 与 458 两个错误码行为与本文回显一致(鉴权与超时机制在位)

本文 --help、janus-cfgconv 用法与全部 API 回显均在 Debian 12 + Janus 1.4.3 实测环境采集(2026-10-26),输出为真实回显照录,session/handle id、指纹、时间戳以你的环境为准。