ngIRCd 28 命令行与运维命令指南
目标:讲清 ngIRCd 28 的全部管理入口:ngircd 命令行选项(实测共 8 个)、systemd 服务管理、IRC 运行期运维命令(OPER/STATS/LINKS/SQUIT/CONNECT/REHASH 等)及其真实回显,全部命令在本机 ngIRCd 28 双实例环境实测。
ngIRCd 28 命令行与运维命令指南
目标:讲清 ngIRCd 28 的全部管理入口:
ngircd命令行选项(实测共 8 个)、systemd 服务管理、IRC 运行期运维命令(OPER/STATS/LINKS/SQUIT/CONNECT/REHASH 等)及其真实回显,全部命令在本机 ngIRCd 28 双实例环境实测。
一、命令面总览
ngIRCd 的管理面由三层组成,与功能丰富的大型 IRCd 相比命令行相当精简:
| 层 | 入口 | 用途 |
|---|---|---|
| 进程命令行 | ngircd <选项>(共 8 个选项) | 启动、配置校验、多实例 |
| 服务管理 | systemd | 启停、开机自启、状态查看 |
| 运行期管理 | IRC 操作员命令(登录后使用) | 统计、互联控制、配置重读 |
没有独立的 reload/status 子命令,也没有任何 HTTP/API 管理面——运行期管理完全走 IRC 协议本身。
二、ngircd 命令行选项(8 个全量)
ngircd --help 完整输出(实测逐行):
ngIRCd 28-CHARCONV+IDENT+IPv6+IRCPLUS+PAM+SSL+SYSLOG+TCPWRAP+ZLIB-x86_64/pc/linux-gnu
Copyright (c)2001-2026 Alexander Barton (<alex@barton.de>) and Contributors.
Homepage: <http://ngircd.barton.de/>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-d, --debug log extra debug messages
-f, --config <f> use file <f> as configuration file
-n, --nodaemon don't fork and don't detach from controlling terminal
-p, --passive disable automatic connections to other servers
-t, --configtest read, validate and display configuration; then exit
-V, --version output version information and exit
-y, --syslog log to syslog even when running in the foreground (-n)
-h, --help display this help and exit
逐项用法与典型场景:
| 选项 | 用途 | 典型场景 |
|---|---|---|
-t, --configtest | 读取、校验并打印生效配置后退出 | 改配置后的标准动作,详见本系列配置篇第九节 |
-V, --version | 输出版本与编译特性旗标串 | 确认部署版本的特性集 |
-f, --config <f> | 指定配置文件 | 多实例:一台机器跑多个 ngIRCd(本系列配置篇第七节的双实例即用 -f 区分配置) |
-n, --nodaemon | 不 fork、不脱离控制终端 | 前台调试;配合服务管理器的 Type=simple 形态 |
-d, --debug | 输出额外调试日志 | 排障(联调互联/认证问题时) |
-y, --syslog | 前台运行(-n)时也写 syslog | 前台调试同时保留系统日志 |
-p, --passive | 禁止向其他服务器主动建链 | 临时断开出站互联(等价于全部 [Server] 段 Passive=yes) |
-h, --help | 显示帮助 | —— |
三、systemd 服务管理
配合安装篇的 ngircd.service 单元(Type=forking,ExecReload=/bin/kill -HUP $MAINPID):
sudo systemctl start ngircd # 启动
sudo systemctl stop ngircd # 停止
sudo systemctl restart ngircd # 重启(改配置后的推荐动作)
sudo systemctl status ngircd # 状态
sudo systemctl enable ngircd # 开机自启
⚠️
systemctl reload ngircd走的是 SIGHUP(REHASH)路径,存在监听套接字重绑竞态(见第七节),日常改配置请用restart而非reload。
四、配置校验:configtest 工作流
ngircd -t / ngircd --configtest 输出解析后的完整生效配置:
$ ngircd --configtest
Using default configuration file "/usr/local/etc/ngircd.conf" ...
Reading configuration from "/usr/local/etc/ngircd.conf" ...
Ok, dump of your server configuration follows:
[GLOBAL]
Name = irc.example.com
...
Ok, dump ... 出现即配置通过;有错误时明确指出错误行。dump 显示的是实际生效值(含默认填充),比配置原文更可信。完整的逐段 dump 与四类配置错误实录见本系列配置篇。
五、IRC 运行期运维命令
运行期管理在 IRC 会话内完成:先用 [Operator] 段配置的账号执行 OPER 提权,再使用管理命令。以下全部回显来自本机 28 版双实例环境实测(OPER admin <密码> 登录):
:irc.example.com MODE ctest :+o
:irc.example.com 381 ctest :You are now an IRC Operator
5.1 统计与状态查询
STATS l(连接/流量统计;211 每行一条连接,219 结束):
:irc.example.com 211 ctest irc2.example.com 0 13 903/545 10 876/525 :176
:irc.example.com 211 ctest ctest!~ctest@localhost 74 24 1828 4 88 :2
:irc.example.com 219 ctest l :End of STATS report
LUSERS(用户/服务/频道计数,操作员额外可见上限):
:irc.example.com 251 ctest :There are 1 users and 0 services on 2 servers
:irc.example.com 252 ctest 1 :operator(s) online
:irc.example.com 254 ctest 2 :channels formed
:irc.example.com 255 ctest :I have 1 users, 0 services and 1 servers
:irc.example.com 265 ctest 1 1 :Current local users: 1, Max: 1
:irc.example.com 266 ctest 1 1 :Current global users: 1, Max: 1
:irc.example.com 250 ctest :Highest connection count: 2 (1 connections received)
ADMIN(返回 [Global] 的 AdminInfo1/AdminInfo2/AdminEMail 三项):
:irc.example.com 256 ctest irc.example.com :Administrative info
:irc.example.com 257 ctest :ngircd Demo Administrator
:irc.example.com 258 ctest :Shanghai, China
:irc.example.com 259 ctest :admin@example.com
TIME(服务器当前时间):
:irc.example.com 391 ctest irc.example.com :Monday October 26 2026 -- 09:30 UTC
INFO(版本旗标串、编译时间、启动时间):
:irc.example.com 371 ctest :ngIRCd 28-CHARCONV+IDENT+IPv6+IRCPLUS+PAM+SSL+SYSLOG+TCPWRAP+ZLIB-x86_64/pc/linux-gnu
:irc.example.com 371 ctest :Birth Date: Oct 26 2026 at 08:11:26
:irc.example.com 371 ctest :On-line since Mon Oct 26 2026 at 09:27:31 (UTC)
:irc.example.com 374 ctest :End of INFO list
Birth Date 是二进制的编译时刻,可用于核对部署的构建版本;On-line since 即本次启动时间。
HELP <命令>(依赖 [Global] HelpFile 指向的 Commands.txt;分页 NOTICE 形式输出):
:irc.example.com NOTICE ctest :USER <username> <hostname> <unused> <realname>
:irc.example.com NOTICE ctest :
:irc.example.com NOTICE ctest :Register (and authenticate) a new user session with a short <username>
:irc.example.com NOTICE ctest :and a human-readable <realname>.
...
5.2 互联拓扑查看:LINKS
:irc.example.com 364 ctest irc2.example.com irc.example.com :1 ngIRCd 28 Demo Server #2
:irc.example.com 364 ctest irc.example.com irc.example.com :0 ngIRCd 28 Demo Server
:irc.example.com 365 ctest * :End of LINKS list
每行 364 为一台服务器:昵称、服务器名、经由谁发现(第二列)、跳数(: 前的数字)与对端 Info。拓扑变化排查首选。
六、互联控制:SQUIT 与 CONNECT(闭环实测)
操作员可主动断开与重连服务器链路。实测闭环(先 SQUIT 断链、再 CONNECT 重连):
断链后 LINKS 只剩本端(364 仅一行 hop 0):
:irc.example.com 381 ctest :You are now an IRC Operator
:irc.example.com 364 ctest irc.example.com irc.example.com :0 ngIRCd 28 Demo Server
:irc.example.com 365 ctest * :End of LINKS list
执行 CONNECT irc2.example.com 重连后,对端以 hop 1 重新出现:
:irc.example.com 364 ctest irc2.example.com irc.example.com :1 ngIRCd 28 Demo Server #2
:irc.example.com 364 ctest irc.example.com irc.example.com :0 ngIRCd 28 Demo Server
:irc.example.com 365 ctest * :End of LINKS list
用法要点:
SQUIT <服务器名> :<原因>断开指定服务器链路(原因会记录传播);CONNECT <服务器名>立即发起对指定服务器的连接——对[Server]段Passive = yes(不自动连接)的 peer 尤其实用:配置好端口、平时保持断开、需要时手动 CONNECT;- 断链后若什么都不做,
ConnectRetry(默认 60 秒)周期到后也会自动重连(Passive 未开启时)。
七、REHASH 与监听竞态坑
REHASH 命令让服务器重读配置文件(操作员命令,也可由 systemd reload 的 SIGHUP 触发):
REHASH
:irc.example.com 382 ctest :Rehashing
382 是唯一回显,仅表示「已接受重读请求」。关键坑:实测中 REHASH 会关闭并重建全部监听套接字,新旧套接字交替的间隙存在端口重绑失败的可能(TIME_WAIT/地址仍被旧套接字引用时 EADDRINUSE)——结果是进程活着、但 6667 不再监听,服务器对客户端「失聪」。本文多轮实测中两种结果都出现过:
- 重绑成功:REHASH 后
ss -tlnp中 6667/6697 监听完好,配置更新生效; - 重绑失败:监听消失,需要
systemctl restart ngircd恢复。
实践建议:改配置后一律 ngircd --configtest 校验,然后 systemctl restart ngircd 应用;REHASH 只用于确认无损的热更新场景,且执行后应立即复查监听(ss -tlnp | grep ngircd)。
八、排障速查
| 现象 | 排查 |
|---|---|
| 改配置后行为未变 | 是否有重复键(28 版取最后值);用 configtest dump 对照生效值 |
| REHASH 后客户端连不上 | `ss -tlnp |
| 联邦断链 | LINKS 看拓扑;CONNECT 手动重连;核对两端 MyPassword/PeerPassword 互换 |
| OPER 报错 | 核对 [Operator] 的 Name/Password;来源掩码 Mask 限制 |
| STATS 无输出 | 需先 OPER 提权(381 确认) |
| 前台看不到日志 | -n 配合 -d(调试级);-y 同时写 syslog |