docs: add native go deployment runbook
This commit is contained in:
66
deploy/systemd/README.md
Normal file
66
deploy/systemd/README.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Go Vehicle Gateway Native Deployment
|
||||||
|
|
||||||
|
本目录用于 ECS 原生部署。当前 goal 后续不再使用 Docker/Portainer 作为 Go 接入链路的部署方式。
|
||||||
|
|
||||||
|
## Runtime Layout
|
||||||
|
|
||||||
|
```text
|
||||||
|
/opt/lingniu-go-native/
|
||||||
|
current -> /opt/lingniu-go-native/releases/<git-short-sha>
|
||||||
|
releases/<git-short-sha>/
|
||||||
|
gateway
|
||||||
|
history-writer
|
||||||
|
stat-writer
|
||||||
|
realtime-api
|
||||||
|
env/
|
||||||
|
gateway.env
|
||||||
|
history-writer.env
|
||||||
|
stat-writer.env
|
||||||
|
realtime-api.env
|
||||||
|
spool/gateway/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Services
|
||||||
|
|
||||||
|
| systemd unit | Binary | Purpose |
|
||||||
|
|---|---|---|
|
||||||
|
| `lingniu-go-gateway.service` | `gateway` | GB32960 TCP `32960`、JT808 TCP `808`、宇通 MQTT 接入,写 Kafka RAW/unified |
|
||||||
|
| `lingniu-go-history-writer.service` | `history-writer` | 消费 RAW topic,写 TDengine `raw_frames` 和核心时序表 |
|
||||||
|
| `lingniu-go-stat-writer.service` | `stat-writer` | 消费 RAW topic,写 MySQL `vehicle_daily_metric` |
|
||||||
|
| `lingniu-go-realtime-api.service` | `realtime-api` | 消费 unified topic,写 Redis,并提供 realtime/raw/stat 查询 API |
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
在开发机或 CI 上构建 Linux amd64 二进制:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd go/vehicle-gateway
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags='-s -w' -o /tmp/lingniu-go-native/gateway ./cmd/gateway
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags='-s -w' -o /tmp/lingniu-go-native/history-writer ./cmd/history-writer
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags='-s -w' -o /tmp/lingniu-go-native/stat-writer ./cmd/stat-writer
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags='-s -w' -o /tmp/lingniu-go-native/realtime-api ./cmd/realtime-api
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cutover Notes
|
||||||
|
|
||||||
|
1. 先上传二进制到新 release 目录并更新 `current` symlink。
|
||||||
|
2. 从现有生产 env 生成四个 systemd 专用 env 文件;不要把密钥写入仓库。
|
||||||
|
3. 停止旧 Docker Go 容器或 Java 容器,释放 `808`、`32960`、`20210`。
|
||||||
|
4. 执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
|
||||||
|
systemctl restart lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl is-active lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
|
||||||
|
ss -lntp | egrep ':(808|32960|20210)\b'
|
||||||
|
journalctl -u lingniu-go-gateway --since '5 minutes ago' --no-pager
|
||||||
|
curl -sS 'http://127.0.0.1:20210/api/history/raw-frames?protocol=JT808&limit=1'
|
||||||
|
curl -sS 'http://127.0.0.1:20210/api/history/raw-frames?protocol=GB32960&limit=1'
|
||||||
|
curl -sS 'http://127.0.0.1:20210/api/history/raw-frames?protocol=YUTONG_MQTT&limit=1'
|
||||||
|
```
|
||||||
18
deploy/systemd/lingniu-go-gateway.service
Normal file
18
deploy/systemd/lingniu-go-gateway.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Lingniu Go Vehicle Gateway
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/opt/lingniu-go-native/current
|
||||||
|
EnvironmentFile=/opt/lingniu-go-native/env/gateway.env
|
||||||
|
ExecStart=/opt/lingniu-go-native/current/gateway
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
KillSignal=SIGTERM
|
||||||
|
TimeoutStopSec=30
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
18
deploy/systemd/lingniu-go-history-writer.service
Normal file
18
deploy/systemd/lingniu-go-history-writer.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Lingniu Go History Writer
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/opt/lingniu-go-native/current
|
||||||
|
EnvironmentFile=/opt/lingniu-go-native/env/history-writer.env
|
||||||
|
ExecStart=/opt/lingniu-go-native/current/history-writer
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
KillSignal=SIGTERM
|
||||||
|
TimeoutStopSec=30
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
18
deploy/systemd/lingniu-go-realtime-api.service
Normal file
18
deploy/systemd/lingniu-go-realtime-api.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Lingniu Go Realtime API
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/opt/lingniu-go-native/current
|
||||||
|
EnvironmentFile=/opt/lingniu-go-native/env/realtime-api.env
|
||||||
|
ExecStart=/opt/lingniu-go-native/current/realtime-api
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
KillSignal=SIGTERM
|
||||||
|
TimeoutStopSec=30
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
18
deploy/systemd/lingniu-go-stat-writer.service
Normal file
18
deploy/systemd/lingniu-go-stat-writer.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Lingniu Go Stat Writer
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/opt/lingniu-go-native/current
|
||||||
|
EnvironmentFile=/opt/lingniu-go-native/env/stat-writer.env
|
||||||
|
ExecStart=/opt/lingniu-go-native/current/stat-writer
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
KillSignal=SIGTERM
|
||||||
|
TimeoutStopSec=30
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -748,3 +748,87 @@ calculation_method=TOTAL_MILEAGE_DIFF
|
|||||||
|
|
||||||
- RAW 查询已返回 `raw_hex`、`parsed_json`、`fields_json`,可以用于查看完整解析结果。
|
- RAW 查询已返回 `raw_hex`、`parsed_json`、`fields_json`,可以用于查看完整解析结果。
|
||||||
- 日统计和实时查询在生产端口接管后仍可用。
|
- 日统计和实时查询在生产端口接管后仍可用。
|
||||||
|
|
||||||
|
## 2026-07-02 00:00 原生 systemd 部署与宇通 MQTT 复验
|
||||||
|
|
||||||
|
根据本次 goal 的新要求,Go 接入链路后续不再使用 Docker 部署。本轮已中断 Docker 镜像构建路径,改为 ECS 原生 Linux 二进制 + systemd。
|
||||||
|
|
||||||
|
部署版本:
|
||||||
|
|
||||||
|
- Git commit:`594ab2d`
|
||||||
|
- 部署目录:`/opt/lingniu-go-native`
|
||||||
|
- 当前 release:`/opt/lingniu-go-native/releases/594ab2d`
|
||||||
|
- 当前指针:`/opt/lingniu-go-native/current -> /opt/lingniu-go-native/releases/594ab2d`
|
||||||
|
|
||||||
|
systemd 服务:
|
||||||
|
|
||||||
|
```text
|
||||||
|
lingniu-go-gateway.service active
|
||||||
|
lingniu-go-history-writer.service active
|
||||||
|
lingniu-go-stat-writer.service active
|
||||||
|
lingniu-go-realtime-api.service active
|
||||||
|
```
|
||||||
|
|
||||||
|
端口确认:
|
||||||
|
|
||||||
|
```text
|
||||||
|
[::]:32960 gateway
|
||||||
|
[::]:808 gateway
|
||||||
|
[::]:20210 realtime-api
|
||||||
|
```
|
||||||
|
|
||||||
|
Go Docker 容器已停止:
|
||||||
|
|
||||||
|
```text
|
||||||
|
go-vehicle-gateway Exited
|
||||||
|
go-history-writer Exited
|
||||||
|
go-stat-writer Exited
|
||||||
|
go-realtime-api Exited
|
||||||
|
```
|
||||||
|
|
||||||
|
宇通 MQTT:
|
||||||
|
|
||||||
|
```text
|
||||||
|
yutong mqtt client started
|
||||||
|
mqtt subscribed broker=ssl://cpxlm.axxc.cn:38883 topic=/ytforward/shln/+ qos=1
|
||||||
|
```
|
||||||
|
|
||||||
|
说明:MQTT broker 存在短连接 `EOF` 后自动重连现象,但订阅后已收到真实数据并落 RAW。
|
||||||
|
|
||||||
|
RAW 查询复验:
|
||||||
|
|
||||||
|
```text
|
||||||
|
GET /api/history/raw-frames?protocol=YUTONG_MQTT&limit=3
|
||||||
|
|
||||||
|
total=3
|
||||||
|
protocol=YUTONG_MQTT
|
||||||
|
vin=LMRKH9AC1R1004131
|
||||||
|
vehicle_key=LMRKH9AC1R1004131
|
||||||
|
parse_status=OK
|
||||||
|
parsed_json_len=1104
|
||||||
|
fields_json_len=116
|
||||||
|
```
|
||||||
|
|
||||||
|
同轮回归:
|
||||||
|
|
||||||
|
```text
|
||||||
|
GET /api/history/raw-frames?protocol=JT808&vin=LKLG7C4E3NA774736&messageId=0x0200&limit=1
|
||||||
|
total=1
|
||||||
|
parse_status=OK
|
||||||
|
|
||||||
|
GET /api/history/raw-frames?protocol=GB32960&vin=LB9A32A21R0LS1707&limit=1
|
||||||
|
total=1
|
||||||
|
parse_status=OK
|
||||||
|
|
||||||
|
GET /api/realtime/vehicles/LKLG7C4E3NA774736/online
|
||||||
|
online=true
|
||||||
|
protocols=["JT808"]
|
||||||
|
```
|
||||||
|
|
||||||
|
本轮落地文件:
|
||||||
|
|
||||||
|
- `deploy/systemd/README.md`
|
||||||
|
- `deploy/systemd/lingniu-go-gateway.service`
|
||||||
|
- `deploy/systemd/lingniu-go-history-writer.service`
|
||||||
|
- `deploy/systemd/lingniu-go-stat-writer.service`
|
||||||
|
- `deploy/systemd/lingniu-go-realtime-api.service`
|
||||||
|
|||||||
Reference in New Issue
Block a user