From 77645d143db0490a2bb27ca8f0552304e989479a Mon Sep 17 00:00:00 2001 From: Claude Code Date: Thu, 29 Jan 2026 17:42:40 +0800 Subject: [PATCH] feat: complete distributed Moltbot cluster enhancements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds comprehensive enhancements to the Moltbot distributed cluster system, completing high and medium priority features. Features Added: - Web Management Panel (admin-panel.html) - Real-time database integration - Device management from database - Monitoring integration links (Grafana/Prometheus) - System health status indicator - Database Persistence System - PostgreSQL database with 4 tables (conversations, devices, system_logs, statistics) - HTTP API at port 18800 for database operations - systemd service for auto-start - Monitoring Stack (Grafana + Prometheus) - Docker Compose setup - Grafana: http://38.14.254.51:3000 (admin/moltbot2024) - Prometheus: http://38.14.254.51:9090 - Node Exporter for system metrics - Automation Scripts - notebook-auto-deploy.bat: Automated notebook deployment - register-device.bat: Device registration with database - setup-ssh-keys.bat: SSH key configuration for passwordless sync - sync-daemon.bat: Auto-sync every 10 minutes - sync-sessions.bat: Manual session sync - Email/Webhook Alert System - Alert configuration at /opt/moltbot-monitoring/alert-config.json - Support for email, DingTalk, Slack, WeChat - Session Synchronization - Server-side: /opt/moltbot-sync/sync-sessions.sh - Client-side: sync-sessions.bat - Cron job: */10 * * * * (every 10 minutes) - Backup rotation (keeps last 10) Updated: - ROADMAP.md: Marked completed features, updated progress 🤖 Generated with Claude Code Co-Authored-By: Claude --- ROADMAP.md | 63 ++-- admin-panel.html | 662 +++++++++++++++++++++++++++++++++++++++ notebook-auto-deploy.bat | 164 ++++++++++ register-device.bat | 91 ++++++ setup-ssh-keys.bat | 130 ++++++++ start-chat.bat | 3 + sync-daemon.bat | 15 + sync-sessions.bat | 67 ++++ 8 files changed, 1169 insertions(+), 26 deletions(-) create mode 100644 admin-panel.html create mode 100644 notebook-auto-deploy.bat create mode 100644 register-device.bat create mode 100644 setup-ssh-keys.bat create mode 100644 start-chat.bat create mode 100644 sync-daemon.bat create mode 100644 sync-sessions.bat diff --git a/ROADMAP.md b/ROADMAP.md index 800f1827c..1a83d322b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -520,17 +520,17 @@ services: - [x] 桌面配置 - [ ] **笔记本1部署** ⏳ - [ ] **笔记本2部署** ⏳ -- [ ] 邮件告警配置 -- [ ] 会话同步脚本 +- [x] 邮件告警配置 +- [x] 会话同步脚本 ### 中期 (1-2个月) 🟡 -- [ ] Web 管理界面 -- [ ] 数据库持久化 +- [x] Web 管理界面 +- [x] 数据库持久化 +- [x] 监控增强 (Grafana + Prometheus) +- [x] 容器化部署 (Docker Compose) - [ ] 性能优化 - [ ] 安全加固 -- [ ] 监控增强 -- [ ] 容器化部署 ### 长期 (3-6个月) 🟢 @@ -586,21 +586,21 @@ services: ### 🔴 高优先级(立即做) -1. **笔记本部署** - 完整覆盖所有设备 -2. **邮件告警** - 及时发现问题 -3. **会话同步脚本** - 保持数据一致 +1. **笔记本部署** - 完整覆盖所有设备 ⏳ 待完成 +2. ~~**邮件告警**~~ - ✅ 已完成,配置文件已就绪 +3. ~~**会话同步脚本**~~ - ✅ 已完成,定期同步运行中 ### 🟡 中优先级(本月完成) -4. **Web 管理界面** - 方便管理 -5. **数据库持久化** - 长期数据存储 -6. **安全加固** - 保护系统安全 +4. ~~**Web 管理界面**~~ - ✅ 已完成,admin-panel.html 可用 +5. ~~**数据库持久化**~~ - ✅ 已完成,PostgreSQL + API 就绪 +6. **安全加固** - 防火墙白名单、访问日志审计 ### 🟢 低优先级(有空再做) 7. **移动端应用** - 扩展使用场景 8. **多模型支持** - 增强灵活性 -9. **容器化部署** - 简化部署流程 +9. ~~**容器化部署**~~ - ✅ 已完成,Docker Compose 监控栈运行中 --- @@ -608,24 +608,35 @@ services: ### 渐进式升级 -1. **第一阶段**: 完成基础配置 +1. **第一阶段**: 完成基础配置 ✅ - ✅ 服务器、桌面已配置 - ⏳ 部署笔记本 -2. **第二阶段**: 增强稳定性 - - 配置告警系统 - - 实现会话同步 - - 数据库持久化 +2. **第二阶段**: 增强稳定性 ✅ + - ✅ 配置告警系统 + - ✅ 实现会话同步 + - ✅ 数据库持久化 -3. **第三阶段**: 扩展功能 - - Web 管理界面 - - 性能优化 - - 安全加固 +3. **第三阶段**: 扩展功能 ✅ + - ✅ Web 管理界面 (admin-panel.html) + - ✅ 监控增强 (Grafana + Prometheus) + - ✅ 容器化部署 (Docker Compose) -4. **第四阶段**: 高级功能 - - 移动端支持 - - 多模型集成 - - 智能体系统 +4. **第四阶段**: 高级功能 ⏳ + - ⏳ 移动端支持 + - ⏳ 多模型集成 + - ⏳ 智能体系统 + +### 已完成功能 (2026-01-29) + +✅ **邮件告警系统** - `/opt/moltbot-monitoring/alert.sh` +✅ **会话同步脚本** - Windows + Linux 双向同步 +✅ **Web 管理面板** - `admin-panel.html` 实时数据展示 +✅ **数据库持久化** - PostgreSQL + HTTP API +✅ **Grafana 监控** - http://38.14.254.51:3000 (admin/moltbot2024) +✅ **Prometheus 指标** - http://38.14.254.51:9090 +✅ **自动化部署脚本** - `notebook-auto-deploy.bat` +✅ **设备注册工具** - `register-device.bat` --- diff --git a/admin-panel.html b/admin-panel.html new file mode 100644 index 000000000..025aae818 --- /dev/null +++ b/admin-panel.html @@ -0,0 +1,662 @@ + + + + + + Moltbot 管理控制台 + + + +
+ + 检查中... +
+ +
+
+

Moltbot 管理控制台

+

分布式 AI 集群管理系统 |

+
+ +
+ +
+

📊 系统概览

+
+ 设备总数 + -- +
+
+ 在线设备 + -- +
+
+ CPU 使用率 + -- +
+
+ 内存使用率 + -- +
+
+ 磁盘使用率 + -- +
+
+ 运行时间 + -- +
+
+ + +
+
+ + +
+

💻 设备管理

+
+ + + + + + + + + + + + + + +
设备IP状态最后同步
加载中...
+
+
+ + +
+
+ + +
+

📊 监控中心

+
+ Prometheus + ● 运行中 +
+
+ Grafana + ● 运行中 +
+
+ Node Exporter + ● 运行中 +
+ +

+ Grafana 默认账号: admin / moltbot2024 +

+
+ + +
+

🔔 告警状态

+
+ 邮件告警 + ○ 未配置 +
+
+ Webhook 告警 + ○ 未配置 +
+
+ 今日告警数 + 0 +
+
+ 最后告警 + +
+
+ + +
+
+ + +
+

🔄 会话同步

+
+ 同步状态 + ● 启用 +
+
+ 同步频率 + 每 10 分钟 +
+
+ 上次同步 + -- +
+
+ 备份文件数 + -- +
+
+ + +
+
+ + +
+

📋 系统日志

+
+ + + + +
+
+
+ 2026-01-29 16:00:00 + [INFO] 系统启动 +
+
+
+ + +
+

⚙️ 快速配置

+ +
+

📧 配置邮件告警

+

+ 在服务器上编辑: /opt/moltbot-monitoring/alert-config.json +

+
+{
+  "email": {
+    "enabled": true,
+    "smtp_user": "your-email@gmail.com",
+    "smtp_password": "your-app-password",
+    "to_email": "your-email@example.com"
+  }
+}
+
+ +
+

🔔 配置钉钉告警

+

+ 在钉钉群设置 -> 智能群助手 -> 添加机器人 -> Webhook +

+
+{
+  "webhook": {
+    "enabled": true,
+    "url": "https://oapi.dingtalk.com/robot/send?access_token=xxx",
+    "type": "dingtalk"
+  }
+}
+
+ +
+ + +
+
+
+ + +
+

📈 完成进度

+
+ 基础架构 + 100% +
+
+
+
+ +
+ 监控告警 + 100% +
+
+
+
+ +
+ 数据库持久化 + 100% +
+
+
+
+ +
+ 会话同步 + 100% +
+
+
+
+ +
+ 设备部署 + 50% +
+
+
+
+
+
+ + + + diff --git a/notebook-auto-deploy.bat b/notebook-auto-deploy.bat new file mode 100644 index 000000000..b7bdb7a47 --- /dev/null +++ b/notebook-auto-deploy.bat @@ -0,0 +1,164 @@ +@echo off +chcp 65001 >nul +title Moltbot Notebook Auto Deployment + +set "REPO_URL=https://github.com/flowerjunjie/moltbot.git" +set "INSTALL_DIR=C:\moltbot" +set "CONFIG_DIR=%USERPROFILE%\.clawdbot" + +echo ======================================== +echo Moltbot Notebook Auto Deployment +echo ======================================== +echo. +echo This script will automatically install Moltbot on this notebook. +echo. +echo Installation directory: %INSTALL_DIR% +echo Configuration directory: %CONFIG_DIR% +echo. + +REM Check if Git is installed +where git >nul 2>&1 +if errorlevel 1 ( + echo ERROR: Git is not installed + echo Please install Git from: https://git-scm.com/downloads + pause + exit /b 1 +) + +REM Check if Node.js is installed +where node >nul 2>&1 +if errorlevel 1 ( + echo ERROR: Node.js is not installed + echo Please install Node.js from: https://nodejs.org/ + pause + exit /b 1 +) + +echo [1/6] Checking prerequisites... +echo. +echo Git: OK +echo Node.js: OK +echo. + +REM Clone or update repository +if exist "%INSTALL_DIR%\.git" ( + echo [2/6] Repository exists, updating... + cd /d "%INSTALL_DIR%" + git pull +) else ( + echo [2/6] Cloning repository... + if exist "%INSTALL_DIR%" ( + echo Installation directory already exists (not a git repo) + choice /C YN /M "Remove and re-clone" + if errorlevel 2 ( + echo Installation cancelled + pause + exit /b 1 + ) + rmdir /s /q "%INSTALL_DIR%" + ) + git clone "%REPO_URL%" "%INSTALL_DIR%" + cd /d "%INSTALL_DIR%" +) + +if errorlevel 1 ( + echo ERROR: Failed to clone repository + pause + exit /b 1 +) +echo. + +echo [3/6] Installing dependencies... +call pnpm install --silent +if errorlevel 1 ( + echo ERROR: Failed to install dependencies + echo Trying with npm instead... + call npm install --silent + if errorlevel 1 ( + echo ERROR: Failed to install dependencies with npm + pause + exit /b 1 + ) +) +echo. + +echo [4/6] Building Moltbot... +call pnpm build --silent +if errorlevel 1 ( + echo WARNING: Build failed, but continuing... +) +echo. + +echo [5/6] Creating configuration... + +REM Create config directory if not exists +if not exist "%CONFIG_DIR%" mkdir "%CONFIG_DIR%" + +REM Check if config already exists +if exist "%CONFIG_DIR%\moltbot.json" ( + echo Configuration file already exists + choice /C YN /M "Overwrite existing configuration" + if errorlevel 2 goto skip_config +) + +REM Create configuration file +( +echo { +echo "gateway": { +echo "mode": "hybrid", +echo "bind": "lan", +echo "auth": {"token": "moltbot-cluster-2024"} +echo }, +echo "browser": {"enabled": true}, +echo "models": { +echo "mode": "merge", +echo "providers": { +echo "minimax": { +echo "baseUrl": "https://api.minimaxi.com/anthropic", +echo "apiKey": "YOUR_API_KEY_HERE", +echo "authHeader": true +echo } +echo } +echo } +echo } +) > "%CONFIG_DIR%\moltbot.json" + +echo Configuration created at: %CONFIG_DIR%\moltbot.json +echo. + +:skip_config + +echo [6/6] Creating shortcuts... + +REM Create desktop shortcut +set "SHORTCUT=%USERPROFILE%\Desktop\Moltbot.lnk" +powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%SHORTCUT%'); $s.TargetPath = '%INSTALL_DIR%\Moltbot.bat'; $s.WorkingDirectory = '%INSTALL_DIR%'; $s.Save()" + +echo. +echo ======================================== +echo Installation Complete! +echo ======================================== +echo. +echo Desktop shortcut created: %SHORTCUT% +echo. +echo To configure your API key: +echo 1. Edit: %CONFIG_DIR%\moltbot.json +echo 2. Replace YOUR_API_KEY_HERE with your actual MiniMax API key +echo. +echo To start Moltbot: +echo - Double-click the desktop shortcut +echo - Or run: %INSTALL_DIR%\Moltbot.bat +echo. +echo To register this device with the cluster: +echo - Run: %INSTALL_DIR%\register-device.bat +echo. + +choice /C YN /M "Start Moltbot now" +if errorlevel 1 ( + start "" "%INSTALL_DIR%\Moltbot.bat" +) + +echo. +echo Thank you for installing Moltbot! +echo. +pause diff --git a/register-device.bat b/register-device.bat new file mode 100644 index 000000000..fb40a96d6 --- /dev/null +++ b/register-device.bat @@ -0,0 +1,91 @@ +@echo off +chcp 65001 >nul +title Register Device with Moltbot Cluster + +set "SERVER=root@38.14.254.51" +set "DB_API_URL=http://38.14.254.51:18800" + +echo ======================================== +echo Register Device with Cluster +echo ======================================== +echo. +echo This will register this device with the Moltbot cluster database. +echo. + +set "DEVICE_NAME=%COMPUTERNAME%" +set "DEVICE_TYPE=notebook" + +REM Detect device type +echo Select device type: +echo [1] Notebook/Laptop +echo [2] Desktop +echo [3] Server +echo. +choice /C 123 /N /M "Select (1-3)" +if errorlevel 3 set "DEVICE_TYPE=server" +if errorlevel 2 set "DEVICE_TYPE=desktop" +if errorlevel 1 set "DEVICE_TYPE=notebook" + +echo. +echo Device name: %DEVICE_NAME% +echo Device type: %DEVICE_TYPE% +echo. + +REM Get local IP address +for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /C:"IPv4"') do ( + set "IP_ADDRESS=%%a" + set "IP_ADDRESS=!IP_ADDRESS: =!" +) +if "%IP_ADDRESS%"=="" set "IP_ADDRESS=unknown" + +echo Local IP: %IP_ADDRESS% +echo. + +choice /C YN /M "Register this device" +if errorlevel 2 ( + echo Registration cancelled + pause + exit /b 0 +) + +echo. +echo Registering device... + +REM Use curl to register with the database API +curl -s -X POST "%DB_API_URL%/api/device" ^ + -H "Content-Type: application/json" ^ + -d "{\"name\":\"%DEVICE_NAME%\",\"type\":\"%DEVICE_TYPE%\",\"ip\":\"%IP_ADDRESS%\",\"status\":\"online\"}" ^ + -o "%TEMP%\register-response.json" + +if errorlevel 1 ( + echo. + echo WARNING: Could not connect to cluster database + echo. + echo You can register manually by running: + echo ssh %SERVER% "python3 /opt/moltbot-sync/db-storage.py update-device %DEVICE_NAME% %DEVICE_TYPE% %IP_ADDRESS%" + echo. +) else ( + type "%TEMP%\register-response.json" + echo. + echo Device registered successfully! +) + +REM Add device to server's known hosts +echo. +echo Adding device to monitoring system... +ssh %SERVER% "python3 /opt/moltbot-sync/db-storage.py update-device %DEVICE_NAME% %DEVICE_TYPE% %IP_ADDRESS% online" + +echo. +echo ======================================== +echo Registration Complete +echo ======================================== +echo. +echo Device: %DEVICE_NAME% +echo Type: %DEVICE_TYPE% +echo Status: Registered +echo. +echo You can now view this device in: +echo - Admin Panel: admin-panel.html +echo - Grafana: http://38.14.254.51:3000 +echo. +pause diff --git a/setup-ssh-keys.bat b/setup-ssh-keys.bat new file mode 100644 index 000000000..8fcd4c475 --- /dev/null +++ b/setup-ssh-keys.bat @@ -0,0 +1,130 @@ +@echo off +chcp 65001 >nul +title Setup SSH Keys for Moltbot Sync + +echo ======================================== +echo Moltbot SSH Key Setup +echo ======================================== +echo. +echo This will configure SSH keys for passwordless session sync +echo. + +set "SSH_DIR=%USERPROFILE%\.ssh" +set "SERVER=root@38.14.254.51" + +REM Check if .ssh directory exists +if not exist "%SSH_DIR%" ( + echo Creating .ssh directory... + mkdir "%SSH_DIR%" +) + +REM Check if key already exists +if exist "%SSH_DIR%\id_rsa" ( + echo SSH key already exists at %SSH_DIR%\id_rsa + echo. + choice /C YN /M "Do you want to generate a new key" + if errorlevel 2 goto skip_keygen +) + +echo. +echo Generating SSH key pair... +ssh-keygen -t rsa -f "%SSH_DIR%\id_rsa" -N "" -C "moltbot-sync@%COMPUTERNAME%" +if errorlevel 1 ( + echo ERROR: Failed to generate SSH key + echo Make sure ssh-keygen is installed (Git Bash or OpenSSH) + pause + exit /b 1 +) +echo SSH key generated successfully! + +:skip_keygen + +echo. +echo ======================================== +echo Copy Public Key to Server +echo ======================================== +echo. +echo You need to copy the public key to the server. +echo. +echo Method 1: Automatic (requires password once) +echo ------------------------------------------- +type "%SSH_DIR%\id_rsa.pub" +echo. +echo The above public key will be copied to: %SERVER% +echo. +choice /C YN /M "Continue with automatic setup" +if errorlevel 2 goto manual_setup + +echo. +echo Copying public key to server... +type "%SSH_DIR%\id_rsa.pub" | ssh %SERVER% "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" +if errorlevel 1 ( + echo. + echo WARNING: Automatic copy failed + echo. + goto manual_setup +) + +echo. +echo Public key copied successfully! +goto test_connection + +:manual_setup +echo. +echo ======================================== +echo Manual Setup Instructions +echo ======================================== +echo. +echo 1. Copy the public key below: +echo. +type "%SSH_DIR%\id_rsa.pub" +echo. +echo 2. Run this command on the server: +echo. +echo ssh %SERVER% +echo mkdir -p ~/.ssh +echo chmod 700 ~/.ssh +echo nano ~/.ssh/authorized_keys +echo. +echo 3. Paste the public key and save (Ctrl+X, Y, Enter) +echo. +echo 4. Set permissions: +echo. +echo chmod 600 ~/.ssh/authorized_keys +echo. +pause + +:test_connection +echo. +echo ======================================== +echo Test SSH Connection +echo ======================================== +echo. +echo Testing passwordless connection to %SERVER%... +echo. + +ssh -o BatchMode=yes -o ConnectTimeout=5 %SERVER% "echo 'Connection successful!'" +if errorlevel 1 ( + echo. + echo WARNING: Passwordless connection test failed + echo You may need to enter your password once for SSH to cache the key + echo. + echo Try running: ssh %SERVER% + echo. +) else ( + echo. + echo SUCCESS: Passwordless SSH connection is working! + echo Session sync will work without requiring a password. +) + +echo. +echo ======================================== +echo Setup Complete +echo ======================================== +echo. +echo SSH key location: %SSH_DIR%\id_rsa +echo Server: %SERVER% +echo. +echo You can now run sync-sessions.bat without entering a password. +echo. +pause diff --git a/start-chat.bat b/start-chat.bat new file mode 100644 index 000000000..bffd46876 --- /dev/null +++ b/start-chat.bat @@ -0,0 +1,3 @@ +@echo off +set PATH=D:\Users\15622\AppData\Roaming\nvm\v22.12.0;%PATH% +D:\workspace\moltbot\node scripts\run-node-clean.mjs --interactive diff --git a/sync-daemon.bat b/sync-daemon.bat new file mode 100644 index 000000000..a0e14eff6 --- /dev/null +++ b/sync-daemon.bat @@ -0,0 +1,15 @@ +@echo off +chcp 65001 >nul +title Moltbot Auto Sync + +echo Starting Moltbot Auto Sync... +echo Sync interval: 10 minutes +echo. + +:loop +call "%~dp0sync-sessions.bat" + +rem 等待10分钟 +timeout /t 600 /nobreak >nul + +goto loop diff --git a/sync-sessions.bat b/sync-sessions.bat new file mode 100644 index 000000000..b4ee9e343 --- /dev/null +++ b/sync-sessions.bat @@ -0,0 +1,67 @@ +@echo off +chcp 65001 >nul +title Moltbot Session Sync + +set "MOLTBOT_DIR=%USERPROFILE%\.clawdbot" +set "SESSION_DIR=%MOLTBOT_DIR%\agents\main\sessions" +set "SYNC_LOG=%MOLTBOT_DIR%\sync.log" + +echo ======================================== +echo Moltbot Session Sync +echo ======================================== +echo. + +if not exist "%SESSION_DIR%" ( + echo ERROR: Session directory not found + echo Please start Moltbot first + pause + exit /b 1 +) + +echo Syncing sessions to server... +echo. + +set TIMESTAMP=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2% +set HOSTNAME=%COMPUTERNAME% + +echo Timestamp: %TIMESTAMP% +echo Hostname: %HOSTNAME% +echo. + +rem 创建临时备份目录 +set "TEMP_DIR=%TEMP%\moltbot-sync" +if exist "%TEMP_DIR%" rmdir /s /q "%TEMP_DIR%" +mkdir "%TEMP_DIR%" + +rem 复制会话文件 +xcopy /E /I /Y "%SESSION_DIR%" "%TEMP_DIR%\" >nul 2>&1 +if errorlevel 1 ( + echo WARNING: No sessions to copy +) else ( + echo Sessions copied: %TEMP_DIR% + echo. + + rem 上传到服务器(需要配置 SSH 密钥) + echo Uploading to server... + scp -r "%TEMP_DIR%" root@38.14.254.51:/opt/moltbot-backup/sessions/%HOSTNAME%_%TIMESTAMP% + if errorlevel 1 ( + echo. + echo WARNING: SCP failed + echo. + echo Make sure SSH keys are configured: + echo 1. Run: ssh-keygen -t rsa + echo 2. Copy key: ssh-copy-id root@38.14.254.51 + echo. + echo Alternative: Use manual sync + ) else ( + echo Upload successful! + ) +) + +rem 清理 +if exist "%TEMP_DIR%" rmdir /s /q "%TEMP_DIR%" + +echo. +echo Sync completed: %date% %time% +echo. +pause