项目名称: huamo-data-service
版本: 1.0.0
描述: 透析机数据转发服务,接收设备数据并上传至阿里云 IoT
部署方式: 使用预编译的独立可执行文件部署
| 文件名 | 操作系统 | 架构 | 使用场景 |
|---|---|---|---|
index-win.exe |
Windows | x64 | Windows 服务器 |
index-linux |
Linux | x64 | Linux 服务器 |
index-macos |
macOS | x64 | macOS 本地开发 |
将以下文件复制到部署目录: deployment/ ├── index-win.exe # 可执行文件 └── hmConfig.json # 配置文件
编辑 hmConfig.json:json { "port": 13000, "iotRegion": "cn-shanghai" }
方式一:直接双击运行 双击 index-win.exe
方式二:命令行运行
```powershell
.\index-win.exe
index-win.exe
```
方式三:后台运行(推荐)
```powershell
Start-Process -FilePath "C:\path\to\index-win.exe" -WindowStyle Hidden
#### 4. 验证服务状态
netstat -ano | findstr :13000
curl http://localhost:13000/health
```
将以下文件复制到部署目录:
```bash
mkdir -p /opt/huamo-service
cd /opt/huamo-service
cp index-linux .
cp hmConfig.json .
chmod +x index-linux
```
编辑 hmConfig.json:json { "port": 13000, "iotRegion": "cn-shanghai" }
方式一:直接运行bash ./index-linux
方式二:后台运行(推荐)
```bash
nohup ./index-linux > service.log 2>&1 &
screen -S huamo-service
./index-linux
**方式三:使用 Systemd(推荐)**
创建服务文件 `/etc/systemd/system/huamo-service.service`:
[Unit]
Description=Huamo Data Service
After=network.target
[Service]
Type=simple
User=nobody
WorkingDirectory=/opt/huamo-service
ExecStart=/opt/huamo-service/index-linux
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
```
启动服务:
```bash
sudo systemctl daemon-reload
sudo systemctl start huamo-service
sudo systemctl enable huamo-service
sudo systemctl status huamo-service
sudo journalctl -u huamo-service -f
```
# 检查端口是否监听
netstat -tlnp | grep 13000
# 或
ss -tlnp | grep 13000
# 访问健康检查接口
curl http://localhost:13000/health
{
"port": 13000,
"iotRegion": "cn-shanghai"
}
配置项说明:
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| port | number | 13000 | 服务监听端口 |
| iotRegion | string | cn-shanghai | 阿里云 IoT 区域 |
常见区域代码:
- cn-shanghai: 华东2(上海)
- cn-beijing: 华北2(北京)
- cn-hangzhou: 华东1(杭州)
- cn-shenzhen: 华南1(深圳)
请求方式: POST
接口路径: /api/message
请求头: Content-Type: application/json
请求体示例:json { "MAC": "00:11:22:33:44:55", "IP": "192.168.1.100", "DataBase": { "temperature": 37.5, "pressure": 120 } }
响应成功(200):json { "success": true, "message": "数据接收并转发成功", "deviceId": "productKey/deviceName" }
响应失败(400):json { "success": false, "message": "缺少必要字段: MAC, ip, data" }
请求方式: GET
接口路径: /health
响应示例:json { "status": "OK", "clients": 5, "cacheSize": 10, "timestamp": "2025-12-10T12:34:56.789Z" }
Win+R 输入 taskschd.mscHuamo Data Service透析机数据服务启动时启动程序C:\path\to\index-win.exeC:\path\to\# 查看任务
Get-ScheduledTask -TaskName "Huamo Data Service"
# 运行任务
Start-ScheduledTask -TaskName "Huamo Data Service"
# 停止任务
Stop-ScheduledTask -TaskName "Huamo Data Service"
见上面 Systemd 部分
编辑 crontab:bash crontab -e
添加以下行:cron @reboot /opt/huamo-service/index-linux > /opt/huamo-service/huamo.log 2>&1
# 查看事件查看器(应用程序事件日志)
eventvwr.msc
# 查看 systemd 日志
journalctl -u huamo-service -n 50 -f
# 查看实时日志
tail -f /opt/huamo-service/huamo.log
# 查看最近错误
grep -i error /opt/huamo-service/huamo.log
Windows:powershell # 使用详细模式运行查看错误 .\index-win.exe 2>&1 | tee output.log
Linux:bash # 直接运行查看错误信息 ./index-linux
Windows:
```powershell
netstat -ano | findstr :13000
taskkill /PID /F
```
Linux:
```bash
lsof -i :13000
ss -tlnp | grep 13000
kill -9
```
Windows:powershell # 查看进程资源占用 Get-Process | findstr index-win
Linux:
```bash
ps aux | grep index-linux
top -p
```
| 配置项 | 推荐值 | 说明 |
|---|---|---|
| port | 13000 | 避免使用 80、443 等特殊端口 |
| iotRegion | 根据实际位置 | 选择离服务器最近的区域 |
| 内存 | 512 MB+ | 根据设备数量调整 |
小型部署(1-10 个设备): ┌─────────────┐ │ 单台服务器 │ (index-win.exe 或 index-linux) └─────────────┘
中型部署(10-100 个设备): ┌────────────────────┐ │ 负载均衡器 │ └────────┬───────────┘ │ ┌─────────┼─────────┐ │ │ │ ┌───▼──┐ ┌───▼──┐ ┌───▼──┐ │服务器1│ │服务器2│ │服务器3│ └──────┘ └──────┘ └──────┘
# Windows
xcopy hmConfig.json backup\hmConfig.json.bak /Y
# Linux
cp hmConfig.json backup/hmConfig.json.bak
index-win.exe 或 index-linuxhmConfig.json使用 Windows 性能监控器:powershell perfmon.msc
使用系统监控工具:bash # 使用 Prometheus + Grafana # 或者简单的 CPU/内存监控 watch -n 1 'ps aux | grep index-linux'
taskkill /IM index-win.exe /Fsudo systemctl stop huamo-service备份配置
bash cp hmConfig.json hmConfig.json.backup
替换可执行文件
index-win.exe 或 index-linux 替换旧文件.\index-win.exesudo systemctl start huamo-servicebash curl http://localhost:13000/health # 启动服务
.\index-win.exe
# 后台启动
Start-Process -FilePath ".\index-win.exe" -WindowStyle Hidden
# 查看端口
netstat -ano | findstr :13000
# 健康检查
curl http://localhost:13000/health
# 启动服务
./index-linux
# 后台启动
nohup ./index-linux > huamo.log 2>&1 &
# 查看端口
netstat -tlnp | grep 13000
# 健康检查
curl http://localhost:13000/health
# 查看日志
journalctl -u huamo-service -f