适用于 Windows 7 / Windows 8 / Windows Server 2008 R2 / 2012 等不支持新版 agent 的系统。
准备工作
以管理员权限打开 PowerShell 或 CMD,下面的命令都需要管理员权限。
第一步:下载文件
New-Item -Path "C:\Program Files\Komari" -ItemType Directory -Force
Invoke-WebRequest -Uri "https://github.com/xykt/komari-agent-win7_win8_legacy/releases/download/1.1.40/komari-agent_amd64_legacy.exe" -OutFile "C:\Program Files\Komari\komari-agent.exe" -UseBasicParsing
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/xykt/komari-agent-win7_win8_legacy/refs/heads/main/tools/nssm.exe" -OutFile "C:\Windows\System32\nssm.exe" -UseBasicParsing
如果 Invoke-WebRequest 因为 TLS 版本问题失败(老系统常见),先执行:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
第二步:注册为 Windows 服务
把 <面板地址> 和 <TOKEN> 替换成你自己的:
nssm install komari-agent "C:\Program Files\Komari\komari-agent.exe"
nssm set komari-agent AppParameters "-e <面板地址> -t <TOKEN> --disable-auto-update"
nssm set komari-agent AppDirectory "C:\Program Files\Komari"
nssm set komari-agent Start SERVICE_AUTO_START
nssm set komari-agent AppStdout "C:\Program Files\Komari\stdout.log"
nssm set komari-agent AppStderr "C:\Program Files\Komari\stderr.log"
nssm set komari-agent AppExit Default Restart
nssm set komari-agent AppRestartDelay 5000
参数说明:
-e面板地址,例如https://svr-agent.czl.net-ttoken,从面板生成--disable-auto-update禁用自动更新(老系统建议加,避免被新版替换后跑不起来)
第三步:检查并修复 binPath(重要)
某些 NSSM 版本注册服务时会漏掉服务名参数,必须先验证:
sc.exe qc komari-agent
看 BINARY_PATH_NAME 那一行:
正常:"C:\Windows\System32\nssm.exe" komari-agent
异常:C:\Windows\System32\nssm.exe(缺少服务名)
如果是异常情况,手动修复:
CMD 下:
sc.exe config komari-agent binPath= "\"C:\Windows\System32\nssm.exe\" komari-agent"
PowerShell 下:
sc.exe config komari-agent binPath= '"C:\Windows\System32\nssm.exe" komari-agent'
第四步:启动服务
nssm start komari-agent
验证状态:
sc.exe query komari-agent
STATE 显示 RUNNING 就成功了。
查看日志:
type "C:\Program Files\Komari\stdout.log"
type "C:\Program Files\Komari\stderr.log"
常用运维命令
:: 启动 / 停止 / 重启
nssm start komari-agent
nssm stop komari-agent
nssm restart komari-agent
:: 修改参数(比如换 token)
nssm stop komari-agent
nssm set komari-agent AppParameters "-e <新面板地址> -t <新TOKEN> --disable-auto-update"
nssm start komari-agent
:: 图形化编辑配置
nssm edit komari-agent
:: 查看当前配置
nssm get komari-agent Application
nssm get komari-agent AppParameters
nssm get komari-agent AppDirectory
卸载
nssm stop komari-agent
nssm remove komari-agent confirm
:: 清理文件
rmdir /s /q "C:\Program Files\Komari"
:: 可选:移除 nssm
del C:\Windows\System32\nssm.exe
排错速查
| 现象 | 原因 | 解决 |
|---|---|---|
nssm start 报"系统找不到指定的文件" |
binPath 缺少服务名参数 | 见第三步 |
| 服务启动后立即停止 | 参数错误或网络不通 | 看 stderr.log |
| 下载报 SSL/TLS 错误 | 老系统默认 TLS 1.0 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 服务启动一直 pending | 之前服务残留冲突 | nssm remove + sc delete 后重启系统再装 |