import { Client } from "ssh2"; const SSH_CONFIG = { host: "119.45.10.34", port: 22, username: "root", password: "#xyzh%CS#2512@28", readyTimeout: 10000, }; function sshExec(command, timeout = 30000) { return new Promise((resolve, reject) => { const conn = new Client(); let stdout = ""; let stderr = ""; let timer = setTimeout(() => { conn.end(); resolve({ stdout, stderr: stderr + "\n[TIMEOUT]", code: -1 }); }, timeout); conn.on("ready", () => { conn.exec(command, (err, stream) => { if (err) { clearTimeout(timer); conn.end(); return reject(err); } stream.on("close", (code) => { clearTimeout(timer); conn.end(); resolve({ stdout, stderr, code }); }); stream.on("data", (d) => { stdout += d.toString(); }); stream.stderr.on("data", (d) => { stderr += d.toString(); }); }); }).on("error", (err) => { clearTimeout(timer); reject(new Error("SSH failed: " + err.message)); }).connect(SSH_CONFIG); }); } async function main() { console.log("=== 连接服务器 119.45.10.34 ===\n"); const checks = [ ["1. PM2 进程状态", "pm2 list 2>/dev/null || echo 'PM2_NOT_FOUND'"], ["2. 端口监听", "ss -tlnp | grep -E '3001|3012|80|443' || echo 'NO_MATCH'"], ["3. .env 关键配置", `grep -E '^(PORT|FC_SERVER_URL|VOLC_ARK_KNOWLEDGE|VOLC_RTC_APP_ID|VOLC_ARK_ENDPOINT_ID|COZE_)' /www/wwwroot/demo.tensorgrove.com.cn/server/.env 2>/dev/null | sed 's/\\(=.\\{6\\}\\).*/\\1***/' || echo '(文件不存在)'`], ["4. .env 所有键", `grep -v '^#' /www/wwwroot/demo.tensorgrove.com.cn/server/.env 2>/dev/null | grep '=' | cut -d= -f1 || echo '(无)'`], ["5. Nginx API 代理", `grep -A5 'location /api' /www/server/panel/vhost/nginx/demo.tensorgrove.com.cn.conf 2>/dev/null || find /www/server -name '*.conf' 2>/dev/null | head -10`], ["6. 后端 Health Check (3012)", `curl -s --max-time 5 http://127.0.0.1:3012/api/health 2>&1 || echo 'UNREACHABLE_3012'`], ["7. 后端 Health Check (3001)", `curl -s --max-time 5 http://127.0.0.1:3001/api/health 2>&1 || echo 'UNREACHABLE_3001'`], ["8. FC 回调 HTTPS 可达性", `curl -s -o /dev/null -w '%{http_code}' --max-time 5 -X POST https://demo.tensorgrove.com.cn/api/voice/fc_callback -H 'Content-Type: application/json' -d '{"Type":"test"}' 2>&1 || echo 'HTTPS_FAILED'`], ["9. SSL 证书", `echo | openssl s_client -connect demo.tensorgrove.com.cn:443 -servername demo.tensorgrove.com.cn 2>/dev/null | openssl x509 -noout -dates 2>/dev/null || echo 'SSL_CHECK_FAILED'`], ["10. PM2 最近日志 (最后30行)", `pm2 logs bigwo-server --nostream --lines 30 2>/dev/null || echo 'NO_LOGS'`], ["11. 前端 dist", `ls -la /www/wwwroot/demo.tensorgrove.com.cn/client/dist/index.html 2>&1`], ["12. 磁盘空间", `df -h / 2>&1`], ["13. Node.js 版本", `node -v 2>&1`], ]; for (const [title, cmd] of checks) { console.log(`\n${"=".repeat(50)}`); console.log(` ${title}`); console.log(`${"=".repeat(50)}`); try { const r = await sshExec(cmd); if (r.stdout) console.log(r.stdout.trimEnd()); if (r.stderr && r.stderr.trim()) console.log("[stderr]", r.stderr.trimEnd()); } catch (e) { console.log(`[ERROR] ${e.message}`); } } console.log("\n=== 检查完成 ==="); } main().catch(e => { console.error("Fatal:", e.message); process.exit(1); });